| """ |
""" |
| |
|
| from zope.security.checker import ProxyFactory |
from zope.security.checker import ProxyFactory |
| from zope.security.proxy import getProxiedObject |
from zope.security.proxy import removeSecurityProxy |
| from zope.app.location import ILocation, Location |
from zope.app.location import ILocation, Location |
| |
|
| class TrustedAdapterFactory(object): |
class TrustedAdapterFactory(object): |
| And the object proxied is not. (We actually have to remove the |
And the object proxied is not. (We actually have to remove the |
| adapter to get to the adapted object in this case.) |
adapter to get to the adapted object in this case.) |
| |
|
| >>> a = getProxiedObject(a) |
>>> a = removeSecurityProxy(a) |
| >>> type(a.context).__name__ |
>>> type(a.context).__name__ |
| 'list' |
'list' |
| |
|
| >>> a = TM(p, o2, o3) |
>>> a = TM(p, o2, o3) |
| >>> type(a).__name__ |
>>> type(a).__name__ |
| '_Proxy' |
'_Proxy' |
| >>> a = getProxiedObject(a) |
>>> a = removeSecurityProxy(a) |
| >>> a.context[0] is o, a.context[1] is o2, a.context[2] is o3 |
>>> a.context[0] is o, a.context[1] is o2, a.context[2] is o3 |
| (True, True, True) |
(True, True, True) |
| |
|
| >>> a = TM(p, ProxyFactory(o2), ProxyFactory(o3)) |
>>> a = TM(p, ProxyFactory(o2), ProxyFactory(o3)) |
| >>> type(a).__name__ |
>>> type(a).__name__ |
| '_Proxy' |
'_Proxy' |
| >>> a = getProxiedObject(a) |
>>> a = removeSecurityProxy(a) |
| >>> a.context[0] is o, a.context[1] is o2, a.context[2] is o3 |
>>> a.context[0] is o, a.context[1] is o2, a.context[2] is o3 |
| (True, True, True) |
(True, True, True) |
| |
|
| |
|
| >>> TL(o).__parent__ is o |
>>> TL(o).__parent__ is o |
| True |
True |
| >>> getProxiedObject(TL(p)).__parent__ is o |
>>> removeSecurityProxy(TL(p)).__parent__ is o |
| True |
True |
| |
|
| The factory adapter has the __name__ and __module__ of the factory it adapts: |
The factory adapter has the __name__ and __module__ of the |
| |
factory it adapts: |
| |
|
| >>> (TA.__module__, TA.__name__) == (A.__module__, A.__name__) |
>>> (TA.__module__, TA.__name__) == (A.__module__, A.__name__) |
| True |
True |
| |
|
| def __call__(self, *args): |
def __call__(self, *args): |
| for arg in args: |
for arg in args: |
| if getProxiedObject(arg) is not arg: |
if removeSecurityProxy(arg) is not arg: |
| args = map(getProxiedObject, args) |
args = map(removeSecurityProxy, args) |
| adapter = self.factory(*args) |
adapter = self.factory(*args) |
| if (ILocation.providedBy(adapter) |
if (ILocation.providedBy(adapter) |
| and adapter.__parent__ is None): |
and adapter.__parent__ is None): |