def locate(self, item): key = self.key_reverse(item) if self.wrapper is not None: proxy = self.wrapper(item, name=key, container=self) if IAcquirer.providedBy(proxy): return proxy.__of__(self) return proxy return item
def connectionOfPersistent(obj): """ zope2 cxn fetcher for wrapped items """ if not (IAcquirer.providedBy(obj) or hasattr(obj, '__parent__')): return getattr(obj, '_p_jar', None) for parent in aq_iter(obj): conn = getattr(parent, '_p_jar', None) if conn is not None: return conn
def rewrap_in_request_container(obj, context=None): '''Fix an object's acquisition wrapper to be able to acquire the REQUEST.''' request = getattr(context, 'REQUEST', None) or getRequest() if IAcquirer.providedBy(obj) and request is not None: chain = [] parent = obj while 1: chain.append(parent) parent = aq_parent(aq_inner(parent)) if parent in chain or parent is None or isinstance( parent, RequestContainer): break obj = RequestContainer(REQUEST=request) for ob in reversed(chain): obj = aq_base(ob).__of__(obj) return obj
def aq_iter(obj, error=None): if not (IAcquirer.providedBy(obj) or hasattr(obj, '__parent__')): raise TypeError("%s not acquisition wrapped" % obj) # adapted from alecm's 'listen' seen = set() # get the inner-most wrapper (maybe save some cycles, and prevent # bogus loop detection) cur = aq_inner(obj) while cur is not None: yield cur seen.add(id(aq_base(cur))) cur = getattr(cur, 'aq_parent', getattr(cur, '__parent__', None)) if id(aq_base(cur)) in seen: if error is not None: raise error('__parent__ loop found') break
def aq_iter(obj, error=None): if not (IAcquirer.providedBy(obj) or hasattr(obj, '__parent__')): raise TypeError("%s not acquisition wrapped" % obj) # adapted from alecm's 'listen' seen = set() # get the inner-most wrapper (maybe save some cycles, and prevent # bogus loop detection) cur = aq_inner(obj) while cur is not None: yield cur seen.add(id(aq_base(cur))) cur = getattr(cur, 'aq_parent', getattr(cur, '__parent__', None)) if cur: cur = aq_inner(cur) # unwrap from Acquisition context if id(aq_base(cur)) in seen: if error is not None: raise error('__parent__ loop found') break
def aq_iter(obj, error=None): if not (IAcquirer.providedBy(obj) or hasattr(obj, '__parent__')): raise TypeError("%s not acquisition wrapped" %obj) # adapted from alecm's 'listen' seen = set() # get the inner-most wrapper (maybe save some cycles, and prevent # bogus loop detection) cur = aq_inner(obj) while cur is not None: yield cur seen.add(id(aq_base(cur))) cur = getattr(cur, 'aq_parent', getattr(cur, '__parent__', None)) if id(aq_base(cur)) in seen: # avoid loops resulting from acquisition-less views # whose __parent__ points to # the context whose aq_parent points to the view if error is not None: raise error, '__parent__ loop found' break
def __call__(self, form, request): template = self.template if IAcquirer.providedBy(template): return ImplicitAcquisitionWrapper(template, form) else: return template