[Zope-Checkins] SVN: Zope/trunk/lib/python/AccessControl/ using isinstance()

Andreas Jung andreas at andreas-jung.com
Wed Sep 8 03:16:07 EDT 2004


Log message for revision 27470:
  using isinstance()
  


Changed:
  U   Zope/trunk/lib/python/AccessControl/Owned.py
  U   Zope/trunk/lib/python/AccessControl/Permission.py
  U   Zope/trunk/lib/python/AccessControl/Role.py
  U   Zope/trunk/lib/python/AccessControl/SecurityInfo.py


-=-
Modified: Zope/trunk/lib/python/AccessControl/Owned.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/Owned.py	2004-09-08 07:01:19 UTC (rev 27469)
+++ Zope/trunk/lib/python/AccessControl/Owned.py	2004-09-08 07:16:06 UTC (rev 27470)
@@ -275,8 +275,7 @@
     if callable(attr): return attr()
     return attr
 
-def ownerInfo(user,
-              getattr=getattr, type=type, st=type('')):
+def ownerInfo(user, getattr=getattr):
     if user is None:
         return None
     uid=user.getId()
@@ -290,7 +289,7 @@
         db=db.aq_parent
         if db is root: break
         id=db.id
-        if type(id) is not st:
+        if not isinstance(id, str):
             try: id=id()
             except: id=str(id)
         path.append(id)

Modified: Zope/trunk/lib/python/AccessControl/Permission.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/Permission.py	2004-09-08 07:01:19 UTC (rev 27469)
+++ Zope/trunk/lib/python/AccessControl/Permission.py	2004-09-08 07:16:06 UTC (rev 27470)
@@ -14,9 +14,9 @@
 
 $Id$
 """
+
 import string, Products, Globals
 
-ListType=type([])
 
 name_trans=filter(lambda c, an=string.letters+string.digits+'_': c not in an,
                   map(chr,range(256)))
@@ -83,7 +83,7 @@
     def setRoles(self, roles):
         obj=self.obj
 
-        if type(roles) is ListType and not roles:
+        if isinstance(roles, list) and not roles:
             if hasattr(obj, self._p): delattr(obj, self._p)
         else:
             setattr(obj, self._p, roles)
@@ -100,14 +100,14 @@
         roles=self.getRoles()
         if role in roles:
             if present: return
-            if type(roles) is ListType: roles.remove(role)
+            if isinstance(roles, list): roles.remove(role)
             else:
                 roles=list(roles)
                 roles.remove(role)
                 roles=tuple(roles)
         elif not present: return
         else:
-            if type(roles) is ListType: roles.append(role)
+            if isinstance(roles, list): roles.append(role)
             else: roles=roles+(role,)
         self.setRoles(roles)
 

Modified: Zope/trunk/lib/python/AccessControl/Role.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/Role.py	2004-09-08 07:01:19 UTC (rev 27469)
+++ Zope/trunk/lib/python/AccessControl/Role.py	2004-09-08 07:16:06 UTC (rev 27470)
@@ -21,7 +21,6 @@
 from App.Common import aq_base
 from cgi import escape
 
-ListType=type([])
 
 DEFAULTMAXLISTUSERS=250
 
@@ -109,7 +108,7 @@
             p=Permission(name,value,self)
             roles=p.getRoles(default=[])
             d={'name': name,
-               'acquire': type(roles) is ListType and 'CHECKED' or '',
+               'acquire': isinstance(roles, list) and 'CHECKED' or '',
                'roles': map(
                    lambda ir, roles=roles, valid=valid, ip=ip:
                    {
@@ -262,7 +261,7 @@
             if name==permission:
                 p=Permission(name,value,self)
                 roles=p.getRoles()
-                return type(roles) is ListType and 'CHECKED' or ''
+                return isinstance(roles, list) and 'CHECKED' or ''
 
         raise ValueError, (
             "The permission <em>%s</em> is invalid." % escape(permission))
@@ -317,7 +316,7 @@
             aclu = getattr(aq_base(item), '__allow_groups__', _notfound)
             if aclu is not _notfound:
                 mlu = getattr(aclu, 'maxlistusers', _notfound)
-                if type(mlu) != type(1): mlu = DEFAULTMAXLISTUSERS
+                if not isinstance(mlu, int): mlu = DEFAULTMAXLISTUSERS
                 if mlu < 0: raise OverflowError
                 un = getattr(aclu, 'user_names', _notfound)
                 if un is not _notfound:

Modified: Zope/trunk/lib/python/AccessControl/SecurityInfo.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/SecurityInfo.py	2004-09-08 07:01:19 UTC (rev 27469)
+++ Zope/trunk/lib/python/AccessControl/SecurityInfo.py	2004-09-08 07:16:06 UTC (rev 27470)
@@ -126,7 +126,7 @@
         This should be a boolean value, a map of attribute names to
         booleans, or a callable (name, value) -> boolean.
         """
-        if type(access) == type(''):
+        if isinstance(access, str):
             access = access.lower()
             if access == 'allow':
                 access = 1



More information about the Zope-Checkins mailing list