[Checkins]
SVN: zc.sourcefactory/trunk/src/zc/sourcefactory/browser/token.
removeing the security proxy before getting the _p_oid for
the token of a persistent object. Otherwise we'll never get
it directly but only from the parent for security proxied objects
Christian Zagrodnick
cz at gocept.com
Mon Oct 15 06:43:41 EDT 2007
Log message for revision 80878:
removeing the security proxy before getting the _p_oid for the token of a persistent object. Otherwise we'll never get it directly but only from the parent for security proxied objects
Changed:
U zc.sourcefactory/trunk/src/zc/sourcefactory/browser/token.py
U zc.sourcefactory/trunk/src/zc/sourcefactory/browser/token.txt
-=-
Modified: zc.sourcefactory/trunk/src/zc/sourcefactory/browser/token.py
===================================================================
--- zc.sourcefactory/trunk/src/zc/sourcefactory/browser/token.py 2007-10-15 10:42:49 UTC (rev 80877)
+++ zc.sourcefactory/trunk/src/zc/sourcefactory/browser/token.py 2007-10-15 10:43:41 UTC (rev 80878)
@@ -59,21 +59,22 @@
# Persistent objects are identified by their oid. If it is persistent but
# not added to the database, we try to get to the parent, add the value to
# the database and get the oid then.
+ # We have to remove proxies to avoid security here.
+ value_unproxied = zope.proxy.removeAllProxies(value)
try:
- oid = value._p_oid
+ oid = value_unproxied._p_oid
except AttributeError:
oid = None
if oid is None:
if not hasattr(value, '__parent__'):
raise ValueError('Can not determine OID for %r' % value)
- # We have to remove proxies to avoid security here.
- value_unproxied = zope.proxy.removeAllProxies(value)
connection = ZODB.interfaces.IConnection(value_unproxied.__parent__)
connection.add(value_unproxied)
oid = value_unproxied._p_oid
return ZODB.utils.oid_repr(oid)
+
@zope.component.adapter(zope.interface.interfaces.IInterface)
@zope.interface.implementer(zc.sourcefactory.interfaces.IToken)
def fromInterface(value):
Modified: zc.sourcefactory/trunk/src/zc/sourcefactory/browser/token.txt
===================================================================
--- zc.sourcefactory/trunk/src/zc/sourcefactory/browser/token.txt 2007-10-15 10:42:49 UTC (rev 80877)
+++ zc.sourcefactory/trunk/src/zc/sourcefactory/browser/token.txt 2007-10-15 10:43:41 UTC (rev 80878)
@@ -54,7 +54,8 @@
Traceback (most recent call last):
ValueError: Can not determine OID for <PersistentDummy object at 0x...>
-Security proxied objects are unpacked to get to their connection attributed::
+Security proxied objects are unwrapped to get to their oid or connection
+attribute::
>>> from zope.security.proxy import ProxyFactory
>>> p3 = PersistentDummy()
@@ -63,11 +64,22 @@
>>> p3p = ProxyFactory(p3)
>>> p3p._p_jar
Traceback (most recent call last):
+ ...
ForbiddenAttribute: ('_p_jar', <PersistentDummy object at 0x...>)
>>> zc.sourcefactory.browser.token.fromPersistent(p3p)
'0x...'
+
+As a side-effect `p3` now has an _p_oid assigned. When an object already has
+an OID the connection is not queried, so a __parent__ would not be necessary:
+
+ >>> del p3.__parent__
+ >>> zc.sourcefactory.browser.token.fromPersistent(p3p)
+ '0x...'
+
+
+
Interfaces
==========
More information about the Checkins
mailing list