コード例 #1
0
 def __init__(self, ipdb=None, mode=None, parent=None, uid=None):
     #
     if ipdb is not None:
         self.nl = ipdb.nl
         self.ipdb = ipdb
     else:
         self.nl = None
         self.ipdb = None
     #
     self._parent = None
     if parent is not None:
         self._mode = mode or parent._mode
         self._parent = parent
     elif ipdb is not None:
         self._mode = mode or ipdb.mode
     else:
         self._mode = mode or 'implicit'
     #
     self.nlmsg = None
     self.uid = uid or uuid32()
     self.last_error = None
     self._commit_hooks = []
     self._sids = []
     self._ts = threading.local()
     self._snapshots = {}
     self.global_tx = {}
     self._targets = {}
     self._local_targets = {}
     self._write_lock = threading.RLock()
     self._direct_state = State(self._write_lock)
     self._linked_sets = self._linked_sets or set()
     #
     for i in self._fields:
         TransactionalBase.__setitem__(self, i, None)
コード例 #2
0
ファイル: transactional.py プロジェクト: 0xD3ADB33F/pyroute2
 def __init__(self, ipdb=None, mode=None, parent=None, uid=None):
     #
     if ipdb is not None:
         self.nl = ipdb.nl
         self.ipdb = ipdb
     else:
         self.nl = None
         self.ipdb = None
     #
     self._parent = None
     if parent is not None:
         self._mode = mode or parent._mode
         self._parent = parent
     elif ipdb is not None:
         self._mode = mode or ipdb.mode
     else:
         self._mode = mode or 'implicit'
     #
     self.nlmsg = None
     self.uid = uid or uuid32()
     self.last_error = None
     self._commit_hooks = []
     self._sids = []
     self._ts = threading.local()
     self._snapshots = {}
     self.global_tx = {}
     self._targets = {}
     self._local_targets = {}
     self._write_lock = threading.RLock()
     self._direct_state = State(self._write_lock)
     self._linked_sets = self._linked_sets or set()
     #
     for i in self._fields:
         TransactionalBase.__setitem__(self, i, None)
コード例 #3
0
    def __setitem__(self, direct, key, value):
        if not direct:
            # automatically set target on the active transaction,
            # which must be started prior to that call
            transaction = self.current_tx
            transaction[key] = value
            if value is not None:
                transaction._targets[key] = threading.Event()
        else:
            # set the item
            TransactionalBase.__setitem__(self, key, value)

            # update on local targets
            with self._write_lock:
                if key in self._local_targets:
                    func = self._fields_cmp.get(key, lambda x, y: x == y)
                    if func(value, self._local_targets[key].value):
                        self._local_targets[key].set()

            # cascade update on nested targets
            for tn in tuple(self.global_tx.values()):
                if (key in tn._targets) and (key in tn):
                    if self._fields_cmp.\
                            get(key, lambda x, y: x == y)(value, tn[key]):
                        tn._targets[key].set()
コード例 #4
0
ファイル: transactional.py プロジェクト: 0xD3ADB33F/pyroute2
    def __setitem__(self, direct, key, value):
        if not direct:
            # automatically set target on the active transaction,
            # which must be started prior to that call
            transaction = self.current_tx
            transaction[key] = value
            if value is not None:
                transaction._targets[key] = threading.Event()
        else:
            # set the item
            TransactionalBase.__setitem__(self, key, value)

            # update on local targets
            with self._write_lock:
                if key in self._local_targets:
                    func = self._fields_cmp.get(key, lambda x, y: x == y)
                    if func(value, self._local_targets[key].value):
                        self._local_targets[key].set()

            # cascade update on nested targets
            for tn in tuple(self.global_tx.values()):
                if (key in tn._targets) and (key in tn):
                    if self._fields_cmp.\
                            get(key, lambda x, y: x == y)(value, tn[key]):
                        tn._targets[key].set()