PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /proc/self/root/opt/alt/python37/lib/python3.7/site-packages/raven/utils/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //proc/self/root/opt/alt/python37/lib/python3.7/site-packages/raven/utils/transaction.py

from __future__ import absolute_import

from threading import local


class TransactionContext(object):
    def __init__(self, stack, context):
        self.stack = stack
        self.context = context

    def __enter__(self):
        self.stack.push(self.context)
        return self

    def __exit__(self, *exc_info):
        self.stack.pop(self.context)


class TransactionStack(local):
    def __init__(self):
        self.stack = []

    def __len__(self):
        return len(self.stack)

    def __iter__(self):
        return iter(self.stack)

    def __call__(self, context):
        return TransactionContext(self, context)

    def clear(self):
        self.stack = []

    def peek(self):
        try:
            return self.stack[-1]
        except IndexError:
            return None

    def push(self, context):
        self.stack.append(context)
        return context

    def pop(self, context=None):
        if context is None:
            return self.stack.pop()

        while self.stack:
            if self.stack.pop() is context:
                return context