[Zope-Checkins] CVS: Packages/ZClasses - Basic.py:1.21.68.1.30.1
Method.py:1.24.2.2.28.1 Property.py:1.35.68.1.30.1
ZClass.py:1.63.68.2.30.1
Tres Seaver
tseaver at palladion.com
Sat May 28 20:42:17 EDT 2005
Update of /cvs-repository/Packages/ZClasses
In directory cvs.zope.org:/tmp/cvs-serv32028/lib/python/ZClasses
Modified Files:
Tag: tseaver-hasattr_geddon-branch
Basic.py Method.py Property.py ZClass.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/ZClasses/Basic.py 1.21.68.1 => 1.21.68.1.30.1 ===
--- Packages/ZClasses/Basic.py:1.21.68.1 Mon Nov 17 17:34:18 2003
+++ Packages/ZClasses/Basic.py Sat May 28 20:41:37 2005
@@ -16,6 +16,7 @@
import Globals, OFS.PropertySheets, OFS.Image, ExtensionClass
import Acquisition, Products
from zExceptions import BadRequest
+from ZODB.utils import safe_hasattr
class ZClassBasicSheet(OFS.PropertySheets.PropertySheet,
OFS.PropertySheets.View):
@@ -128,7 +129,7 @@
def zclass_productid(self):
# find the name of the enclosing Product
obj=self
- while hasattr(obj, 'aq_parent'):
+ while safe_hasattr(obj, 'aq_parent'):
obj=obj.aq_parent
try:
if obj.meta_type=='Product':
=== Packages/ZClasses/Method.py 1.24.2.2 => 1.24.2.2.28.1 ===
--- Packages/ZClasses/Method.py:1.24.2.2 Thu Jan 8 18:34:00 2004
+++ Packages/ZClasses/Method.py Sat May 28 20:41:37 2005
@@ -23,6 +23,7 @@
from OFS.DTMLMethod import DTMLMethod
from Products.PythonScripts.PythonScript import PythonScript
from zExceptions import BadRequest
+from ZODB.utils import safe_hasattr
import marshal
from cgi import escape
@@ -142,7 +143,7 @@
try: r=self.getClassAttr(id.strip())
except: return default
- if hasattr(r, methodattr):
+ if safe_hasattr(r, methodattr):
m=r.__dict__[methodattr]
if r.__class__ is W:
# Ugh, we need to convert an old wrapper to a new one
@@ -163,9 +164,9 @@
return getattr(r, 'aq_base', r).__of__(self)
def __bobo_traverse__(self, request, name):
- if hasattr(self, 'aq_base'):
+ if safe_hasattr(self, 'aq_base'):
b=self.aq_base
- if hasattr(b,name): return getattr(self, name)
+ if safe_hasattr(b,name): return getattr(self, name)
try: return self[name]
except: return getattr(self, name)
@@ -219,7 +220,7 @@
m=self.__dict__[methodattr]
wrapper=getattr(m, '_permissionMapper', None)
if wrapper is None: wrapper=PermissionMapper()
- if hasattr(m,'__of__'): return aqwrap(m, wrapper, parent)
+ if safe_hasattr(m,'__of__'): return aqwrap(m, wrapper, parent)
return m
class MWp(Globals.Persistent):
@@ -235,8 +236,10 @@
m=getattr(self, methodattr)
m=self.__dict__[methodattr]
wrapper=getattr(m, '_permissionMapper', None)
- if wrapper is None: wrapper=PermissionMapper()
- if hasattr(m,'__of__'): return aqwrap(m, wrapper, parent)
+ if wrapper is None:
+ wrapper=PermissionMapper()
+ if safe_hasattr(m,'__of__'):
+ return aqwrap(m, wrapper, parent)
return m
@@ -260,7 +263,8 @@
def __of__(self, parent):
m=getattr(self, methodattr)
m=self.__dict__[methodattr]
- if hasattr(m,'__of__'): return aqwrap(m, self, parent)
+ if safe_hasattr(m,'__of__'):
+ return aqwrap(m, self, parent)
return m
=== Packages/ZClasses/Property.py 1.35.68.1 => 1.35.68.1.30.1 ===
--- Packages/ZClasses/Property.py:1.35.68.1 Mon Nov 17 17:34:18 2003
+++ Packages/ZClasses/Property.py Sat May 28 20:41:37 2005
@@ -16,6 +16,7 @@
import OFS.PropertySheets, Globals, OFS.SimpleItem, OFS.PropertyManager
import Acquisition
from AccessControl.Permission import pname
+from ZODB.utils import safe_hasattr
class ClassCaretaker:
def __init__(self, klass): self.__dict__['_k']=klass
@@ -328,7 +329,7 @@
def klass_sequence(klass,attr,result=None):
if result is None: result={}
- if hasattr(klass,attr):
+ if safe_hasattr(klass,attr):
for i in getattr(klass,attr): result[i]=1
for klass in klass.__bases__:
klass_sequence(klass, attr, result)
=== Packages/ZClasses/ZClass.py 1.63.68.2 => 1.63.68.2.30.1 ===
--- Packages/ZClasses/ZClass.py:1.63.68.2 Mon Nov 17 17:34:18 2003
+++ Packages/ZClasses/ZClass.py Sat May 28 20:41:37 2005
@@ -21,6 +21,7 @@
from ComputedAttribute import ComputedAttribute
from Products.PythonScripts.PythonScript import PythonScript
from zExceptions import BadRequest, Redirect
+from ZODB.utils import safe_hasattr
import webdav.Collection
import marshal
@@ -66,8 +67,10 @@
pack[ zname ] = Z
if meta_type is None:
- if hasattr(base_class, 'meta_type'): meta_type=base_class.meta_type
- else: meta_type=base_class.__name__
+ if safe_hasattr(base_class, 'meta_type'):
+ meta_type=base_class.meta_type
+ else:
+ meta_type=base_class.__name__
base_module = base_class.__module__
base_name = base_class.__name__
@@ -104,12 +107,12 @@
# Walk up the aq hierarchy, looking for a ZClass
# with the given name.
while 1:
- if hasattr(ob, name):
+ if safe_hasattr(ob, name):
return getattr(ob, name)
- elif hasattr(ob, '_getOb'):
+ elif safe_hasattr(ob, '_getOb'):
try: return ob._getOb(name)
except: pass
- if hasattr(ob, 'aq_parent'):
+ if safe_hasattr(ob, 'aq_parent'):
ob=ob.aq_parent
continue
raise AttributeError, name
@@ -298,7 +301,7 @@
def _setBasesHoldOnToYourButts(self, bases):
# Eeeek
copy=self.__class__(self.id, self.title, bases,
- hasattr(self._zclass_, '_p_deactivate')
+ safe_hasattr(self._zclass_, '_p_deactivate')
)
copy._zclass_.__dict__.update(
@@ -316,7 +319,7 @@
copy._zclass_propertysheets_class)
self._zclass_propertysheets_class=copy._zclass_propertysheets_class
- if hasattr(self.propertysheets.__class__, '_p_oid'):
+ if safe_hasattr(self.propertysheets.__class__, '_p_oid'):
copy.propertysheets.__class__.__dict__.update(
self.propertysheets.__class__.__dict__)
get_transaction().register(
@@ -354,11 +357,11 @@
# for one.
jar=None
while 1:
- if hasattr(self, '_p_jar'):
+ if safe_hasattr(self, '_p_jar'):
jar=self._p_jar
if jar is not None:
return jar
- if not hasattr(self, 'aq_parent'):
+ if not safe_hasattr(self, 'aq_parent'):
return jar
self=self.aq_parent
@@ -454,12 +457,12 @@
except AttributeError:
i.id=id
folder=durl=None
- if hasattr(self, 'Destination'):
+ if safe_hasattr(self, 'Destination'):
d=self.Destination
if d.im_self.__class__ is FactoryDispatcher:
folder=d()
if folder is None: folder=self.aq_parent
- if not hasattr(folder,'_setObject'):
+ if not safe_hasattr(folder,'_setObject'):
folder=folder.aq_parent
folder._setObject(id, i)
@@ -477,7 +480,8 @@
def fromRequest(self, id=None, REQUEST={}):
i=mapply(self._zclass_, (), REQUEST)
- if id is not None and (not hasattr(i, 'id') or not i.id): i.id=id
+ if id is not None and (not safe_hasattr(i, 'id') or not i.id):
+ i.id=id
return i
@@ -565,8 +569,10 @@
def ZClassBaseClassNames(self):
r=[]
for c in self._zbases:
- if hasattr(c, 'id'): r.append(c.id)
- elif hasattr(c, '__name__'): r.append(c.__name__)
+ if safe_hasattr(c, 'id'):
+ r.append(c.id)
+ elif safe_hasattr(c, '__name__'):
+ r.append(c.__name__)
return r
@@ -579,7 +585,7 @@
"Directory listing for FTP"
out=()
files=self.__dict__.items()
- if not (hasattr(self,'isTopLevelPrincipiaApplicationObject') and
+ if not (safe_hasattr(self,'isTopLevelPrincipiaApplicationObject') and
self.isTopLevelPrincipiaApplicationObject):
files.insert(0,('..',self.aq_parent))
for k,v in files:
@@ -638,7 +644,7 @@
"Directory listing for FTP"
out=()
files=self.__dict__.items()
- if not (hasattr(self,'isTopLevelPrincipiaApplicationObject') and
+ if not (safe_hasattr(self,'isTopLevelPrincipiaApplicationObject') and
self.isTopLevelPrincipiaApplicationObject):
files.insert(0,('..',self.aq_parent))
for k,v in files:
More information about the Zope-Checkins
mailing list