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

Modified Files:
      Tag: tseaver-hasattr_geddon-branch
        ImplPython.py Implementation.py Owned.py Permission.py 
        PermissionMapping.py Role.py SimpleObjectPolicies.py User.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/AccessControl/ImplPython.py 1.1.2.5 => 1.1.2.5.2.1 ===
--- Packages/AccessControl/ImplPython.py:1.1.2.5        Tue Feb 15 15:59:25 2005
+++ Packages/AccessControl/ImplPython.py        Sat May 28 20:41:28 2005
@@ -22,6 +22,7 @@
 from Acquisition import aq_acquire
 from ExtensionClass import Base
 from zLOG import LOG, PROBLEM
+from ZODB.utils import safe_hasattr
 
 # This is used when a permission maps explicitly to no permission.  We
 # try and get this from cAccessControl first to make sure that if both
@@ -90,7 +91,7 @@
         n = self._p
         r = None
         while 1:
-            if hasattr(obj, n):
+            if safe_hasattr(obj, n):
                 roles = getattr(obj, n)
 
                 if roles is None:


=== Packages/AccessControl/Implementation.py 1.1.2.7 => 1.1.2.7.26.1 ===
--- Packages/AccessControl/Implementation.py:1.1.2.7    Tue Feb  3 15:30:06 2004
+++ Packages/AccessControl/Implementation.py    Sat May 28 20:41:28 2005
@@ -24,6 +24,7 @@
 module was introduced.
 
 """
+from ZODB.utils import safe_hasattr
 
 def getImplementationName():
     """Return the name of the implementation currently being used."""
@@ -60,7 +61,7 @@
         mod = sys.modules[modname]
         for n in names:
             setattr(mod, n, getattr(impl, n))
-        if hasattr(mod, "initialize"):
+        if safe_hasattr(mod, "initialize"):
             mod.initialize(impl)
 
     from AccessControl.SecurityManager import setSecurityPolicy


=== Packages/AccessControl/Owned.py 1.19.46.4 => 1.19.46.4.26.1 ===
--- Packages/AccessControl/Owned.py:1.19.46.4   Fri Mar 12 11:58:29 2004
+++ Packages/AccessControl/Owned.py     Sat May 28 20:41:28 2005
@@ -18,6 +18,7 @@
 import Globals, urlparse, SpecialUsers, ExtensionClass
 from AccessControl import getSecurityManager, Unauthorized
 from Acquisition import aq_get, aq_parent, aq_base
+from ZODB.utils import safe_hasattr
 
 UnownableOwner=[]
 def ownableFilter(self):
@@ -55,7 +56,7 @@
             return owner
 
         d={'path': '/'.join(owner[0]), 'id': owner[1],
-           'explicit': hasattr(self, '_owner'),
+           'explicit': safe_hasattr(self, '_owner'),
            'userCanChangeOwnershipType':
            getSecurityManager().checkPermission('Take ownership', self)
            }
@@ -226,8 +227,8 @@
         else: _owner=None
 
         if (_owner is None and
-            ((not hasattr(self, 'aq_parent')) or
-             (not hasattr(self, 'getPhysicalRoot'))
+            ((not safe_hasattr(self, 'aq_parent')) or
+             (not safe_hasattr(self, 'getPhysicalRoot'))
              )
             ):
             # This is a special case. An object is


=== Packages/AccessControl/Permission.py 1.10 => 1.10.134.1 ===
--- Packages/AccessControl/Permission.py:1.10   Wed Aug 14 17:29:07 2002
+++ Packages/AccessControl/Permission.py        Sat May 28 20:41:28 2005
@@ -17,6 +17,7 @@
 __version__='$Revision$'[11:-2]
 
 import string, Products, Globals
+from ZODB.utils import safe_hasattr
 
 ListType=type([])
 
@@ -38,7 +39,7 @@
         self.name=name
         self._p='_'+string.translate(name,name_trans)+"_Permission"
         self.data=data
-        if hasattr(obj, 'aq_base'): obj=obj.aq_base
+        if safe_hasattr(obj, 'aq_base'): obj=obj.aq_base
         self.obj=obj
         self.default=default
 
@@ -49,21 +50,21 @@
         # attributes that this permission represents.
         obj=self.obj
         name=self._p
-        if hasattr(obj, name): return getattr(obj, name)
+        if safe_hasattr(obj, name): return getattr(obj, name)
         roles=default
         for name in self.data:
             if name:
-                if hasattr(obj, name):
+                if safe_hasattr(obj, name):
                     attr=getattr(obj, name)
-                    if hasattr(attr,'im_self'):
+                    if safe_hasattr(attr,'im_self'):
                         attr=attr.im_self
-                        if hasattr(attr, '__dict__'):
+                        if safe_hasattr(attr, '__dict__'):
                             attr=attr.__dict__
                             name=name+'__roles__'
                             if attr.has_key(name):
                                 roles=attr[name]
                                 break
-            elif hasattr(obj, '__dict__'):
+            elif safe_hasattr(obj, '__dict__'):
                 attr=obj.__dict__
                 if attr.has_key('__roles__'):
                     roles=attr['__roles__']
@@ -86,7 +87,7 @@
         obj=self.obj
 
         if type(roles) is ListType and not roles:
-            if hasattr(obj, self._p): delattr(obj, self._p)
+            if safe_hasattr(obj, self._p): delattr(obj, self._p)
         else:
             setattr(obj, self._p, roles)
 
@@ -134,6 +135,6 @@
         Products.__ac_permissions__=(
             Products.__ac_permissions__+((perm,(),default),))
         mangled=pname(perm) # get mangled permission name
-        if not hasattr(Globals.ApplicationDefaultPermissions, mangled):
+        if not safe_hasattr(Globals.ApplicationDefaultPermissions, mangled):
             setattr(Globals.ApplicationDefaultPermissions,
                     mangled, default)


=== Packages/AccessControl/PermissionMapping.py 1.13.70.1 => 1.13.70.1.30.1 ===
--- Packages/AccessControl/PermissionMapping.py:1.13.70.1       Mon Nov 17 
17:34:01 2003
+++ Packages/AccessControl/PermissionMapping.py Sat May 28 20:41:28 2005
@@ -21,6 +21,7 @@
 from Permission import pname
 from Owned import UnownableOwner
 from Globals import InitializeClass
+from ZODB.utils import safe_hasattr
 from cgi import escape
 
 class RoleManager:
@@ -79,7 +80,7 @@
 
     def _isBeingUsedAsAMethod(self, REQUEST =None, wannaBe=0):
         try:
-            if hasattr(self, 'aq_self'):
+            if safe_hasattr(self, 'aq_self'):
                 r=self.aq_acquire('_isBeingUsedAsAMethod_')
             else:
                 r=self._isBeingUsedAsAMethod_


=== Packages/AccessControl/Role.py 1.56.14.4 => 1.56.14.4.22.1 ===
--- Packages/AccessControl/Role.py:1.56.14.4    Tue May  4 03:40:54 2004
+++ Packages/AccessControl/Role.py      Sat May 28 20:41:28 2005
@@ -21,6 +21,7 @@
 from Permission import Permission
 from App.Common import aq_base
 from cgi import escape
+from ZODB.utils import safe_hasattr
 
 ListType=type([])
 
@@ -78,7 +79,7 @@
 
         r=gather_permissions(self.__class__, [], d)
         if all:
-            if hasattr(self, '_subobject_permissions'):
+            if safe_hasattr(self, '_subobject_permissions'):
                 for p in self._subobject_permissions():
                     pname=p[0]
                     if not d.has_key(pname):
@@ -189,7 +190,7 @@
 
     def manage_access(self, REQUEST, **kw):
         "Return an interface for making permissions settings"
-        if hasattr(self, '_isBeingUsedAsAMethod') and \
+        if safe_hasattr(self, '_isBeingUsedAsAMethod') and \
            self._isBeingUsedAsAMethod():
             return apply(self._method_manage_access,(), kw)
         else:
@@ -391,13 +392,13 @@
         for key, value in inst.items():
             if key.find('__roles__') >= 0:
                 _add({'name': key, 'value': value, 'class': 0})
-            if hasattr(value, '__roles__'):
+            if safe_hasattr(value, '__roles__'):
                 _add({'name': '%s.__roles__' % key, 'value': value.__roles__,
                       'class': 0})
         for key, value in clas.items():
             if key.find('__roles__') >= 0:
                 _add({'name': key, 'value': value, 'class' : 1})
-            if hasattr(value, '__roles__'):
+            if safe_hasattr(value, '__roles__'):
                 _add({'name': '%s.__roles__' % key, 'value': value.__roles__,
                       'class': 1})
         return data
@@ -409,12 +410,12 @@
         dup =dict.has_key
         x=0
         while x < 100:
-            if hasattr(obj, '__ac_roles__'):
+            if safe_hasattr(obj, '__ac_roles__'):
                 roles=obj.__ac_roles__
                 for role in roles:
                     if not dup(role):
                         dict[role]=1
-            if not hasattr(obj, 'aq_parent'):
+            if not safe_hasattr(obj, 'aq_parent'):
                 break
             obj=obj.aq_parent
             x=x+1
@@ -525,7 +526,7 @@
     except: return None
 
 def classattr(cls, attr):
-    if hasattr(cls, attr):
+    if safe_hasattr(cls, attr):
         return getattr(cls, attr)
     try:    bases=cls.__bases__
     except: bases=()


=== Packages/AccessControl/SimpleObjectPolicies.py 1.12.70.5 => 1.12.70.5.26.1 
===
--- Packages/AccessControl/SimpleObjectPolicies.py:1.12.70.5    Tue Jan 27 
16:49:04 2004
+++ Packages/AccessControl/SimpleObjectPolicies.py      Sat May 28 20:41:28 2005
@@ -44,6 +44,7 @@
 
 _noroles = [] # this is imported from various places
 
+from ZODB.utils import safe_hasattr
 import Record
 
 # Allow access to unprotected attributes
@@ -78,7 +79,7 @@
     restricted code.  The argument Type must be a type."""
     if type(Type) is not type:
         raise ValueError, "%s is not a type" % `Type`
-    if hasattr(Type, '__roles__'):
+    if safe_hasattr(Type, '__roles__'):
         raise ValueError, "%s handles its own security" % `Type`
     if not (isinstance(allowed, int) or isinstance(allowed, dict)):
         raise ValueError, "The 'allowed' argument must be an int or dict."


=== Packages/AccessControl/User.py 1.176.14.8 => 1.176.14.8.2.1 ===
--- Packages/AccessControl/User.py:1.176.14.8   Fri Mar 18 08:17:31 2005
+++ Packages/AccessControl/User.py      Sat May 28 20:41:28 2005
@@ -30,6 +30,7 @@
 from AccessControl.SecurityManagement import newSecurityManager
 from AccessControl.SecurityManagement import noSecurityManager
 from AccessControl.ZopeSecurityPolicy import _noroles
+from ZODB.utils import safe_hasattr
 
 ListType=type([])
 
@@ -101,7 +102,7 @@
             if parent is not None:
                 object = parent
                 continue
-            if hasattr(object, 'im_self'):
+            if safe_hasattr(object, 'im_self'):
                 object=object.im_self
                 object=getattr(object, 'aq_inner', object)
                 continue
@@ -129,7 +130,7 @@
     def _shared_roles(self, parent):
         r=[]
         while 1:
-            if hasattr(parent,'__roles__'):
+            if safe_hasattr(parent,'__roles__'):
                 roles=parent.__roles__
                 if roles is None: return 'Anonymous',
                 if 'Shared' in roles:
@@ -139,8 +140,8 @@
                 else:
                     try: return r+list(roles)
                     except: return r
-            if hasattr(parent, 'aq_parent'):
-                while hasattr(parent.aq_self,'aq_self'):
+            if safe_hasattr(parent, 'aq_parent'):
+                while safe_hasattr(parent.aq_self,'aq_self'):
                     parent=parent.aq_self
                 parent=parent.aq_parent
             else: return r
@@ -156,11 +157,11 @@
         if context is not None:
             if object is None:
                 return 1
-            if not hasattr(object, 'aq_inContextOf'):
-                if hasattr(object, 'im_self'):
+            if not safe_hasattr(object, 'aq_inContextOf'):
+                if safe_hasattr(object, 'im_self'):
                     # This is a method.  Grab its self.
                     object=object.im_self
-                if not hasattr(object, 'aq_inContextOf'):
+                if not safe_hasattr(object, 'aq_inContextOf'):
                     # Object is not wrapped, so return false.
                     return 0
             return object.aq_inContextOf(context, 1)
@@ -225,7 +226,7 @@
             if parent is not None:
                 inner_obj = parent
                 continue
-            if hasattr(inner_obj, 'im_self'):
+            if safe_hasattr(inner_obj, 'im_self'):
                 inner_obj=inner_obj.im_self
                 inner_obj=getattr(inner_obj, 'aq_inner', inner_obj)
                 continue
@@ -531,7 +532,7 @@
         """API method for creating a new user object. Note that not all
            user folder implementations support dynamic creation of user
            objects."""
-        if hasattr(self, '_doAddUser'):
+        if safe_hasattr(self, '_doAddUser'):
             return self._doAddUser(name, password, roles, domains, **kw)
         raise NotImplementedError
 
@@ -539,14 +540,14 @@
         """API method for changing user object attributes. Note that not
            all user folder implementations support changing of user object
            attributes."""
-        if hasattr(self, '_doChangeUser'):
+        if safe_hasattr(self, '_doChangeUser'):
             return self._doChangeUser(name, password, roles, domains, **kw)
         raise NotImplementedError
 
     def userFolderDelUsers(self, names):
         """API method for deleting one or more user objects. Note that not
            all user folder implementations support deletion of user objects."""
-        if hasattr(self, '_doDelUsers'):
+        if safe_hasattr(self, '_doDelUsers'):
             return self._doDelUsers(names)
         raise NotImplementedError
 
@@ -744,7 +745,7 @@
         if innerparent is not None:
             # this is not a method, we needn't treat it specially
             c = innerparent
-        elif hasattr(v, 'im_self'):
+        elif safe_hasattr(v, 'im_self'):
             # this is a method, we need to treat it specially
             c = v.im_self
             c = getattr(v, 'aq_inner', v)
@@ -971,7 +972,7 @@
 
     def manage_afterAdd(self, item, container):
         if item is self:
-            if hasattr(self, 'aq_base'): self=self.aq_base
+            if safe_hasattr(self, 'aq_base'): self=self.aq_base
             container.__allow_groups__=self
 
     def __creatable_by_emergency_user__(self): return 1

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to