Пример #1
0
 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
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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
Пример #6
0
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
Пример #7
0
 def __call__(self, form, request):
     template = self.template
     if IAcquirer.providedBy(template):
         return ImplicitAcquisitionWrapper(template, form)
     else:
         return template
Пример #8
0
 def __call__(self, form, request):
     template = self.template
     if IAcquirer.providedBy(template):
         return ImplicitAcquisitionWrapper(template, form)
     else:
         return template