[Zope-Checkins] CVS: Zope/lib/python/webdav - Collection.py:1.23 LockItem.py:1.5 Resource.py:1.50 common.py:1.14 davcmds.py:1.16 xmltools.py:1.12

Andreas Jung andreas@zope.com
Thu, 29 Nov 2001 13:18:17 -0500


Update of /cvs-repository/Zope/lib/python/webdav
In directory cvs.zope.org:/tmp/cvs-serv23260

Modified Files:
	Collection.py LockItem.py Resource.py common.py davcmds.py 
	xmltools.py 
Log Message:
replaced string module calls by string methods


=== Zope/lib/python/webdav/Collection.py 1.22 => 1.23 ===
 __version__='$Revision$'[11:-2]
 
-import sys, os, string, Globals, davcmds, Lockable,re
+import sys, os,  Globals, davcmds, Lockable,re
 from common import urlfix, rfc1123_date
 from Resource import Resource
 from AccessControl import getSecurityManager
@@ -77,7 +77,7 @@
         self.dav__init(REQUEST, RESPONSE)
         ifhdr = REQUEST.get_header('If', '')
         url = urlfix(REQUEST['URL'], 'DELETE')
-        name = unquote(filter(None, string.split(url, '/'))[-1])
+        name = unquote(filter(None, url.split( '/'))[-1])
         parent = self.aq_parent
         user = getSecurityManager().getUser()
         token = None
@@ -106,7 +106,7 @@
             for tok in tokens:
                 # We already know that the simple if handler succeeded,
                 # we just want to get the right token out of the header now
-                if string.find(ifhdr, tok) > -1:
+                if ifhdr.find(tok) > -1:
                     token = tok
         cmd = davcmds.DeleteCollection()
         result = cmd.apply(self, token, user, REQUEST['URL'])


=== Zope/lib/python/webdav/LockItem.py 1.4 => 1.5 ===
 __version__ = "$Revision$"[11:-2]
 
-from string import lower, split, join
+
 from Globals import Persistent
 from WriteLockInterface import LockItemInterface
 from AccessControl import ClassSecurityInfo
@@ -28,8 +28,8 @@
     # Timeout *should* be in the form "Seconds-XXX" or "Infinite"
     errors = []
     try:
-        t = split(str(timeout), '-')[-1]
-        if lower(t) == 'infinite':
+        t =str(timeout).split('-')[-1]
+        if t.lower() == 'infinite':
             timeout = DEFAULTTIMEOUT # Default to 1800 secods for infinite
         else:                       # requests
             timeout = long(t)
@@ -60,11 +60,11 @@
         # First check the values and raise value errors if outside of contract
         if not getattr(creator, 'getUserName', None):
             errors.append("Creator not a user object")
-        if lower(str(depth)) not in ('0', 'infinity'):
+        if str(depth).lower() not in ('0', 'infinity'):
             errors.append("Depth must be 0 or infinity")
-        if lower(locktype) != 'write':
+        if locktype.lower() != 'write':
             errors.append("Lock type '%s' not supported" % locktype)
-        if lower(lockscope) != 'exclusive':
+        if lockscope.lower() != 'exclusive':
             errors.append("Lock scope '%s' not supported" % lockscope)
 
         timeout, e = validateTimeout(timeout)
@@ -95,7 +95,7 @@
 
     def getCreatorPath(self):
         db, name = self._creator
-        path = join(db,'/')
+        path = '/'.join(db)
         return "/%s/%s" % (path, name)
 
     def getOwner(self):


=== Zope/lib/python/webdav/Resource.py 1.49 => 1.50 ===
 __version__='$Revision$'[11:-2]
 
-import sys, os, string, mimetypes, davcmds, ExtensionClass, Lockable
+import sys, os,  mimetypes, davcmds, ExtensionClass, Lockable
 from common import absattr, aq_base, urlfix, rfc1123_date, tokenFinder, urlbase
 from common import IfParser
 from urllib import quote, unquote
@@ -104,7 +104,7 @@
         # if 'col' is passed in, an operation is happening on a submember
         # of a collection, while the Lock may be on the parent.  Lob off
         # the final part of the URL  (ie '/a/b/foo.html' becomes '/a/b/')
-        if col: url = url[:string.rfind(url, '/')+1]
+        if col: url = url[:url.rfind('/')+1]
 
         havetag = lambda x, self=self: self.wl_hasLock(x)
         found = 0; resourcetagged = 0
@@ -151,14 +151,14 @@
             content_type=absattr(self.content_type)
         if content_type is None:
             url=urlfix(REQUEST['URL'], 'HEAD')
-            name=unquote(filter(None, string.split(url, '/'))[-1])
+            name=unquote(filter(None, url.split( '/')[-1]))
             content_type, encoding=mimetypes.guess_type(name)
         if content_type is None:
             if hasattr(self, 'default_content_type'):
                 content_type=absattr(self.default_content_type)
         if content_type is None:
             content_type = 'application/octet-stream'
-        RESPONSE.setHeader('Content-Type', string.lower(content_type))
+        RESPONSE.setHeader('Content-Type', content_type.lower())
 
         if hasattr(aq_base(self), 'get_size'):
             RESPONSE.setHeader('Content-Length', absattr(self.get_size))
@@ -183,7 +183,7 @@
     def OPTIONS(self, REQUEST, RESPONSE):
         """Retrieve communication options."""
         self.dav__init(REQUEST, RESPONSE)
-        RESPONSE.setHeader('Allow', string.join(self.__http_methods__,', '))
+        RESPONSE.setHeader('Allow', ', '.join(self.__http_methods__))
         RESPONSE.setHeader('Content-Length', 0)
         RESPONSE.setHeader('DAV', '1,2', 1)
         RESPONSE.setStatus(200)
@@ -206,7 +206,7 @@
         self.dav__init(REQUEST, RESPONSE)
         ifhdr = REQUEST.get_header('If', '')
         url = urlfix(REQUEST['URL'], 'DELETE')
-        name = unquote(filter(None, string.split(url, '/'))[-1])
+        name = unquote(filter(None, url.split( '/')[-1]))
         parent = self.aq_parent
         # Lock checking
         if Lockable.wl_isLocked(self):
@@ -301,9 +301,9 @@
             raise 'Bad Request', 'Invalid Destination header'
 
         name = path.pop()
-        parent_path = string.join(path, '/')
+        parent_path = '/'.join(path)
 
-        oflag=string.upper(REQUEST.get_header('Overwrite', 'F'))
+        oflag=REQUEST.get_header('Overwrite', 'F').upper()
         if not oflag in ('T', 'F'):
             raise 'Bad Request', 'Invalid Overwrite header.'
 
@@ -390,10 +390,10 @@
             raise 'Bad Request', 'No destination given'
 
         flag=REQUEST.get_header('Overwrite', 'F')
-        flag=string.upper(flag)
+        flag=flag.upper()
 
         name = path.pop()
-        parent_path = string.join(path, '/')
+        parent_path = '/'.join(path)
 
         try: parent = self.restrictedTraverse(path)
         except ValueError:


=== Zope/lib/python/webdav/common.py 1.13 => 1.14 ===
 __version__='$Revision$'[11:-2]
 
-import string, time, urllib, re
+import  time, urllib, re
 from App.Common import iso8601_date, rfc850_date, rfc1123_date
 from App.Common import aq_base
 
@@ -31,6 +31,17 @@
         url=url[:-1]
     return url
 
+def is_acquired(ob):
+    # Return true if this object is not a direct
+    # subobject of its aq_parent object.
+    if not hasattr(ob, 'aq_parent'):
+        return 0
+    if hasattr(aq_base(ob.aq_parent), absattr(ob.id)):
+        return 0
+    if hasattr(aq_base(ob), 'isTopLevelPrincipiaApplicationObject') and \
+            ob.isTopLevelPrincipiaApplicationObject:
+        return 0
+    return 1
 
 def urlbase(url, ftype=urllib.splittype, fhost=urllib.splithost):
     # Return a '/' based url such as '/foo/bar', removing
@@ -53,7 +64,7 @@
     if not token: return None           # An empty string was passed in
     if token[0] == '[': return None     # An Etag was passed in
     if token[0] == '<': token = token[1:-1]
-    return token[string.find(token,':')+1:]
+    return token[token.find(':')+1:]
 
 
 ### If: header handling support.  IfParser returns a sequence of


=== Zope/lib/python/webdav/davcmds.py 1.15 => 1.16 ===
 __version__='$Revision$'[11:-2]
 
-import sys, os, string
+import sys, os
 from common import absattr, aq_base, urlfix, urlbase
 from OFS.PropertySheets import DAVProperties
 from LockItem import LockItem
@@ -26,8 +26,8 @@
 from urllib import quote
 from AccessControl import getSecurityManager
 
-def safe_quote(url, mark=r'%', find=string.find):
-    if find(url, mark) > -1:
+def safe_quote(url, mark=r'%'):
+    if url.find(mark) > -1:
         return url
     return quote(url)
 
@@ -105,14 +105,14 @@
             for ps in propsets:
                 if hasattr(aq_base(ps), 'dav__allprop'):
                     stats.append(ps.dav__allprop())
-            stats=string.join(stats, '') or '<d:status>200 OK</d:status>\n'
+            stats=''.join(stats) or '<d:status>200 OK</d:status>\n'
             result.write(stats)            
         elif self.propname:
             stats=[]
             for ps in propsets:
                 if hasattr(aq_base(ps), 'dav__propnames'):
                     stats.append(ps.dav__propnames())
-            stats=string.join(stats, '') or '<d:status>200 OK</d:status>\n'
+            stats=''.join(stats) or '<d:status>200 OK</d:status>\n'
             result.write(stats)
         elif self.propnames:
             rdict={}
@@ -266,7 +266,7 @@
         # This is lame, but I cant find a way to keep ZPublisher
         # from sticking a traceback into my xml response :(
         get_transaction().abort()
-        result=string.replace(result, '200 OK', '424 Failed Dependency')
+        result=result.replace( '200 OK', '424 Failed Dependency')
         return result
 
 
@@ -282,7 +282,7 @@
         self.type = 'write'
         self.owner = ''
         timeout = request.get_header('Timeout', 'infinite')
-        self.timeout = string.strip(string.split(timeout,',')[-1])
+        self.timeout = timeout.split(',')[-1].strip()
         self.parse(data)
 
     def parse(self, data, dav='DAV:'):


=== Zope/lib/python/webdav/xmltools.py 1.11 => 1.12 ===
 __version__='$Revision$'[11:-2]
 
-import sys, os, string
+import sys, os
 import Shared.DC.xml.xmllib
 from Acquisition import Implicit
 
@@ -63,12 +63,12 @@
                 return ''
             self=self.aq_parent
 
-    def elements(self, name=None, ns=None, lower=string.lower):
+    def elements(self, name=None, ns=None ):
         nodes=[]
-        name=name and lower(name)
+        name=name and name.lower()
         for node in self.__nodes__:
             if node.__type__==type_element and \
-               ((name is None) or (lower(node.__name__)==name)) and \
+               ((name is None) or ((node.__name__.lower())==name)) and \
                ((ns is None) or (node.namespace()==ns)):
                 nodes.append(node)
         return nodes
@@ -100,7 +100,7 @@
         result=['<?xml version="1.0" encoding="%s"?>' % self.encoding]
         for node in self.__nodes__:
             result.append(node.toxml())
-        return string.join(result, '')
+        return ''.join(result)
 
     #def __del__(self):
     #    self.document=None
@@ -119,16 +119,16 @@
             attr=Attribute(name, val)
             self.__attrs__.append(attr)
         self.ns_parse()
-        parts=string.split(self.__name__, ':')
+        parts=self.__name__.split(':')
         if len(parts) > 1:
             self.__nskey__=parts[0]
-            self.__name__=string.join(parts[1:], ':')
+            self.__name__=':'.join(parts[1:])
             
     def ns_parse(self):
         nsdef=self.__nsdef__={}
         for attr in self.attrs():
             name, val=attr.name(), attr.value()
-            key=string.lower(name)
+            key=name.lower()
             if key[:6]=='xmlns:':
                 nsdef[name[6:]]=val
             elif key=='xmlns':
@@ -198,13 +198,13 @@
             for node in self.__nodes__:
                 result.append(node.toxml())
             result.append('</%s>' % qname)
-        return string.join(result, '')
+        return ''.join(result)
 
     def strval(self, top=1):
         if not self.__value__ and not self.__nodes__:
             return ''
         result=map(lambda n: n.toxml(), self.__nodes__)
-        return string.join(result, '')
+        return ''.join(result)
 
 class Attribute(Node):
     __type__=type_attribute
@@ -212,12 +212,12 @@
         self.__name__=name
         self.__value__=val
         self.__nskey__=''
-        parts=string.split(name, ':')
+        parts=name.split(':')
         if len(parts) > 1:
-            pre=string.lower(parts[0])
+            pre=parts[0].lower()
             if not (pre in ('xml', 'xmlns')):
                 self.__nskey__=parts[0]
-                self.__name__=string.join(parts[1:], ':')
+                self.__name__=':'.join(parts[1:])
 
     def remap(self, dict, n=0, top=1):
         nsval=self.namespace()
@@ -344,12 +344,12 @@
 
 
 
-def escape(data, rmap={}, replace=string.replace):
-    data=replace(data, "&", "&amp;")
-    data=replace(data, "<", "&lt;")
-    data=replace(data, ">", "&gt;")
+def escape(data, rmap={}):
+    data=data.replace( "&", "&amp;")
+    data=data.replace( "<", "&lt;")
+    data=data.replace( ">", "&gt;")
     for key, val in rmap.items():
-        data=replace(data, key, val)
+        data=data.replace( key, val)
     return data
 
 def remap(data, dict={'DAV:': 'd'}):