Update of /cvs-repository/Packages/Shared/DC/ZRDB In directory cvs.zope.org:/tmp/cvs-serv32028/lib/python/Shared/DC/ZRDB
Modified Files: Tag: tseaver-hasattr_geddon-branch Aqueduct.py Connection.py DA.py RDB.py Results.py Search.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/Shared/DC/ZRDB/Aqueduct.py 1.56.68.3 => 1.56.68.3.12.1 === --- Packages/Shared/DC/ZRDB/Aqueduct.py:1.56.68.3 Sun Nov 14 16:35:03 2004 +++ Packages/Shared/DC/ZRDB/Aqueduct.py Sat May 28 20:41:36 2005 @@ -25,6 +25,7 @@ from AccessControl.Role import RoleManager from DocumentTemplate import HTML from zExceptions import Redirect +from ZODB.utils import safe_hasattr from string import strip, replace @@ -134,7 +135,7 @@ __traceback_info__=o q=getattr(o,id) try: - if hasattr(q,'_searchable_arguments'): + if safe_hasattr(q,'_searchable_arguments'): try: q=q.__of__(self.aq_parent) except: pass return q === Packages/Shared/DC/ZRDB/Connection.py 1.35.68.4 => 1.35.68.4.28.1 === --- Packages/Shared/DC/ZRDB/Connection.py:1.35.68.4 Thu Jan 8 18:33:58 2004 +++ Packages/Shared/DC/ZRDB/Connection.py Sat May 28 20:41:36 2005 @@ -28,6 +28,7 @@ from cgi import escape import DocumentTemplate, RDB from zExceptions import BadRequest +from ZODB.utils import safe_hasattr class Connection( Globals.Persistent, @@ -75,7 +76,7 @@ def title_and_id(self): s=Connection.inheritedAttribute('title_and_id')(self) - if hasattr(self, '_v_connected') and self._v_connected: + if safe_hasattr(self, '_v_connected') and self._v_connected: s="%s, which is connected" % s else: s="%s, which is <font color=red> not connected</font>" % s @@ -83,7 +84,7 @@ def title_or_id(self): s=Connection.inheritedAttribute('title_or_id')(self) - if hasattr(self, '_v_connected') and self._v_connected: + if safe_hasattr(self, '_v_connected') and self._v_connected: s="%s (connected)" % s else: s="%s (<font color=red> not connected</font>)" % s @@ -147,7 +148,7 @@ def manage_close_connection(self, REQUEST=None): " " try: - if hasattr(self,'_v_database_connection'): + if safe_hasattr(self,'_v_database_connection'): self._v_database_connection.close() except: LOG('Shared.DC.ZRDB.Connection', === Packages/Shared/DC/ZRDB/DA.py 1.110.12.7 => 1.110.12.7.22.1 === --- Packages/Shared/DC/ZRDB/DA.py:1.110.12.7 Sun May 16 11:17:30 2004 +++ Packages/Shared/DC/ZRDB/DA.py Sat May 28 20:41:36 2005 @@ -39,8 +39,11 @@ from webdav.Resource import Resource from webdav.Lockable import ResourceLockedError from zExceptions import BadRequest -try: from IOBTree import Bucket -except: Bucket=lambda:{} +from ZODB.utils import safe_hasattr +try: + from IOBTree import Bucket +except: + Bucket=lambda:{} class DatabaseError(BadRequest): @@ -359,8 +362,10 @@ query = query + ('\nDBConnId: %s' % self.connection_hook, ) # Try to fetch from cache - if hasattr(self,'_v_cache'): cache=self._v_cache - else: cache=self._v_cache={}, Bucket() + if safe_hasattr(self,'_v_cache'): + cache=self._v_cache + else: + cache=self._v_cache={}, Bucket() cache, tcache = cache max_cache=self.max_cache_ now=time() @@ -403,10 +408,13 @@ __traceback_supplement__ = (SQLMethodTracebackSupplement, self) if REQUEST is None: - if kw: REQUEST=kw + if kw: + REQUEST=kw else: - if hasattr(self, 'REQUEST'): REQUEST=self.REQUEST - else: REQUEST={} + if safe_hasattr(self, 'REQUEST'): + REQUEST=self.REQUEST + else: + REQUEST={} # connection hook c = self.connection_id @@ -425,7 +433,7 @@ except: raise DatabaseError, ( '%s is not connected to a database' % self.id) - if hasattr(self, 'aq_parent'): + if safe_hasattr(self, 'aq_parent'): p=self.aq_parent if self._isBeingAccessedAsZClassDefinedInstanceMethod(): p=p.aq_parent @@ -453,7 +461,8 @@ result=self._cached_result(DB__, (query, self.max_rows_)) else: result=DB__.query(query, self.max_rows_) - if hasattr(self, '_v_brain'): brain=self._v_brain + if safe_hasattr(self, '_v_brain'): + brain=self._v_brain else: brain=self._v_brain=getBrain(self.class_file_, self.class_name_) @@ -486,15 +495,15 @@ if len(results) > 1: raise KeyError, key else: raise KeyError, key r=results[0] - # if hasattr(self, 'aq_parent'): r=r.__of__(self.aq_parent) + # if safe_hasattr(self, 'aq_parent'): r=r.__of__(self.aq_parent) return r self._arg[key] # raise KeyError if not an arg return Traverse(self,{},key) def connectionIsValid(self): - return (hasattr(self, self.connection_id) and - hasattr(getattr(self, self.connection_id), 'connected')) + return (safe_hasattr(self, self.connection_id) and + safe_hasattr(getattr(self, self.connection_id), 'connected')) def connected(self): return getattr(getattr(self, self.connection_id), 'connected')() @@ -506,7 +515,7 @@ Z=getattr(Z, 'aq_self', Z) for d in self.aq_acquire('_getProductRegistryData')('zclasses'): z=d['meta_class'] - if hasattr(z._zclass_,'_p_deactivate'): + if safe_hasattr(z._zclass_,'_p_deactivate'): # Eek, persistent continue x={} @@ -561,12 +570,12 @@ except: raise KeyError, key else: raise KeyError, key r=results[0] - # if hasattr(da, 'aq_parent'): r=r.__of__(da.aq_parent) + # if safe_hasattr(da, 'aq_parent'): r=r.__of__(da.aq_parent) self._r=r if key is self: return r - if hasattr(r,'__bobo_traverse__'): + if safe_hasattr(r,'__bobo_traverse__'): try: return r.__bobo_traverse__(REQUEST, key) except: pass @@ -578,7 +587,8 @@ def __getattr__(self, name): r=self.__dict__['_r'] - if hasattr(r, name): return getattr(r,name) + if safe_hasattr(r, name): + return getattr(r,name) return getattr(self.__dict__['_da'], name) === Packages/Shared/DC/ZRDB/RDB.py 1.33 => 1.33.132.1 === --- Packages/Shared/DC/ZRDB/RDB.py:1.33 Wed Aug 14 17:50:59 2002 +++ Packages/Shared/DC/ZRDB/RDB.py Sat May 28 20:41:36 2005 @@ -23,6 +23,7 @@ from Record import Record from Acquisition import Implicit import ExtensionClass +from ZODB.utils import safe_hasattr def parse_text(s): if find(s,'\\') < 0 and (find(s,'\\t') < 0 and find(s,'\\n') < 0): return s @@ -143,11 +144,13 @@ # Add SQL Aliases d=r.__dict__ for k, v in aliases: - if not hasattr(r,k): d[k]=v + if not safe_hasattr(r,k): + d[k]=v - if hasattr(brains, '__init__'): + if safe_hasattr(brains, '__init__'): binit=brains.__init__ - if hasattr(binit,'im_func'): binit=binit.im_func + if safe_hasattr(binit,'im_func'): + binit=binit.im_func def __init__(self, data, parent, binit=binit): Record.__init__(self,data) binit(self.__of__(parent)) === Packages/Shared/DC/ZRDB/Results.py 1.14 => 1.14.118.1 === --- Packages/Shared/DC/ZRDB/Results.py:1.14 Wed Aug 14 17:50:59 2002 +++ Packages/Shared/DC/ZRDB/Results.py Sat May 28 20:41:36 2005 @@ -15,6 +15,7 @@ from string import strip, lower, upper, join from Acquisition import Implicit from Record import Record +from ZODB.utils import safe_hasattr class SQLAlias(ExtensionClass.Base): def __init__(self, name): self._n=name @@ -75,11 +76,13 @@ # Add SQL Aliases d=r.__dict__ for k, v in aliases: - if not hasattr(r,k): d[k]=v + if not safe_hasattr(r,k): + d[k]=v - if hasattr(brains, '__init__'): + if safe_hasattr(brains, '__init__'): binit=brains.__init__ - if hasattr(binit,'im_func'): binit=binit.im_func + if safe_hasattr(binit,'im_func'): + binit=binit.im_func def __init__(self, data, parent, binit=binit): Record.__init__(self,data) if parent is not None: self=self.__of__(parent) === Packages/Shared/DC/ZRDB/Search.py 1.20.68.3 => 1.20.68.3.12.1 === --- Packages/Shared/DC/ZRDB/Search.py:1.20.68.3 Sun Nov 14 16:35:03 2004 +++ Packages/Shared/DC/ZRDB/Search.py Sat May 28 20:41:36 2005 @@ -16,10 +16,12 @@ __version__='$Revision$'[11:-2] from Globals import DTMLFile -from Aqueduct import custom_default_report, custom_default_zpt_report, nicify, Args +from Aqueduct import custom_default_report, custom_default_zpt_report +from Aqueduct import nicify, Args from string import join from cgi import escape from AccessControl import getSecurityManager +from ZODB.utils import safe_hasattr addForm=DTMLFile('dtml/searchAdd', globals()) def manage_addZSearch(self, report_id, report_title, report_style, @@ -125,7 +127,7 @@ try: id=i['id'] if (not old(id) and - hasattr(getattr(o,id),'_searchable_arguments') + safe_hasattr(getattr(o,id),'_searchable_arguments') ): t.append(i['id']) ids[id]=1 @@ -146,7 +148,7 @@ __traceback_info__=o q=getattr(o,id) try: - if hasattr(q,'_searchable_arguments'): + if safe_hasattr(q,'_searchable_arguments'): try: q=q.__of__(self.aq_parent) except: pass return q _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins