Пример #1
0
def context_from_method(fun, args, kwargs):
    """Currently works only for methods by assuming that the first
    argument is `self`. Unfortunately we cannot know the dynamic binding
    for the method because the @transact decorator is invoked at class
    definition time.

    If `self` is already a persistent object with a context attached, then that context
    is returned, otherwise it searches for matching IContextExtractor subscription adpaters.

    """

    that = args[0] if args else None

    context = get_peristent_context(that)

    if that:
        extractors = querySubscriptions(that, IContextExtractor)
        if extractors:
            for i in extractors:
                context.update(i.get_context())

    return context
Пример #2
0
def context(obj):
    if getattr(_context, 'x', None):
        return _context.x
    return get_peristent_context(obj)
Пример #3
0
def context(obj):
    if getattr(_context, 'x', None):
        return _context.x
    return get_peristent_context(obj)