nti.externalization.proxy
: Support for transparent proxies¶
Support for working with transparent proxies.
There are times during the externalization process (such as when
computing object identifiers
) that we
need to be working with the “real” object, stripped of any security or
other proxes placed around it. This module provides removeAllProxies
for that purpose.
It is extensible with registerProxyUnwrapper
.
-
removeAllProxies
(proxy)[source]¶ If the object in proxy is proxied by one of the types of proxies known about by this module, remove all of the known proxies, unwrapping down to the original base object.
This module may know about
zope.proxy
,zope.container.contained
, andAcquisition
, if they are installed.>>> from nti.externalization.proxy import removeAllProxies >>> from zope.container.contained import ContainedProxy >>> obj = object() >>> proxy = ContainedProxy(obj) >>> proxy == obj True >>> proxy is obj False >>> removeAllProxies(obj) is obj True >>> removeAllProxies(proxy) is obj True
Changed in version 1.0: The default proxy unwrappers are all optional and will only be registered if they can be imported.
-
registerProxyUnwrapper
(func)[source]¶ Register a function that can unwrap a single proxy from a proxied object. If there is nothing to unwrap, the function should return the given object.
New in version 1.0: This is a provisional way to extend the unwrapping functionality (where speed is critical). It may not be supported in the future.