[Zope] Finding an object in a folder

Dieter Maurer dieter at handshake.de
Mon May 30 13:54:20 EDT 2005


Paul Winkler wrote at 2005-5-27 16:28 -0400:
>On Tue, May 24, 2005 at 08:59:01PM +0200, Dieter Maurer wrote:
>> An incredibly long time ago, I filed a feature request for
>> "hasattr_unacquired" -- together with patch, unit tests and documentation
>> update. 
>
>Do you mean this?
>http://www.zope.org/Collectors/Zope/742

Probably.

>the unit tests and docs are missing.

In what almost surely was the source for the patch,
I see:

--- Products/OFSP/help/dtml-funcs.stx~	2002-01-09 18:44:05.000000000 +0100
+++ Products/OFSP/help/dtml-funcs.stx	2002-12-21 16:19:49.000000000 +0100
@@ -55,6 +55,9 @@
     getattr(object, name) and seeing whether it raises an exception or
     not.)
 
+    hasattr_unacquired(object, string) -- like "hasattr" but only
+    unacquired attributes are taken into account.
+
     hash(object) -- Return the hash value of the object (if it has
     one). Hash values are integers. They are used to quickly compare
     dictionary keys during a dictionary lookup. Numeric values that compare

I.e. the description of "hasattr_unacquired" for Zope's embedded
online help (the only docs Zope contains itself).


Indeed, I did the unit test extension only later (and only to prevent
the test suite to fail -- I trusted my 3 line extension :-).
I added to ".../AccessControl/tests/actual_python.py":

  # After all the above, these wrappers were still untouched:
  #     ['DateTime', '_print_', 'reorder', 'same_type', 'test']
+ # DM 2004-07-09: 'hasattr_unacquired' untouched, too
  # So do something to touch them.
  def f9():
+     # DM 2004-07-09: 'hasattr_unacquired'...
+     class C: x=1
+     c = C()
+     assert hasattr_unacquired(c,'x')
+     assert not hasattr_unacquired(c,'xx')
  
      d = DateTime()


A more elaborate test would add:

  from ExtensionClass import Base
  from Acquisition import Implicit

  class B(Base): x=1
  class C(Implicit): y=1
  c = C().__of__(B())
  assert not hasattr_unacquired(c, 'x')
  assert hasattr_unacquired(c, 'y')

-- 
Dieter


More information about the Zope mailing list