Update of /cvs-repository/Packages/App
In directory cvs.zope.org:/tmp/cvs-serv32028/lib/python/App

Modified Files:
      Tag: tseaver-hasattr_geddon-branch
        ApplicationManager.py CacheManager.py Common.py 
        DavLockManager.py Extensions.py Factory.py 
        FactoryDispatcher.py Management.py PersistentExtra.py 
        Product.py ProductContext.py ProductRegistry.py Undo.py 
        special_dtml.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/App/ApplicationManager.py 1.88.4.5 => 1.88.4.5.26.1 ===
--- Packages/App/ApplicationManager.py:1.88.4.5 Mon Mar  8 02:58:46 2004
+++ Packages/App/ApplicationManager.py  Sat May 28 20:41:29 2005
@@ -29,6 +29,7 @@
 from cStringIO import StringIO
 from AccessControl import getSecurityManager
 from zExceptions import Redirect
+from ZODB.utils import safe_hasattr
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from cgi import escape
 import zLOG
@@ -191,7 +192,7 @@
         pairs=[]
         append=pairs.append
         for ob, v in dict.items():
-            if hasattr(ob, '__module__'):
+            if safe_hasattr(ob, '__module__'):
                 name='%s.%s' % (ob.__module__, ob.__name__)
             else: name='%s' % ob.__name__
             append((v, name))
@@ -283,7 +284,7 @@
     manage_main._setName('manage_main')
 
     def version_txt(self):
-        if not hasattr(self, '_v_version_txt'):
+        if not safe_hasattr(self, '_v_version_txt'):
             self._v_version_txt=version_txt()
 
         return self._v_version_txt
@@ -342,7 +343,7 @@
 #
 #    def __setstate__(self, v):
 #        ApplicationManager.inheritedAttribute('__setstate__')(self, v)
-#        if not hasattr(self, 'Products'):
+#        if not safe_hasattr(self, 'Products'):
 #            self.Products=ProductFolder()
 
 
@@ -510,7 +511,7 @@
         l = []
         for k,v in socket_map.items():
             # this is only an approximation
-            if hasattr(v, 'port'):
+            if safe_hasattr(v, 'port'):
                 type = str(getattr(v, '__class__', 'unknown'))
                 port = v.port
                 l.append((str(type), 'Port: %s' % port))


=== Packages/App/CacheManager.py 1.27.44.3 => 1.27.44.3.30.1 ===
--- Packages/App/CacheManager.py:1.27.44.3      Mon Nov 17 17:34:02 2003
+++ Packages/App/CacheManager.py        Sat May 28 20:41:29 2005
@@ -18,6 +18,7 @@
 
 import Globals, time, sys
 from DateTime import DateTime
+from ZODB.utils import safe_hasattr
 
 class CacheManager:
     """Cache management mix-in
@@ -230,7 +231,7 @@
 
     def _getActivityMonitor(self):
         db = self._p_jar.db()
-        if not hasattr(db, 'getActivityMonitor'):
+        if not safe_hasattr(db, 'getActivityMonitor'):
             return None
         am = db.getActivityMonitor()
         if am is None:


=== Packages/App/Common.py 1.20 => 1.20.74.1 ===
--- Packages/App/Common.py:1.20 Tue Feb 11 13:42:40 2003
+++ Packages/App/Common.py      Sat May 28 20:41:29 2005
@@ -21,6 +21,7 @@
 
 # Legacy API for this module; 3rd party code may use this.
 from os.path import realpath
+from ZODB.utils import safe_hasattr
 
 
 # These are needed because the various date formats below must
@@ -73,7 +74,7 @@
     # Return the aq_base of an object.
     return getattr(ob, 'aq_base', ob)
 
-def is_acquired(ob, hasattr=hasattr, aq_base=aq_base, absattr=absattr):
+def is_acquired(ob, hasattr=safe_hasattr, aq_base=aq_base, absattr=absattr):
     # Return true if this object is not considered to be
     # a direct subobject of its acquisition parent
     # Used to prevent acquisition side-affects in FTP traversal


=== Packages/App/DavLockManager.py 1.8 => 1.8.132.1 ===
--- Packages/App/DavLockManager.py:1.8  Wed Aug 14 17:31:40 2002
+++ Packages/App/DavLockManager.py      Sat May 28 20:41:29 2005
@@ -15,6 +15,7 @@
 
 import OFS, Acquisition, Globals
 from AccessControl import getSecurityManager, ClassSecurityInfo
+from ZODB.utils import safe_hasattr
 from webdav.Lockable import wl_isLocked
 
 class DavLockManager(OFS.SimpleItem.Item, Acquisition.Implicit):
@@ -78,7 +79,7 @@
         if result is None:
             result = []
         base = Acquisition.aq_base(obj)
-        if not hasattr(base, 'objectItems'):
+        if not safe_hasattr(base, 'objectItems'):
             return result
         try: items = obj.objectItems()
         except: return result
@@ -88,7 +89,7 @@
             if path: p = '%s/%s' % (path, id)
             else: p = id
 
-            dflag = hasattr(ob, '_p_changed') and (ob._p_changed == None)
+            dflag = safe_hasattr(ob, '_p_changed') and (ob._p_changed == None)
             bs = Acquisition.aq_base(ob)
             if wl_isLocked(ob):
                 li = []
@@ -98,7 +99,7 @@
                                  'token':token})
                 addresult((p, li))
                 dflag = 0
-            if hasattr(bs, 'objectItems'):
+            if safe_hasattr(bs, 'objectItems'):
                 self._findapply(ob, result, p)
             if dflag: ob._p_deactivate()
 


=== Packages/App/Extensions.py 1.21.12.2 => 1.21.12.2.30.1 ===
--- Packages/App/Extensions.py:1.21.12.2        Mon Nov 17 17:34:02 2003
+++ Packages/App/Extensions.py  Sat May 28 20:41:29 2005
@@ -20,6 +20,8 @@
 import os, zlib, imp
 import Products
 from zExceptions import NotFound
+from ZODB.utils import safe_hasattr
+
 path_split=os.path.split
 path_join=os.path.join
 exists=os.path.exists
@@ -171,7 +173,7 @@
         if v == class_name: raise ValueError, (
             'The class, %s, is not defined in file, %s' % (class_name, module))
 
-    if not hasattr(c,'__bases__'): raise ValueError, (
+    if not safe_hasattr(c,'__bases__'): raise ValueError, (
         '%s, is not a class' % class_name)
 
     return c


=== Packages/App/Factory.py 1.27 => 1.27.64.1 ===
--- Packages/App/Factory.py:1.27        Wed May 14 10:43:44 2003
+++ Packages/App/Factory.py     Sat May 28 20:41:29 2005
@@ -16,6 +16,7 @@
 __version__='$Revision$'[11:-2]
 
 import OFS.SimpleItem, Acquisition, Globals, AccessControl.Role
+from ZODB.utils import safe_hasattr
 
 class Factory(
     AccessControl.Role.RoleManager,
@@ -69,7 +70,7 @@
 
     def manage_afterAdd(self, item, container):
         import Product  # local to avoid circular import
-        if hasattr(self, 'aq_parent'):
+        if safe_hasattr(self, 'aq_parent'):
             container=self.aq_parent
         elif item is not self:
             container=None
@@ -79,7 +80,7 @@
 
     def manage_beforeDelete(self, item, container):
         import Product  # local to avoid circular import
-        if hasattr(self, 'aq_parent'):
+        if safe_hasattr(self, 'aq_parent'):
             container=self.aq_parent
         elif item is not self:
             container=None


=== Packages/App/FactoryDispatcher.py 1.21 => 1.21.132.1 ===
--- Packages/App/FactoryDispatcher.py:1.21      Wed Aug 14 17:31:40 2002
+++ Packages/App/FactoryDispatcher.py   Sat May 28 20:41:29 2005
@@ -16,6 +16,7 @@
 import Acquisition, sys, Products
 from AccessControl.PermissionMapping import aqwrap
 from AccessControl.Owned import UnownableOwner
+from ZODB.utils import safe_hasattr
 
 class ProductDispatcher(Acquisition.Implicit):
     " "
@@ -44,7 +45,7 @@
     _owner=UnownableOwner
 
     def __init__(self, product, dest, REQUEST=None):
-        if hasattr(product,'aq_base'): product=product.aq_base
+        if safe_hasattr(product,'aq_base'): product=product.aq_base
         self._product=product
         self._d=dest
         if REQUEST is not None:
@@ -74,7 +75,7 @@
     def __getattr__(self, name):
         p=self.__dict__['_product']
         d=p.__dict__
-        if hasattr(p,name) and d.has_key(name):
+        if safe_hasattr(p,name) and d.has_key(name):
             m=d[name]
             w=getattr(m, '_permissionMapper', None)
             if w is not None:


=== Packages/App/Management.py 1.61.68.4 => 1.61.68.4.28.1 ===
--- Packages/App/Management.py:1.61.68.4        Thu Jan  8 18:33:45 2004
+++ Packages/App/Management.py  Sat May 28 20:41:29 2005
@@ -20,6 +20,7 @@
 from Dialogs import MessageDialog
 from Globals import DTMLFile, HTMLFile
 from zExceptions import Redirect
+from ZODB.utils import safe_hasattr
 from AccessControl import getSecurityManager, Unauthorized
 from cgi import escape
 
@@ -62,7 +63,7 @@
                 if validate(None, self, None, o):
                     result.append(d)
             except:
-                if not hasattr(o, '__roles__'):
+                if not safe_hasattr(o, '__roles__'):
                     result.append(d)
 
         return result


=== Packages/App/PersistentExtra.py 1.8 => 1.8.124.1 ===
--- Packages/App/PersistentExtra.py:1.8 Wed Aug 14 17:31:40 2002
+++ Packages/App/PersistentExtra.py     Sat May 28 20:41:29 2005
@@ -61,7 +61,8 @@
         # BoboPOS 2 code:
         jar=self._p_jar
         if jar is None:
-            if hasattr(self,'aq_parent') and hasattr(self.aq_parent, '_p_jar'):
+            if (safe_hasattr(self,'aq_parent')
+            and safe_hasattr(self.aq_parent, '_p_jar')):
                 jar=self.aq_parent._p_jar
             if jar is None: return 0
         if not jar.name: return 0


=== Packages/App/Product.py 1.63.2.3 => 1.63.2.3.30.1 ===
--- Packages/App/Product.py:1.63.2.3    Mon Nov 17 17:34:02 2003
+++ Packages/App/Product.py     Sat May 28 20:41:29 2005
@@ -48,6 +48,7 @@
 from Permission import PermissionManager
 import RefreshFuncs
 from App.config import getConfiguration
+from ZODB.utils import safe_hasattr
 
 
 class ProductFolder(Folder):
@@ -292,7 +293,7 @@
         Returns the ProductHelp object associated
         with the Product.
         """
-        if not hasattr(self, 'Help'):
+        if not safe_hasattr(self, 'Help'):
             self._setObject('Help', ProductHelp('Help', self.id))
         return self.Help
 
@@ -495,8 +496,10 @@
     products=app.Control_Panel.Products
     fver = ''
 
-    if hasattr(productp, '__import_error__'): ie=productp.__import_error__
-    else: ie=None
+    if safe_hasattr(productp, '__import_error__'):
+        ie=productp.__import_error__
+    else:
+        ie=None
 
     # Retrieve version number from any suitable version.txt
     for fname in ('version.txt', 'VERSION.txt', 'VERSION.TXT'):
@@ -514,7 +517,7 @@
         if ihasattr(products,name):
             old=getattr(products, name)
             if ihasattr(old,'version') and old.version==fver:
-                if hasattr(old, 'import_error_') and \
+                if safe_hasattr(old, 'import_error_') and \
                    old.import_error_==ie:
                     # Version hasn't changed. Don't reinitialize.
                     return old
@@ -588,7 +591,7 @@
     return product
 
 def ihasattr(o, name):
-    return hasattr(o, name) and o.__dict__.has_key(name)
+    return safe_hasattr(o, name) and o.__dict__.has_key(name)
 
 
 def doInstall():


=== Packages/App/ProductContext.py 1.43 => 1.43.56.1 ===
--- Packages/App/ProductContext.py:1.43 Fri May  2 18:01:34 2003
+++ Packages/App/ProductContext.py      Sat May 28 20:41:29 2005
@@ -25,10 +25,13 @@
 from types import ListType, TupleType
 from Interface.Implements import instancesOfObjectImplements
 from App.Product import doInstall
+from ZODB.utils import safe_hasattr
 
 import ZClasses # to enable 'PC.registerBaseClass()'
 
-if not hasattr(Products, 'meta_types'): Products.meta_types=()
+if not hasattr(Products, 'meta_types'):
+    Products.meta_types=()
+
 if not hasattr(Products, 'meta_classes'):
     Products.meta_classes={}
     Products.meta_class_info={}
@@ -166,7 +169,7 @@
 
             fd = pack.__FactoryDispatcher__ = __FactoryDispatcher__
 
-        if not hasattr(pack, '_m'): pack._m=fd.__dict__
+        if not safe_hasattr(pack, '_m'): pack._m=fd.__dict__
         m=pack._m
 
         if interfaces is _marker:
@@ -201,7 +204,7 @@
             name=os.path.split(icon)[1]
             icon=Globals.ImageFile(icon, self.__pack.__dict__)
             icon.__roles__=None
-            if not hasattr(OFS.misc_.misc_, pid):
+            if not safe_hasattr(OFS.misc_.misc_, pid):
                 setattr(OFS.misc_.misc_, pid, OFS.misc_.Misc_(pid, {}))
             getattr(OFS.misc_.misc_, pid)[name]=icon
 
@@ -215,7 +218,8 @@
         #
         base_class=Z._zclass_
         if meta_type is None:
-            if hasattr(base_class, 'meta_type'): meta_type=base_class.meta_type
+            if safe_hasattr(base_class, 'meta_type'):
+                meta_type=base_class.meta_type
             else:                                meta_type=base_class.__name__
 
         module=base_class.__module__


=== Packages/App/ProductRegistry.py 1.15.68.1 => 1.15.68.1.30.1 ===
--- Packages/App/ProductRegistry.py:1.15.68.1   Mon Nov 17 17:34:03 2003
+++ Packages/App/ProductRegistry.py     Sat May 28 20:41:29 2005
@@ -22,6 +22,7 @@
 # ....what?
 
 from OFS.Folder import Folder
+from ZODB.utils import safe_hasattr
 
 class ProductRegistryMixin:
     # This class implements a protocol for registering products that
@@ -116,7 +117,7 @@
     # method. Until Jim has time to look into this, this aq_maybe method
     # appears to be an effective work-around...
     def aq_maybe(self, name):
-        if hasattr(self, name):
+        if safe_hasattr(self, name):
             return getattr(self, name)
         return self.aq_acquire(name)
 
@@ -171,7 +172,7 @@
 
     def _setProductRegistryData(self, name, v):
         name='_product_%s' % name
-        if hasattr(self, name):
+        if safe_hasattr(self, name):
             return setattr(self, name, v)
         else:
             raise AttributeError, name


=== Packages/App/Undo.py 1.32.44.1 => 1.32.44.1.34.1 ===
--- Packages/App/Undo.py:1.32.44.1      Mon Jul 21 12:35:11 2003
+++ Packages/App/Undo.py        Sat May 28 20:41:29 2005
@@ -21,6 +21,7 @@
 from DateTime import DateTime
 import Globals, ExtensionClass
 from ZopeUndo.Prefix import Prefix
+from ZODB.utils import safe_hasattr
 
 class UndoSupport(ExtensionClass.Base):
 
@@ -46,15 +47,15 @@
         )
 
     def get_request_var_or_attr(self, name, default):
-        if hasattr(self, 'REQUEST'):
+        if safe_hasattr(self, 'REQUEST'):
             REQUEST=self.REQUEST
             if REQUEST.has_key(name): return REQUEST[name]
-            if hasattr(self, name): v=getattr(self, name)
+            if safe_hasattr(self, name): v=getattr(self, name)
             else: v=default
             REQUEST[name]=v
             return v
         else:
-            if hasattr(self, name): v=getattr(self, name)
+            if safe_hasattr(self, name): v=getattr(self, name)
             else: v=default
             return v
 
@@ -81,7 +82,7 @@
         # by any member of a user folder in the place where the user
         # is defined.
         user = getSecurityManager().getUser()
-        if hasattr(user, 'aq_parent'):
+        if safe_hasattr(user, 'aq_parent'):
             path = '/'.join(user.aq_parent.getPhysicalPath()[1:-1])
         else:
             path=''


=== Packages/App/special_dtml.py 1.25.12.1 => 1.25.12.1.30.1 ===
--- Packages/App/special_dtml.py:1.25.12.1      Mon Nov 17 17:34:03 2003
+++ Packages/App/special_dtml.py        Sat May 28 20:41:29 2005
@@ -15,6 +15,7 @@
 from types import InstanceType
 from zLOG import LOG,WARNING
 from App.config import getConfiguration
+from ZODB.utils import safe_hasattr
 
 class HTML(DocumentTemplate.HTML,Persistence.Persistent,):
     "Persistent HTML Document Templates"
@@ -46,7 +47,7 @@
             if mtime != self._v_last_read:
                 self.cook()
                 self._v_last_read=mtime
-        elif not hasattr(self,'_v_cooked'):
+        elif not safe_hasattr(self,'_v_cooked'):
             try: changed=self.__changed__()
             except: changed=1
             self.cook()
@@ -85,7 +86,7 @@
     def _get__roles__(self):
         imp = getattr(aq_parent(aq_inner(self)),
                       '%s__roles__' % self.__name__)
-        if hasattr(imp, '__of__'):
+        if safe_hasattr(imp, '__of__'):
             return imp.__of__(self)
         return imp
 
@@ -143,7 +144,7 @@
             # We're first, so get the REQUEST.
             try:
                 req = self.aq_acquire('REQUEST')
-                if hasattr(req, 'taintWrapper'):
+                if safe_hasattr(req, 'taintWrapper'):
                     req = req.taintWrapper()
             except: pass
             bound_data['REQUEST'] = req

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to