[Zope-Checkins] CVS: Packages/webdav - Collection.py:1.24.66.3.22.1 Lockable.py:1.8.122.1 NullResource.py:1.39.62.5.2.1 Resource.py:1.55.10.9.6.1 common.py:1.17.66.1.30.1 davcmds.py:1.20.66.2.30.1

Tres Seaver tseaver at palladion.com
Sat May 28 20:42:19 EDT 2005


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

Modified Files:
      Tag: tseaver-hasattr_geddon-branch
	Collection.py Lockable.py NullResource.py Resource.py 
	common.py davcmds.py 
Log Message:

  - Removed all uses of the 'hasattr' builtin from the core, where
    the object being tested derives (or might) from Persistent.
    XXX:  currently, this branch imports a 'safe_hasattr' from ZODB.utils,
    which adds a dependency on ZODB for some packages;  we probably
    need a better location, and perhas a C implementation?


=== Packages/webdav/Collection.py 1.24.66.3 => 1.24.66.3.22.1 ===
--- Packages/webdav/Collection.py:1.24.66.3	Fri Jul 30 17:49:05 2004
+++ Packages/webdav/Collection.py	Sat May 28 20:41:38 2005
@@ -22,6 +22,7 @@
 from urllib import unquote
 from WriteLockInterface import WriteLockInterface
 from zExceptions import MethodNotAllowed, NotFound
+from ZODB.utils import safe_hasattr
 from webdav.common import Locked, PreconditionFailed
 
 class Collection(Resource):
@@ -52,8 +53,8 @@
         # Note that we are willing to acquire the default document
         # here because what we really care about is whether doing
         # a GET on this collection / would yield a 200 response.
-        if hasattr(self, 'index_html'):
-            if hasattr(self.index_html, 'HEAD'):
+        if safe_hasattr(self, 'index_html'):
+            if safe_hasattr(self.index_html, 'HEAD'):
                 return self.index_html.HEAD(REQUEST, RESPONSE)
             raise MethodNotAllowed, (
                   'Method not supported for this resource.'


=== Packages/webdav/Lockable.py 1.8 => 1.8.122.1 ===
--- Packages/webdav/Lockable.py:1.8	Wed Aug 14 18:11:40 2002
+++ Packages/webdav/Lockable.py	Sat May 28 20:41:38 2005
@@ -18,6 +18,7 @@
 from LockItem import LockItem
 from AccessControl import ClassSecurityInfo
 from Globals import PersistentMapping
+from ZODB.utils import safe_hasattr
 import Acquisition
 
 class ResourceLockedError(Exception): pass
@@ -67,8 +68,8 @@
             for token, lock in locks.items():
                 if not lock.isValid():
                     del locks[token]
-            if (not locks) and hasattr(Acquisition.aq_base(self),
-                                       '__no_valid_write_locks__'):
+            if (not locks) and safe_hasattr(Acquisition.aq_base(self),
+                                            '__no_valid_write_locks__'):
                 self.__no_valid_write_locks__()
             return locks
         else:
@@ -124,14 +125,15 @@
         except:
             # The locks may be totally messed up, so we'll just delete
             # and replace.
-            if hasattr(self, '_dav_writelocks'): del self._dav_writelocks
+            if safe_hasattr(self, '_dav_writelocks'):
+                del self._dav_writelocks
             if WriteLockInterface.isImplementedBy(self):
                 self._dav_writelocks = PersistentMapping()
 
         # Call into a special hook used by LockNullResources to delete
         # themselves.  Could be used by other objects who want to deal
         # with the state of empty locks.
-        if hasattr(Acquisition.aq_base(self), '__no_valid_write_locks__'):
+        if safe_hasattr(Acquisition.aq_base(self), '__no_valid_write_locks__'):
             self.__no_valid_write_locks__()
 
 


=== Packages/webdav/NullResource.py 1.39.62.5 => 1.39.62.5.2.1 ===
--- Packages/webdav/NullResource.py:1.39.62.5	Wed Mar 16 08:58:55 2005
+++ Packages/webdav/NullResource.py	Sat May 28 20:41:38 2005
@@ -25,6 +25,7 @@
 import OFS.SimpleItem
 from zExceptions import Unauthorized, NotFound, Forbidden, BadRequest
 from zExceptions import MethodNotAllowed
+from ZODB.utils import safe_hasattr
 from common import isDavCollection
 from common import Locked, Conflict, PreconditionFailed, UnsupportedMediaType
 from OFS.CopySupport import CopyError
@@ -166,7 +167,7 @@
         name=self.__name__
         parent = self.__parent__
 
-        if hasattr(aq_base(parent), name):
+        if safe_hasattr(aq_base(parent), name):
             raise MethodNotAllowed, 'The name %s is in use.' % name
         if not isDavCollection(parent):
             raise Forbidden, 'Cannot create collection at this location.'


=== Packages/webdav/Resource.py 1.55.10.9 => 1.55.10.9.6.1 ===
--- Packages/webdav/Resource.py:1.55.10.9	Wed Dec 22 18:29:30 2004
+++ Packages/webdav/Resource.py	Sat May 28 20:41:38 2005
@@ -26,6 +26,7 @@
 import ExtensionClass
 from Acquisition import aq_base
 from AccessControl import getSecurityManager
+from ZODB.utils import safe_hasattr
 from ZPublisher.HTTPRangeSupport import HTTPRangeInterface
 from zExceptions import Unauthorized, Forbidden
 from zExceptions import BadRequest, MethodNotAllowed 
@@ -70,7 +71,7 @@
         # Also, we sniff for a ZServer response object, because we don't
         # want to write duplicate headers (since ZS writes Date
         # and Connection itself).
-        if not hasattr(response, '_server_version'):
+        if not safe_hasattr(response, '_server_version'):
             response.setHeader('Connection', 'close')
             response.setHeader('Date', rfc1123_date(), 1)
         # XXMSXX response.setHeader('MS-Author-Via', 'DAV')
@@ -84,7 +85,7 @@
     def dav__validate(self, object, methodname, REQUEST):
         msg='<strong>You are not authorized to access this resource.</strong>'
         method=None
-        if hasattr(object, methodname):
+        if safe_hasattr(object, methodname):
             method=getattr(object, methodname)
         else:
             try:    method=object.aq_acquire(methodname)
@@ -160,25 +161,25 @@
         self.dav__init(REQUEST, RESPONSE)
 
         content_type=None
-        if hasattr(self, 'content_type'):
+        if safe_hasattr(self, 'content_type'):
             content_type=absattr(self.content_type)
         if content_type is None:
             url=urlfix(REQUEST['URL'], 'HEAD')
             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'):
+            if safe_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', content_type.lower())
 
-        if hasattr(aq_base(self), 'get_size'):
+        if safe_hasattr(aq_base(self), 'get_size'):
             RESPONSE.setHeader('Content-Length', absattr(self.get_size))
-        if hasattr(self, '_p_mtime'):
+        if safe_hasattr(self, '_p_mtime'):
             mtime=rfc1123_date(self._p_mtime)
             RESPONSE.setHeader('Last-Modified', mtime)
-        if hasattr(aq_base(self), 'http__etag'):
+        if safe_hasattr(aq_base(self), 'http__etag'):
             etag = self.http__etag(readonly=1)
             if etag:
                 RESPONSE.setHeader('Etag', etag)
@@ -272,7 +273,7 @@
     def PROPPATCH(self, REQUEST, RESPONSE):
         """Set and/or remove properties defined on the resource."""
         self.dav__init(REQUEST, RESPONSE)
-        if not hasattr(aq_base(self), 'propertysheets'):
+        if not safe_hasattr(aq_base(self), 'propertysheets'):
             raise MethodNotAllowed, (
                   'Method not supported for this resource.')
         # Lock checking
@@ -304,7 +305,7 @@
         seamless across namespaces (e.g. from Zope to Apache), COPY
         is currently only supported within the Zope namespace."""
         self.dav__init(REQUEST, RESPONSE)
-        if not hasattr(aq_base(self), 'cb_isCopyable') or \
+        if not safe_hasattr(aq_base(self), 'cb_isCopyable') or \
            not self.cb_isCopyable():
             raise MethodNotAllowed, 'This object may not be copied.'
 
@@ -337,9 +338,9 @@
         except:
             t, v, tb=sys.exc_info()
             raise t, v
-        if hasattr(parent, '__null_resource__'):
+        if safe_hasattr(parent, '__null_resource__'):
             raise Conflict, 'Object ancestors must already exist.'
-        existing=hasattr(aq_base(parent), name)
+        existing=safe_hasattr(aq_base(parent), name)
         if existing and oflag=='F':
             raise PreconditionFailed, 'Destination resource exists.'
         try:
@@ -407,7 +408,7 @@
         namespace."""
         self.dav__init(REQUEST, RESPONSE)
         self.dav__validate(self, 'DELETE', REQUEST)
-        if not hasattr(aq_base(self), 'cb_isMoveable') or \
+        if not safe_hasattr(aq_base(self), 'cb_isMoveable') or \
            not self.cb_isMoveable():
             raise MethodNotAllowed, 'This object may not be moved.'
 
@@ -431,9 +432,9 @@
         except:
             t, v, tb=sys.exc_info()
             raise t, v
-        if hasattr(parent, '__null_resource__'):
+        if safe_hasattr(parent, '__null_resource__'):
             raise Conflict, 'The resource %s must exist.' % parent_path
-        existing=hasattr(aq_base(parent), name)
+        existing=safe_hasattr(aq_base(parent), name)
         if existing and flag=='F':
             raise PreconditionFailed, 'Resource %s exists.' % dest
         try:


=== Packages/webdav/common.py 1.17.66.1 => 1.17.66.1.30.1 ===
--- Packages/webdav/common.py:1.17.66.1	Mon Nov 17 17:34:22 2003
+++ Packages/webdav/common.py	Sat May 28 20:41:38 2005
@@ -18,6 +18,7 @@
 import  time, urllib, re
 from App.Common import iso8601_date, rfc850_date, rfc1123_date
 from App.Common import aq_base
+from ZODB.utils import safe_hasattr
 import random
 
 _randGen = random.Random(time.time())
@@ -52,12 +53,12 @@
 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'):
+    if not safe_hasattr(ob, 'aq_parent'):
         return 0
-    if hasattr(aq_base(ob.aq_parent), absattr(ob.id)):
+    if safe_hasattr(aq_base(ob.aq_parent), absattr(ob.id)):
         return 0
-    if hasattr(aq_base(ob), 'isTopLevelPrincipiaApplicationObject') and \
-            ob.isTopLevelPrincipiaApplicationObject:
+    if (safe_hasattr(aq_base(ob), 'isTopLevelPrincipiaApplicationObject')
+    and ob.isTopLevelPrincipiaApplicationObject):
         return 0
     return 1
 


=== Packages/webdav/davcmds.py 1.20.66.2 => 1.20.66.2.30.1 ===
--- Packages/webdav/davcmds.py:1.20.66.2	Mon Nov 17 17:34:22 2003
+++ Packages/webdav/davcmds.py	Sat May 28 20:41:38 2005
@@ -26,6 +26,7 @@
 from cStringIO import StringIO
 from urllib import quote
 from AccessControl import getSecurityManager
+from ZODB.utils import safe_hasattr
 from zExceptions import BadRequest, Forbidden
 from common import isDavCollection
 from common import PreconditionFailed
@@ -102,7 +103,7 @@
         iscol=isDavCollection(obj)
         if iscol and url[-1] != '/': url=url+'/'
         result.write('<d:response>\n<d:href>%s</d:href>\n' % safe_quote(url))
-        if hasattr(aq_base(obj), 'propertysheets'):
+        if safe_hasattr(aq_base(obj), 'propertysheets'):
             propsets=obj.propertysheets.values()
             obsheets=obj.propertysheets
         else:
@@ -112,14 +113,14 @@
         if self.allprop:
             stats=[]
             for ps in propsets:
-                if hasattr(aq_base(ps), 'dav__allprop'):
+                if safe_hasattr(aq_base(ps), 'dav__allprop'):
                     stats.append(ps.dav__allprop())
             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'):
+                if safe_hasattr(aq_base(ps), 'dav__propnames'):
                     stats.append(ps.dav__propnames())
             stats=''.join(stats) or '<d:status>200 OK</d:status>\n'
             result.write(stats)
@@ -127,7 +128,8 @@
             rdict={}
             for name, ns in self.propnames:
                 ps=obsheets.get(ns, None)
-                if ps is not None and hasattr(aq_base(ps), 'dav__propstat'):
+                if (ps is not None
+                 and safe_hasattr(aq_base(ps), 'dav__propstat')):
                     stat=ps.dav__propstat(name, rdict)
                 else:
                     prop='<n:%s xmlns:n="%s"/>' % (name, ns)
@@ -152,15 +154,16 @@
         result.write('</d:response>\n')
         if depth in ('1', 'infinity') and iscol:
             for ob in obj.listDAVObjects():
-                if hasattr(ob,"meta_type"):
+                if safe_hasattr(ob,"meta_type"):
                     if ob.meta_type=="Broken Because Product is Gone":
                         continue
-                dflag=hasattr(ob, '_p_changed') and (ob._p_changed == None)
-                if hasattr(ob, '__locknull_resource__'):
+                dflag = (safe_hasattr(ob, '_p_changed')
+                          and (ob._p_changed == None))
+                if safe_hasattr(ob, '__locknull_resource__'):
                     # Do nothing, a null resource shouldn't show up to DAV
                     if dflag:
                         ob._p_deactivate()
-                elif hasattr(ob, '__dav_resource__'):
+                elif safe_hasattr(ob, '__dav_resource__'):
                     uri=os.path.join(url, absattr(ob.id))
                     depth=depth=='infinity' and depth or 0
                     self.apply(ob, uri, depth, result, top=0)
@@ -403,7 +406,7 @@
 
         if depth == 'infinity' and iscol:
             for ob in obj.objectValues():
-                if hasattr(obj, '__dav_resource__'):
+                if safe_hasattr(obj, '__dav_resource__'):
                     uri = os.path.join(url, absattr(ob.id))
                     self.apply(ob, creator, depth, token, result,
                                uri, top=0)
@@ -465,7 +468,7 @@
 
         if iscol:
             for ob in obj.objectValues():
-                if hasattr(ob, '__dav_resource__') and \
+                if safe_hasattr(ob, '__dav_resource__') and \
                    WriteLockInterface.isImplementedBy(ob):
                     uri = os.path.join(url, absattr(ob.id))
                     self.apply(ob, token, uri, result, top=0)
@@ -519,8 +522,9 @@
 
         if iscol:
             for ob in obj.objectValues():
-                dflag = hasattr(ob,'_p_changed') and (ob._p_changed == None)
-                if hasattr(ob, '__dav_resource__'):
+                dflag = (safe_hasattr(ob,'_p_changed')
+                          and (ob._p_changed == None))
+                if safe_hasattr(ob, '__dav_resource__'):
                     uri = os.path.join(url, absattr(ob.id))
                     self.apply(ob, token, user, uri, result, top=0)
                     if dflag:



More information about the Zope-Checkins mailing list