Commit 5866524f authored by Andreas Jung's avatar Andreas Jung

using isinstance()

parent f291b685
...@@ -275,8 +275,7 @@ def absattr(attr): ...@@ -275,8 +275,7 @@ def absattr(attr):
if callable(attr): return attr() if callable(attr): return attr()
return attr return attr
def ownerInfo(user, def ownerInfo(user, getattr=getattr):
getattr=getattr, type=type, st=type('')):
if user is None: if user is None:
return None return None
uid=user.getId() uid=user.getId()
...@@ -290,7 +289,7 @@ def ownerInfo(user, ...@@ -290,7 +289,7 @@ def ownerInfo(user,
db=db.aq_parent db=db.aq_parent
if db is root: break if db is root: break
id=db.id id=db.id
if type(id) is not st: if not isinstance(id, str):
try: id=id() try: id=id()
except: id=str(id) except: id=str(id)
path.append(id) path.append(id)
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
$Id$ $Id$
""" """
import string, Products, Globals import string, Products, Globals
ListType=type([])
name_trans=filter(lambda c, an=string.letters+string.digits+'_': c not in an, name_trans=filter(lambda c, an=string.letters+string.digits+'_': c not in an,
map(chr,range(256))) map(chr,range(256)))
...@@ -83,7 +83,7 @@ class Permission: ...@@ -83,7 +83,7 @@ class Permission:
def setRoles(self, roles): def setRoles(self, roles):
obj=self.obj 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) if hasattr(obj, self._p): delattr(obj, self._p)
else: else:
setattr(obj, self._p, roles) setattr(obj, self._p, roles)
...@@ -100,14 +100,14 @@ class Permission: ...@@ -100,14 +100,14 @@ class Permission:
roles=self.getRoles() roles=self.getRoles()
if role in roles: if role in roles:
if present: return if present: return
if type(roles) is ListType: roles.remove(role) if isinstance(roles, list): roles.remove(role)
else: else:
roles=list(roles) roles=list(roles)
roles.remove(role) roles.remove(role)
roles=tuple(roles) roles=tuple(roles)
elif not present: return elif not present: return
else: else:
if type(roles) is ListType: roles.append(role) if isinstance(roles, list): roles.append(role)
else: roles=roles+(role,) else: roles=roles+(role,)
self.setRoles(roles) self.setRoles(roles)
......
...@@ -21,7 +21,6 @@ from Permission import Permission ...@@ -21,7 +21,6 @@ from Permission import Permission
from App.Common import aq_base from App.Common import aq_base
from cgi import escape from cgi import escape
ListType=type([])
DEFAULTMAXLISTUSERS=250 DEFAULTMAXLISTUSERS=250
...@@ -109,7 +108,7 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -109,7 +108,7 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
p=Permission(name,value,self) p=Permission(name,value,self)
roles=p.getRoles(default=[]) roles=p.getRoles(default=[])
d={'name': name, d={'name': name,
'acquire': type(roles) is ListType and 'CHECKED' or '', 'acquire': isinstance(roles, list) and 'CHECKED' or '',
'roles': map( 'roles': map(
lambda ir, roles=roles, valid=valid, ip=ip: lambda ir, roles=roles, valid=valid, ip=ip:
{ {
...@@ -262,7 +261,7 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -262,7 +261,7 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
if name==permission: if name==permission:
p=Permission(name,value,self) p=Permission(name,value,self)
roles=p.getRoles() roles=p.getRoles()
return type(roles) is ListType and 'CHECKED' or '' return isinstance(roles, list) and 'CHECKED' or ''
raise ValueError, ( raise ValueError, (
"The permission <em>%s</em> is invalid." % escape(permission)) "The permission <em>%s</em> is invalid." % escape(permission))
...@@ -317,7 +316,7 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -317,7 +316,7 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
aclu = getattr(aq_base(item), '__allow_groups__', _notfound) aclu = getattr(aq_base(item), '__allow_groups__', _notfound)
if aclu is not _notfound: if aclu is not _notfound:
mlu = getattr(aclu, 'maxlistusers', _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 if mlu < 0: raise OverflowError
un = getattr(aclu, 'user_names', _notfound) un = getattr(aclu, 'user_names', _notfound)
if un is not _notfound: if un is not _notfound:
......
...@@ -126,7 +126,7 @@ class SecurityInfo(Acquisition.Implicit): ...@@ -126,7 +126,7 @@ class SecurityInfo(Acquisition.Implicit):
This should be a boolean value, a map of attribute names to This should be a boolean value, a map of attribute names to
booleans, or a callable (name, value) -> boolean. booleans, or a callable (name, value) -> boolean.
""" """
if type(access) == type(''): if isinstance(access, str):
access = access.lower() access = access.lower()
if access == 'allow': if access == 'allow':
access = 1 access = 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment