[Zope-Checkins] CVS: Packages/OFS - Application.py:1.191.2.14.4.1
Cache.py:1.10.68.1.32.1 CopySupport.py:1.85.2.10.2.1
DTMLDocument.py:1.48.68.3.30.1 FindSupport.py:1.31.68.3.22.1
Image.py:1.145.2.11.2.1 ObjectManager.py:1.163.12.12.2.1
OrderSupport.py:1.2.2.5.2.1 PropertyManager.py:1.52.2.4.30.1
PropertySheets.py:1.89.4.10.6.1 SimpleItem.py:1.106.12.2.32.1
Traversable.py:1.19.4.3.32.1 ZDOM.py:1.12.134.1
Tres Seaver
tseaver at palladion.com
Sat May 28 20:42:12 EDT 2005
Update of /cvs-repository/Packages/OFS
In directory cvs.zope.org:/tmp/cvs-serv32028/lib/python/OFS
Modified Files:
Tag: tseaver-hasattr_geddon-branch
Application.py Cache.py CopySupport.py DTMLDocument.py
FindSupport.py Image.py ObjectManager.py OrderSupport.py
PropertyManager.py PropertySheets.py SimpleItem.py
Traversable.py ZDOM.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/OFS/Application.py 1.191.2.14 => 1.191.2.14.4.1 ===
--- Packages/OFS/Application.py:1.191.2.14 Tue Jan 18 11:21:13 2005
+++ Packages/OFS/Application.py Sat May 28 20:41:31 2005
@@ -30,6 +30,7 @@
import ZDOM
from zLOG import LOG, ERROR, WARNING, INFO
from zExceptions import Redirect as RedirectException, Forbidden
+from ZODB.utils import safe_hasattr
from HelpSys.HelpSys import HelpSys
from Acquisition import aq_base
from App.Product import doInstall
@@ -200,7 +201,8 @@
finished_dict[id(base)] = None
try:
# Try to re-register ZClasses if they need it.
- if hasattr(base,'_register') and hasattr(base,'_zclass_'):
+ if (safe_hasattr(base,'_register')
+ and safe_hasattr(base,'_zclass_')):
class_id=getattr(base._zclass_, '__module__', None)
if class_id and not reg_has_key(class_id):
ob._register()
@@ -210,14 +212,14 @@
'Registered ZClass: %s' % ob.id
)
# Include subobjects.
- if hasattr(base, 'objectItems'):
+ if safe_hasattr(base, 'objectItems'):
m = list(ob.objectItems())
items.extend(m)
# Try to find ZClasses-in-ZClasses.
- if hasattr(base, 'propertysheets'):
+ if safe_hasattr(base, 'propertysheets'):
ps = ob.propertysheets
- if (hasattr(ps, 'methods') and
- hasattr(ps.methods, 'objectItems')):
+ if (safe_hasattr(ps, 'methods') and
+ safe_hasattr(ps.methods, 'objectItems')):
m = list(ps.methods.objectItems())
items.extend(m)
except:
@@ -311,14 +313,14 @@
app = self.getApp()
# Ensure that Control Panel exists.
- if not hasattr(app, 'Control_Panel'):
+ if not safe_hasattr(app, 'Control_Panel'):
cpl=ApplicationManager()
cpl._init()
app._setObject('Control_Panel', cpl)
self.commit('Added Control_Panel')
# b/c: Ensure that a ProductFolder exists.
- if not hasattr(aq_base(app.Control_Panel), 'Products'):
+ if not safe_hasattr(aq_base(app.Control_Panel), 'Products'):
app.Control_Panel.Products=App.Product.ProductFolder()
self.commit('Added Control_Panel.Products')
@@ -370,7 +372,7 @@
# Ensure that there is a transient object container in the temp folder
config = getConfiguration()
- if not hasattr(aq_base(tf), 'session_data'):
+ if not safe_hasattr(aq_base(tf), 'session_data'):
from Products.Transience.Transience import TransientObjectContainer
addnotify = getattr(config, 'session_add_notify_script_path', None)
delnotify = getattr(config, 'session_delete_notify_script_path',
@@ -427,7 +429,7 @@
# do nothing if we've already installed one
return
# Ensure that a browser ID manager exists
- if not hasattr(app, 'browser_id_manager'):
+ if not safe_hasattr(app, 'browser_id_manager'):
from Products.Sessions.BrowserIdManager import BrowserIdManager
bid = BrowserIdManager('browser_id_manager', 'Browser Id Manager')
app._setObject('browser_id_manager', bid)
@@ -440,7 +442,7 @@
# do nothing if we've already installed one
return
# Ensure that a session data manager exists
- if not hasattr(app, 'session_data_manager'):
+ if not safe_hasattr(app, 'session_data_manager'):
from Products.Sessions.SessionDataManager import SessionDataManager
sdm = SessionDataManager('session_data_manager',
title='Session Data Manager',
@@ -454,12 +456,13 @@
app = self.getApp()
# Ensure that Owner role exists.
- if hasattr(app, '__ac_roles__') and not ('Owner' in app.__ac_roles__):
+ if (safe_hasattr(app, '__ac_roles__')
+ and not ('Owner' in app.__ac_roles__)):
app.__ac_roles__=app.__ac_roles__ + ('Owner',)
self.commit('Added Owner role')
# ensure the Authenticated role exists.
- if hasattr(app, '__ac_roles__'):
+ if safe_hasattr(app, '__ac_roles__'):
if not 'Authenticated' in app.__ac_roles__:
app.__ac_roles__=app.__ac_roles__ + ('Authenticated',)
self.commit('Added Authenticated role')
@@ -478,9 +481,9 @@
app = self.getApp()
# Install the initial user.
- if hasattr(app, 'acl_users'):
+ if safe_hasattr(app, 'acl_users'):
users = app.acl_users
- if hasattr(users, '_createInitialUser'):
+ if safe_hasattr(users, '_createInitialUser'):
app.acl_users._createInitialUser()
self.commit('Created initial user')
@@ -491,7 +494,7 @@
return
# Install an error_log
- if not hasattr(app, 'error_log'):
+ if not safe_hasattr(app, 'error_log'):
from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog
error_log = SiteErrorLog()
app._setObject('error_log', error_log)
@@ -502,8 +505,10 @@
app = self.getApp()
if app._getInitializerFlag('virtual_hosting'):
return
- if not app.objectIds('Virtual Host Monster') and not hasattr(app, 'virtual_hosting'):
- from Products.SiteAccess.VirtualHostMonster import VirtualHostMonster
+ if (not app.objectIds('Virtual Host Monster')
+ and not safe_hasattr(app, 'virtual_hosting')):
+ from Products.SiteAccess.VirtualHostMonster \
+ import VirtualHostMonster
vhm=VirtualHostMonster()
vhm.id='virtual_hosting'
vhm.addToContainer(app)
@@ -671,7 +676,7 @@
pname="Products.%s" % product_name
try:
product=__import__(pname, global_dict, global_dict, silly)
- if hasattr(product, '__module_aliases__'):
+ if safe_hasattr(product, '__module_aliases__'):
for k, v in product.__module_aliases__:
if not have_module(k):
if type(v) is _st and have_module(v): v=modules[v]
@@ -777,7 +782,7 @@
for name,method in pgetattr(
product, 'methods', {}).items():
- if not hasattr(Folder.Folder, name):
+ if not safe_hasattr(Folder.Folder, name):
setattr(Folder.Folder, name, method)
if name[-9:]!='__roles__': # not Just setting roles
if (permissions.has_key(name) and
@@ -826,13 +831,13 @@
if ext == '.dtml':
ob = Globals.DTMLFile(base, std_dir)
fn = base
- if hasattr(app, fn):
+ if safe_hasattr(app, fn):
continue
app.manage_addProduct['OFSP'].manage_addDTMLMethod(
id=fn, file=open(ob.raw))
elif ext in ('.pt', '.zpt'):
ob = PageTemplateFile(fn, std_dir, __name__=fn)
- if hasattr(app, fn):
+ if safe_hasattr(app, fn):
continue
app.manage_addProduct['PageTemplates'].manage_addPageTemplate(
id=fn, title='', text=open(ob.filename))
@@ -895,11 +900,14 @@
def pgetattr(product, name, default=install_products, __init__=0):
- if not __init__ and hasattr(product, name): return getattr(product, name)
- if hasattr(product, '__init__'):
+ if not __init__ and safe_hasattr(product, name):
+ return getattr(product, name)
+ if safe_hasattr(product, '__init__'):
product=product.__init__
- if hasattr(product, name): return getattr(product, name)
+ if safe_hasattr(product, name):
+ return getattr(product, name)
- if default is not install_products: return default
+ if default is not install_products:
+ return default
raise AttributeError, name
=== Packages/OFS/Cache.py 1.10.68.1 => 1.10.68.1.32.1 ===
--- Packages/OFS/Cache.py:1.10.68.1 Mon Nov 17 17:34:07 2003
+++ Packages/OFS/Cache.py Sat May 28 20:41:31 2005
@@ -24,6 +24,7 @@
from AccessControl import getSecurityManager
from AccessControl.Role import _isBeingUsedAsAMethod
from AccessControl import Unauthorized
+from ZODB.utils import safe_hasattr
ZCM_MANAGERS = '__ZCacheManager_ids__'
@@ -54,7 +55,7 @@
It causes objects to be found only if they are
in the list of cache managers.
'''
- if (hasattr(aq_base(container), ZCM_MANAGERS) and
+ if (safe_hasattr(aq_base(container), ZCM_MANAGERS) and
name in getattr(container, ZCM_MANAGERS)):
return 1
return 0
@@ -292,7 +293,7 @@
ob = self
used_ids = {}
while ob is not None:
- if hasattr(aq_base(ob), ZCM_MANAGERS):
+ if safe_hasattr(aq_base(ob), ZCM_MANAGERS):
ids = getattr(ob, ZCM_MANAGERS)
for id in ids:
manager = getattr(ob, id, None)
@@ -384,7 +385,7 @@
subobs = ob.objectValues()
for subob in subobs:
subpath = path + (subob.getId(),)
- if hasattr(aq_base(subob), 'objectValues'):
+ if safe_hasattr(aq_base(subob), 'objectValues'):
if sm.checkPermission(
'Access contents information', subob):
findCacheables(
=== Packages/OFS/CopySupport.py 1.85.2.10 => 1.85.2.10.2.1 ===
--- Packages/OFS/CopySupport.py:1.85.2.10 Fri Feb 18 08:47:16 2005
+++ Packages/OFS/CopySupport.py Sat May 28 20:41:31 2005
@@ -23,6 +23,7 @@
from AccessControl.Permissions import delete_objects as DeleteObjects
from Acquisition import aq_base, aq_inner, aq_parent
from zExceptions import Unauthorized, BadRequest
+from ZODB.utils import safe_hasattr
from webdav.Lockable import ResourceLockedError
from cgi import escape
@@ -48,7 +49,7 @@
def _setOb(self, id, object): setattr(self, id, object)
def _delOb(self, id): delattr(self, id)
def _getOb(self, id, default=_marker):
- if hasattr(aq_base(self), id):
+ if safe_hasattr(aq_base(self), id):
return getattr(self, id)
if default is _marker:
raise AttributeError, id
@@ -335,14 +336,14 @@
# (the object will not yet have been connected to the acquisition
# heirarchy).
- if not hasattr(object, 'meta_type'):
+ if not safe_hasattr(object, 'meta_type'):
raise CopyError, MessageDialog(
title = 'Not Supported',
message = ('The object <EM>%s</EM> does not support this' \
' operation' % escape(absattr(object.id))),
action = 'manage_main')
- if not hasattr(self, 'all_meta_types'):
+ if not safe_hasattr(self, 'all_meta_types'):
raise CopyError, MessageDialog(
title = 'Not Supported',
message = 'Cannot paste into this object.',
@@ -472,7 +473,7 @@
def cb_isCopyable(self):
# Is object copyable? Returns 0 or 1
- if not (hasattr(self, '_canCopy') and self._canCopy(0)):
+ if not (safe_hasattr(self, '_canCopy') and self._canCopy(0)):
return 0
if not self.cb_userHasCopyOrMovePermission():
return 0
@@ -480,9 +481,9 @@
def cb_isMoveable(self):
# Is object moveable? Returns 0 or 1
- if not (hasattr(self, '_canCopy') and self._canCopy(1)):
+ if not (safe_hasattr(self, '_canCopy') and self._canCopy(1)):
return 0
- if hasattr(self, '_p_jar') and self._p_jar is None:
+ if safe_hasattr(self, '_p_jar') and self._p_jar is None:
return 0
try: n=aq_parent(aq_inner(self))._reserved_names
except: n=()
=== Packages/OFS/DTMLDocument.py 1.48.68.3 => 1.48.68.3.30.1 ===
--- Packages/OFS/DTMLDocument.py:1.48.68.3 Thu Jan 8 18:33:47 2004
+++ Packages/OFS/DTMLDocument.py Sat May 28 20:41:31 2005
@@ -27,6 +27,7 @@
import Globals
from AccessControl import getSecurityManager
from zExceptions.TracebackSupplement import PathTracebackSupplement
+from ZODB.utils import safe_hasattr
done='done'
@@ -108,7 +109,7 @@
__traceback_supplement__ = (PathTracebackSupplement, self)
kw['document_id'] =self.getId()
kw['document_title']=self.title
- if hasattr(self, 'aq_explicit'):
+ if safe_hasattr(self, 'aq_explicit'):
bself=self.aq_explicit
else: bself=self
=== Packages/OFS/FindSupport.py 1.31.68.3 => 1.31.68.3.22.1 ===
--- Packages/OFS/FindSupport.py:1.31.68.3 Fri Jun 4 12:47:16 2004
+++ Packages/OFS/FindSupport.py Sat May 28 20:41:31 2005
@@ -23,6 +23,7 @@
from string import translate
from AccessControl.DTML import RestrictedDTML
from AccessControl import ClassSecurityInfo
+from ZODB.utils import safe_hasattr
class FindSupport(ExtensionClass.Base):
"""Find support for Zope Folders"""
@@ -81,10 +82,10 @@
obj_expr=(Eval(obj_expr), md, md._push, md._pop)
base=obj
- if hasattr(obj, 'aq_base'):
+ if safe_hasattr(obj, 'aq_base'):
base=obj.aq_base
- if hasattr(base, 'objectItems'):
+ if safe_hasattr(base, 'objectItems'):
try: items=obj.objectItems()
except: return result
else:
@@ -103,24 +104,24 @@
else: p=id
dflag=0
- if hasattr(ob, '_p_changed') and (ob._p_changed == None):
+ if safe_hasattr(ob, '_p_changed') and (ob._p_changed == None):
dflag=1
- if hasattr(ob, 'aq_base'):
+ if safe_hasattr(ob, 'aq_base'):
bs=ob.aq_base
else: bs=ob
if (
(not obj_ids or absattr(bs.getId()) in obj_ids)
and
- (not obj_metatypes or (hasattr(bs, 'meta_type') and
+ (not obj_metatypes or (safe_hasattr(bs, 'meta_type') and
bs.meta_type in obj_metatypes))
and
(not obj_searchterm or
- (hasattr(ob, 'PrincipiaSearchSource') and
+ (safe_hasattr(ob, 'PrincipiaSearchSource') and
ob.PrincipiaSearchSource().find(str(obj_searchterm)) >= 0)
or
- (hasattr(ob, 'SearchableText') and
+ (safe_hasattr(ob, 'SearchableText') and
ob.SearchableText().find(str(obj_searchterm)) >= 0)
)
and
@@ -136,7 +137,7 @@
dflag=0
is_zclass = getattr(bs, 'meta_type', None) == 'Z Class'
- if search_sub and (hasattr(bs, 'objectItems') or is_zclass):
+ if search_sub and (safe_hasattr(bs, 'objectItems') or is_zclass):
if is_zclass:
subob = ob.propertysheets.methods
sub_p = '%s/propertysheets/methods' % p
@@ -189,10 +190,10 @@
obj_expr=(Eval(obj_expr), md, md._push, md._pop)
base=obj
- if hasattr(obj, 'aq_base'):
+ if safe_hasattr(obj, 'aq_base'):
base=obj.aq_base
- if not hasattr(base, 'objectItems'):
+ if not safe_hasattr(base, 'objectItems'):
return result
try: items=obj.objectItems()
except: return result
@@ -206,21 +207,21 @@
else: p=id
dflag=0
- if hasattr(ob, '_p_changed') and (ob._p_changed == None):
+ if safe_hasattr(ob, '_p_changed') and (ob._p_changed == None):
dflag=1
- if hasattr(ob, 'aq_base'):
+ if safe_hasattr(ob, 'aq_base'):
bs=ob.aq_base
else: bs=ob
if (
(not obj_ids or absattr(bs.getId()) in obj_ids)
and
- (not obj_metatypes or (hasattr(bs, 'meta_type') and
+ (not obj_metatypes or (safe_hasattr(bs, 'meta_type') and
bs.meta_type in obj_metatypes))
and
(not obj_searchterm or
- (hasattr(ob, 'PrincipiaSearchSource') and
+ (safe_hasattr(ob, 'PrincipiaSearchSource') and
ob.PrincipiaSearchSource().find(obj_searchterm) >= 0
))
and
@@ -238,7 +239,7 @@
add_result((p, ob))
dflag=0
- if search_sub and hasattr(bs, 'objectItems'):
+ if search_sub and safe_hasattr(bs, 'objectItems'):
self.ZopeFindAndApply(ob, obj_ids, obj_metatypes,
obj_searchterm, obj_expr,
obj_mtime, obj_mspec,
@@ -267,7 +268,7 @@
-def mtime_match(ob, t, q, fn=hasattr):
+def mtime_match(ob, t, q, fn=safe_hasattr):
if not fn(ob, '_p_mtime'):
return 0
return q=='<' and (ob._p_mtime < t) or (ob._p_mtime > t)
@@ -278,11 +279,11 @@
fn=pr.append
while 1:
- if hasattr(ob, permission):
+ if safe_hasattr(ob, permission):
p=getattr(ob, permission)
if type(p) is lt:
map(fn, p)
- if hasattr(ob, 'aq_parent'):
+ if safe_hasattr(ob, 'aq_parent'):
ob=ob.aq_parent
continue
break
@@ -293,7 +294,7 @@
map(fn, ('Manager', 'Anonymous'))
break
- if hasattr(ob, 'aq_parent'):
+ if safe_hasattr(ob, 'aq_parent'):
ob=ob.aq_parent
continue
break
=== Packages/OFS/Image.py 1.145.2.11 => 1.145.2.11.2.1 ===
--- Packages/OFS/Image.py:1.145.2.11 Thu Jan 27 13:47:11 2005
+++ Packages/OFS/Image.py Sat May 28 20:41:31 2005
@@ -29,6 +29,7 @@
from DateTime import DateTime
from Cache import Cacheable
from mimetools import choose_boundary
+from ZODB.utils import safe_hasattr
from ZPublisher import HTTPRangeSupport
from ZPublisher.HTTPRequest import FileUpload
from ZPublisher.Iterators import filestream_iterator
@@ -366,12 +367,12 @@
# we were able to handle this by returning a 304
return ''
- if self.precondition and hasattr(self, str(self.precondition)):
+ if self.precondition and safe_hasattr(self, str(self.precondition)):
# Grab whatever precondition was defined and then
# execute it. The precondition will raise an exception
# if something violates its terms.
c=getattr(self, str(self.precondition))
- if hasattr(c,'isDocTemp') and c.isDocTemp:
+ if safe_hasattr(c,'isDocTemp') and c.isDocTemp:
c(REQUEST['PARENTS'][1],REQUEST)
else:
c()
@@ -492,7 +493,7 @@
if isinstance(file, FileUpload) and not file:
raise ValueError, 'File not specified'
- if hasattr(file, '__class__') and file.__class__ is Pdata:
+ if safe_hasattr(file, '__class__') and file.__class__ is Pdata:
size=len(file)
return file, size
@@ -831,7 +832,7 @@
def cookId(id, title, file):
- if not id and hasattr(file,'filename'):
+ if not id and safe_hasattr(file,'filename'):
filename=file.filename
title=title or filename
id=filename[max(filename.rfind('/'),
=== Packages/OFS/ObjectManager.py 1.163.12.12 => 1.163.12.12.2.1 ===
--- Packages/OFS/ObjectManager.py:1.163.12.12 Sun Mar 27 11:36:23 2005
+++ Packages/OFS/ObjectManager.py Sat May 28 20:41:31 2005
@@ -29,6 +29,7 @@
from AccessControl.SecurityInfo import ClassSecurityInfo
from webdav.Lockable import ResourceLockedError
from ZODB.POSException import ConflictError
+from ZODB.utils import safe_hasattr
from urllib import quote
from cStringIO import StringIO
import marshal
@@ -75,7 +76,7 @@
# An object by the given id exists either in this
# ObjectManager or in the acquisition path.
flags = getattr(obj, '__replaceable__', NOT_REPLACEABLE)
- if hasattr(aq_base(self), id):
+ if safe_hasattr(aq_base(self), id):
# The object is located in this ObjectManager.
if not flags & REPLACEABLE:
raise BadRequest, (
@@ -161,8 +162,9 @@
# Look at _product_meta_types, if there is one
_pmt=()
- if hasattr(self, '_product_meta_types'): _pmt=self._product_meta_types
- elif hasattr(self, 'aq_acquire'):
+ if safe_hasattr(self, '_product_meta_types'):
+ _pmt=self._product_meta_types
+ elif safe_hasattr(self, 'aq_acquire'):
try: _pmt=self.aq_acquire('_product_meta_types')
except: pass
external_candidates.extend(list(_pmt))
@@ -238,7 +240,7 @@
# sub-items are returned. That could have a measurable hit
# on performance as things are currently implemented, so for
# the moment we just make sure not to expose private attrs.
- if id[:1] != '_' and hasattr(aq_base(self), id):
+ if id[:1] != '_' and safe_hasattr(aq_base(self), id):
return getattr(self, id)
if default is _marker:
raise AttributeError, id
@@ -265,7 +267,7 @@
# Try to give user the local role "Owner", but only if
# no local roles have been set on the object yet.
- if hasattr(object, '__ac_local_roles__'):
+ if safe_hasattr(object, '__ac_local_roles__'):
if object.__ac_local_roles__ is None:
user=getSecurityManager().getUser()
if user is not None:
@@ -280,7 +282,7 @@
for object in self.objectValues():
try: s=object._p_changed
except: s=0
- if hasattr(aq_base(object), 'manage_afterAdd'):
+ if safe_hasattr(aq_base(object), 'manage_afterAdd'):
object.manage_afterAdd(item, container)
if s is None: object._p_deactivate()
@@ -288,7 +290,7 @@
for object in self.objectValues():
try: s=object._p_changed
except: s=0
- if hasattr(aq_base(object), 'manage_afterClone'):
+ if safe_hasattr(aq_base(object), 'manage_afterClone'):
object.manage_afterClone(item)
if s is None: object._p_deactivate()
@@ -297,7 +299,7 @@
try: s=object._p_changed
except: s=0
try:
- if hasattr(aq_base(object), 'manage_beforeDelete'):
+ if safe_hasattr(aq_base(object), 'manage_beforeDelete'):
object.manage_beforeDelete(item, container)
except BeforeDeleteException, ob:
raise
@@ -368,13 +370,17 @@
return tuple(map(lambda dict: dict.copy(), self._objects))
def objectIds_d(self,t=None):
- if hasattr(self, '_reserved_names'): n=self._reserved_names
- else: n=()
- if not n: return self.objectIds(t)
+ if safe_hasattr(self, '_reserved_names'):
+ n=self._reserved_names
+ else:
+ n=()
+ if not n:
+ return self.objectIds(t)
r=[]
a=r.append
for id in self.objectIds(t):
- if id not in n: a(id)
+ if id not in n:
+ a(id)
return r
def objectValues_d(self,t=None):
@@ -388,13 +394,17 @@
return r
def objectMap_d(self,t=None):
- if hasattr(self, '_reserved_names'): n=self._reserved_names
- else: n=()
- if not n: return self._objects
+ if safe_hasattr(self, '_reserved_names'):
+ n=self._reserved_names
+ else:
+ n=()
+ if not n:
+ return self._objects
r=[]
a=r.append
for d in self._objects:
- if d['id'] not in n: a(d.copy())
+ if d['id'] not in n:
+ a(d.copy())
return r
def superValues(self,t):
@@ -408,9 +418,10 @@
have=seen.has_key
x=0
while x < 100:
- if not hasattr(obj,'_getOb'): break
+ if not safe_hasattr(obj,'_getOb'):
+ break
get=obj._getOb
- if hasattr(obj,'_objects'):
+ if safe_hasattr(obj,'_objects'):
for i in obj._objects:
try:
id=i['id']
@@ -420,7 +431,7 @@
seen[physicalPath]=1
except: pass
- if hasattr(obj,'aq_parent'):
+ if safe_hasattr(obj,'aq_parent'):
obj=obj.aq_parent
relativePhysicalPath = ('..',) + relativePhysicalPath
else:
@@ -467,22 +478,22 @@
def tpValues(self):
# Return a list of subobjects, used by tree tag.
r=[]
- if hasattr(aq_base(self), 'tree_ids'):
+ if safe_hasattr(aq_base(self), 'tree_ids'):
tree_ids=self.tree_ids
try: tree_ids=list(tree_ids)
except TypeError:
pass
- if hasattr(tree_ids, 'sort'):
+ if safe_hasattr(tree_ids, 'sort'):
tree_ids.sort()
for id in tree_ids:
- if hasattr(self, id):
+ if safe_hasattr(self, id):
r.append(self._getOb(id))
else:
obj_ids=self.objectIds()
obj_ids.sort()
for id in obj_ids:
o=self._getOb(id)
- if hasattr(o, 'isPrincipiaFolderish') and \
+ if safe_hasattr(o, 'isPrincipiaFolderish') and \
o.isPrincipiaFolderish:
r.append(o)
return r
@@ -493,7 +504,8 @@
if not id:
# can't use getId() here (breaks on "old" exported objects)
id=self.id
- if hasattr(id, 'im_func'): id=id()
+ if safe_hasattr(id, 'im_func'):
+ id=id()
ob=self
else: ob=self._getOb(id)
@@ -561,7 +573,8 @@
filepath, customImporters=customImporters)
if verify: self._verifyObjectPaste(ob, validate_src=0)
id=ob.id
- if hasattr(id, 'im_func'): id=id()
+ if safe_hasattr(id, 'im_func'):
+ id=id()
self._setObject(id, ob, set_owner=set_owner)
# try to make ownership implicit if possible in the context
@@ -580,7 +593,7 @@
while 1:
if App.Common.is_acquired(ob):
raise ValueError('FTP List not supported on acquired objects')
- if not hasattr(ob,'aq_parent'):
+ if not safe_hasattr(ob,'aq_parent'):
break
ob=ob.aq_parent
@@ -609,7 +622,7 @@
files.sort()
- if not (hasattr(self,'isTopLevelPrincipiaApplicationObject') and
+ if not (safe_hasattr(self,'isTopLevelPrincipiaApplicationObject') and
self.isTopLevelPrincipiaApplicationObject):
files.insert(0,('..',self.aq_parent))
files.insert(0, ('.', self))
@@ -662,7 +675,7 @@
def __getitem__(self, key):
v=self._getOb(key, None)
if v is not None: return v
- if hasattr(self, 'REQUEST'):
+ if safe_hasattr(self, 'REQUEST'):
request=self.REQUEST
method=request.get('REQUEST_METHOD', 'GET')
if request.maybe_webdav_client and not method in ('GET', 'POST'):
@@ -687,11 +700,13 @@
def all_meta_types(self, interfaces=None):
if interfaces is None:
- if hasattr(self, '_product_interfaces'):
+ if safe_hasattr(self, '_product_interfaces'):
interfaces=self._product_interfaces
- elif hasattr(self, 'aq_acquire'):
- try: interfaces=self.aq_acquire('_product_interfaces')
- except: pass # Bleah generic pass is bad
+ elif safe_hasattr(self, 'aq_acquire'):
+ try:
+ interfaces=self.aq_acquire('_product_interfaces')
+ except:
+ pass # Bleah generic pass is bad
return ObjectManager.all_meta_types(self, interfaces)
=== Packages/OFS/OrderSupport.py 1.2.2.5 => 1.2.2.5.2.1 ===
--- Packages/OFS/OrderSupport.py:1.2.2.5 Wed Jan 26 10:37:26 2005
+++ Packages/OFS/OrderSupport.py Sat May 28 20:41:31 2005
@@ -23,6 +23,7 @@
from Acquisition import aq_base
from DocumentTemplate.sequence import sort
from Globals import InitializeClass
+from ZODB.utils import safe_hasattr
from IOrderSupport import IOrderedContainer
from ObjectManager import ObjectManager
@@ -260,15 +261,15 @@
def tpValues(self):
# Return a list of subobjects, used by tree tag.
r=[]
- if hasattr(aq_base(self), 'tree_ids'):
+ if safe_hasattr(aq_base(self), 'tree_ids'):
tree_ids=self.tree_ids
try: tree_ids=list(tree_ids)
except TypeError:
pass
- if hasattr(tree_ids, 'sort'):
+ if safe_hasattr(tree_ids, 'sort'):
tree_ids.sort()
for id in tree_ids:
- if hasattr(self, id):
+ if safe_hasattr(self, id):
r.append(self._getOb(id))
else:
# this part is different from the ObjectManager code
=== Packages/OFS/PropertyManager.py 1.52.2.4 => 1.52.2.4.30.1 ===
--- Packages/OFS/PropertyManager.py:1.52.2.4 Thu Jan 8 18:33:47 2004
+++ Packages/OFS/PropertyManager.py Sat May 28 20:41:31 2005
@@ -24,6 +24,7 @@
from zExceptions import BadRequest
from cgi import escape
from types import ListType
+from ZODB.utils import safe_hasattr
class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
@@ -122,8 +123,10 @@
propertysheets=vps(DefaultPropertySheets)
def valid_property_id(self, id):
- if not id or id[:1]=='_' or (id[:3]=='aq_') \
- or (' ' in id) or hasattr(aq_base(self), id) or escape(id) != id:
+ if (not id or id[:1]=='_' or (id[:3]=='aq_')
+ or (' ' in id)
+ or safe_hasattr(aq_base(self), id)
+ or escape(id) != id):
return 0
return 1
@@ -151,7 +154,7 @@
def _wrapperCheck(self, object):
# Raise an error if an object is wrapped.
- if hasattr(object, 'aq_base'):
+ if safe_hasattr(object, 'aq_base'):
raise ValueError, 'Invalid property value: wrapped object'
return
@@ -174,7 +177,7 @@
raise BadRequest, 'Invalid or duplicate property id'
if type in ('selection', 'multiple selection'):
- if not hasattr(self, value):
+ if not safe_hasattr(self, value):
raise BadRequest, 'No select variable %s' % value
self._properties=self._properties + (
{'id':id, 'type':type, 'select_variable':value},)
@@ -333,7 +336,7 @@
propdict=self.propdict()
nd=self._reserved_names
for id in ids:
- if not hasattr(aq_base(self), id):
+ if not safe_hasattr(aq_base(self), id):
raise BadRequest, (
'The property <em>%s</em> does not exist' % escape(id))
if (not 'd' in propdict[id].get('mode', 'wd')) or (id in nd):
=== Packages/OFS/PropertySheets.py 1.89.4.10 => 1.89.4.10.6.1 ===
--- Packages/OFS/PropertySheets.py:1.89.4.10 Mon Jan 3 15:10:40 2005
+++ Packages/OFS/PropertySheets.py Sat May 28 20:41:31 2005
@@ -24,6 +24,7 @@
from webdav.common import urlbase
from ExtensionClass import Base
from Globals import Persistent
+from ZODB.utils import safe_hasattr
from Traversable import Traversable
from Acquisition import aq_base
from AccessControl import getSecurityManager
@@ -181,7 +182,7 @@
def _wrapperCheck(self, object):
# Raise an error if an object is wrapped.
- if hasattr(object, 'aq_base'):
+ if safe_hasattr(object, 'aq_base'):
raise ValueError, 'Invalid property value: wrapped object'
return
@@ -198,7 +199,7 @@
'Properties cannot be added to this property sheet')
pself=self.p_self()
self=self.v_self()
- if hasattr(aq_base(self),id):
+ if safe_hasattr(aq_base(self),id):
if not (id=='title' and not self.__dict__.has_key(id)):
raise BadRequest, (
'Invalid property id, <em>%s</em>. It is in use.' %
@@ -253,7 +254,7 @@
if not self.hasProperty(id):
raise BadRequest, 'The property %s does not exist.' % escape(id)
vself=self.v_self()
- if hasattr(vself, '_reserved_names'):
+ if safe_hasattr(vself, '_reserved_names'):
nd=vself._reserved_names
else: nd=()
if (not 'd' in self.propertyInfo(id).get('mode', 'wd')) or (id in nd):
@@ -331,7 +332,7 @@
else:
# It's a non-xml property. Escape value.
attrs=''
- if not hasattr(self,"dav__"+name):
+ if not safe_hasattr(self,"dav__"+name):
value = xml_escape(value)
prop=' <n:%s%s>%s</n:%s>' % (name, attrs, value, name)
@@ -382,7 +383,7 @@
else:
# It's a non-xml property. Escape value.
attrs=''
- if not hasattr(self, 'dav__%s' % name):
+ if not safe_hasattr(self, 'dav__%s' % name):
value = xml_escape(value)
prop='<n:%s%s xmlns:n="%s">%s</n:%s>\n' % (
name, attrs, xml_id, value, name)
@@ -503,7 +504,7 @@
def getProperty(self, id, default=None):
method='dav__%s' % id
- if not hasattr(self, method):
+ if not safe_hasattr(self, method):
return default
return getattr(self, method)()
@@ -518,7 +519,7 @@
def _propertyMap(self):
# Only use getlastmodified if returns a value
- if hasattr(self.v_self(), '_p_mtime'):
+ if safe_hasattr(self.v_self(), '_p_mtime'):
return self.pm + ({'id':'getlastmodified', 'mode':'r'},)
return self.pm
@@ -543,21 +544,21 @@
def dav__getcontenttype(self):
vself=self.v_self()
- if hasattr(vself, 'content_type'):
+ if safe_hasattr(vself, 'content_type'):
return absattr(vself.content_type)
- if hasattr(vself, 'default_content_type'):
+ if safe_hasattr(vself, 'default_content_type'):
return absattr(vself.default_content_type)
return ''
def dav__getcontentlength(self):
vself=self.v_self()
- if hasattr(vself, 'get_size'):
+ if safe_hasattr(vself, 'get_size'):
return vself.get_size()
return ''
def dav__source(self):
vself=self.v_self()
- if hasattr(vself, 'document_src'):
+ if safe_hasattr(vself, 'document_src'):
url=urlbase(vself.absolute_url())
return '\n <n:link>\n' \
' <n:src>%s</n:src>\n' \
@@ -648,7 +649,7 @@
propsets=self.__propsets__()
r=[]
for n in propsets:
- if hasattr(n,'id'): id=n.id
+ if safe_hasattr(n,'id'): id=n.id
else: id=''
r.append((id, n.__of__(self)))
@@ -656,8 +657,9 @@
def get(self, name, default=None):
for propset in self.__propsets__():
- if propset.id==name or (hasattr(propset, 'xml_namespace') and \
- propset.xml_namespace()==name):
+ if (propset.id == name
+ or (safe_hasattr(propset, 'xml_namespace') and
+ propset.xml_namespace()==name)):
return propset.__of__(self)
return default
=== Packages/OFS/SimpleItem.py 1.106.12.2 => 1.106.12.2.32.1 ===
--- Packages/OFS/SimpleItem.py:1.106.12.2 Tue Dec 16 09:50:13 2003
+++ Packages/OFS/SimpleItem.py Sat May 28 20:41:31 2005
@@ -35,6 +35,7 @@
from zExceptions import Redirect
import time
from zLOG import LOG, BLATHER
+from ZODB.utils import safe_hasattr
import marshal
import ZDOM
@@ -68,7 +69,7 @@
return name()
if name is not None:
return name
- if hasattr(self, '__name__'):
+ if safe_hasattr(self, '__name__'):
return self.__name__
raise AttributeError, 'This object has no id'
@@ -159,10 +160,10 @@
error_tb = tb
# turn error_type into a string
- if hasattr(error_type, '__name__'):
+ if safe_hasattr(error_type, '__name__'):
error_type=error_type.__name__
- if hasattr(self, '_v_eek'):
+ if safe_hasattr(self, '_v_eek'):
# Stop if there is recursion.
raise error_type, error_value, tb
self._v_eek=1
@@ -186,7 +187,7 @@
if not REQUEST: REQUEST=self.aq_acquire('REQUEST')
try:
- if hasattr(client, 'standard_error_message'):
+ if safe_hasattr(client, 'standard_error_message'):
s=getattr(client, 'standard_error_message')
else:
client = client.aq_parent
@@ -218,7 +219,7 @@
"to render the standard error message.)")
raise error_type, v, tb
finally:
- if hasattr(self, '_v_eek'): del self._v_eek
+ if safe_hasattr(self, '_v_eek'): del self._v_eek
tb=None
def manage(self, URL1):
@@ -239,8 +240,8 @@
mode=0100000
# check read permissions
- if (hasattr(aq_base(self),'manage_FTPget') and
- hasattr(self.manage_FTPget, '__roles__')):
+ if (safe_hasattr(aq_base(self),'manage_FTPget') and
+ safe_hasattr(self.manage_FTPget, '__roles__')):
try:
if getSecurityManager().validateValue(self.manage_FTPget):
mode=mode | 0440
@@ -250,7 +251,8 @@
mode=mode | 0004
# check write permissions
- if hasattr(aq_base(self),'PUT') and hasattr(self.PUT, '__roles__'):
+ if (safe_hasattr(aq_base(self),'PUT')
+ and safe_hasattr(self.PUT, '__roles__')):
try:
if getSecurityManager().validateValue(self.PUT):
mode=mode | 0220
@@ -260,20 +262,20 @@
mode=mode | 0002
# get size
- if hasattr(aq_base(self), 'get_size'):
+ if safe_hasattr(aq_base(self), 'get_size'):
size=self.get_size()
- elif hasattr(aq_base(self),'manage_FTPget'):
+ elif safe_hasattr(aq_base(self),'manage_FTPget'):
size=len(self.manage_FTPget())
else:
size=0
# get modification time
- if hasattr(aq_base(self), 'bobobase_modification_time'):
+ if safe_hasattr(aq_base(self), 'bobobase_modification_time'):
mtime=self.bobobase_modification_time().timeTime()
else:
mtime=time.time()
# get owner and group
owner=group='Zope'
- if hasattr(aq_base(self), 'get_local_roles'):
+ if safe_hasattr(aq_base(self), 'get_local_roles'):
for user, roles in self.get_local_roles():
if 'Owner' in roles:
owner=user
@@ -288,7 +290,7 @@
while 1:
if App.Common.is_acquired(ob):
raise ValueError('FTP List not supported on acquired objects')
- if not hasattr(ob,'aq_parent'):
+ if not safe_hasattr(ob,'aq_parent'):
break
ob=ob.aq_parent
=== Packages/OFS/Traversable.py 1.19.4.3 => 1.19.4.3.32.1 ===
--- Packages/OFS/Traversable.py:1.19.4.3 Wed Dec 10 12:53:31 2003
+++ Packages/OFS/Traversable.py Sat May 28 20:41:31 2005
@@ -21,6 +21,7 @@
from AccessControl import Unauthorized
from AccessControl.ZopeGuards import guarded_getattr
from ZODB.POSException import ConflictError
+from ZODB.utils import safe_hasattr
from urllib import quote
NotFound = 'NotFound'
@@ -112,7 +113,7 @@
if not path: return self
get=getattr
- has=hasattr
+ has=safe_hasattr
N=None
M=_marker
=== Packages/OFS/ZDOM.py 1.12 => 1.12.134.1 ===
--- Packages/OFS/ZDOM.py:1.12 Wed Aug 14 17:42:56 2002
+++ Packages/OFS/ZDOM.py Sat May 28 20:41:31 2005
@@ -16,6 +16,7 @@
All standard Zope objects support DOM to a limited extent.
"""
import Acquisition
+from ZODB.utils import safe_hasattr
# Node type codes
@@ -141,7 +142,7 @@
"""The Document object associated with this node.
When this is a document this is None"""
node = self
- if hasattr(node, 'aq_parent'):
+ if safe_hasattr(node, 'aq_parent'):
node = self.aq_parent
return node.getOwnerDocument()
return node
@@ -316,7 +317,7 @@
def getPreviousSibling(self):
"""The node immediately preceding this node. If
there is no such node, this returns None."""
- if hasattr(self, 'aq_parent'):
+ if safe_hasattr(self, 'aq_parent'):
parent = self.aq_parent
ids=list(parent.objectIds())
id=self.id
@@ -330,7 +331,7 @@
def getNextSibling(self):
"""The node immediately preceding this node. If
there is no such node, this returns None."""
- if hasattr(self, 'aq_parent'):
+ if safe_hasattr(self, 'aq_parent'):
parent = self.aq_parent
ids=list(parent.objectIds())
id=self.id
@@ -365,7 +366,7 @@
if (child.getNodeType()==ELEMENT_NODE and \
child.getTagName()==tagname or tagname== '*'):
nodeList.append(child)
- if hasattr(child, 'getElementsByTagName'):
+ if safe_hasattr(child, 'getElementsByTagName'):
n1 = child.getElementsByTagName(tagname)
nodeList = nodeList + n1._data
return NodeList(nodeList)
@@ -419,7 +420,7 @@
def getAttribute(self, name):
"""Retrieves an attribute value by name."""
- if name=='title' and hasattr(self.aq_base, 'title'):
+ if name=='title' and safe_hasattr(self.aq_base, 'title'):
return self.title
return ''
More information about the Zope-Checkins
mailing list