コード例 #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
ファイル: db.py プロジェクト: Cloudxtreme/opennode-management
def context(obj):
    if getattr(_context, 'x', None):
        return _context.x
    return get_peristent_context(obj)
コード例 #3
0
ファイル: db.py プロジェクト: bbc88ks/opennode-management
def context(obj):
    if getattr(_context, 'x', None):
        return _context.x
    return get_peristent_context(obj)