예제 #1
0
 def __insertion(self, link_prev, key_value):
     self.__insertions_running[_get_ident()] = 1
     self.__setitem__(*key_value)
     key, value = self.__insertions_running.pop(_get_ident())
     if link_prev[2] != key:
         if key in self:
             del self[key]
         link_next = link_prev[1]
         self._OrderedDict__map[key] = link_prev[1] = link_next[0] = [link_prev, link_next, key]
     dict.__setitem__(self, key, value)
 def __repr__(self, _repr_running={}):
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return "..."
     _repr_running[call_key] = 1
     try:
         return "%s(%s, %r)" % (self.__class__.__name__, self.default_factory, dict(self.items()))
     finally:
         del _repr_running[call_key]
예제 #3
0
파일: lock.py 프로젝트: 18965050/gevent
        def acquire(self):
            me = _get_ident()
            if self._owner == me:
                self._count += 1
                return

            self._owner = me
            self._block.acquire()
            self._count = 1
예제 #4
0
 def __repr__(self, _repr_running={}):
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         if not self: return '%s()' % (self.__class__.__name__,)
         return '%s(%r)' % (self.__class__.__name__, self.items())
     finally:
         del _repr_running[call_key]
예제 #5
0
 def __repr__(self, _repr_running={}):
     'od.__repr__() <==> repr(od)'
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         return '{%s}' % (', '.join('%r: %r' % (k,v) for k,v in self.iteritems()))
     finally:
         del _repr_running[call_key]
예제 #6
0
파일: hash.py 프로젝트: hartym/rdc.etl
 def __repr__(self, _repr_running={}):
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return "..."
     _repr_running[call_key] = 1
     try:
         if not self:
             return "H{}" % ()
         return "H{%s}" % (", ".join(["%r: %r" % (k, v) for k, v in self.iteritems()]),)
     finally:
         del _repr_running[call_key]
예제 #7
0
 def __repr__(self, _repr_running={}):
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         if not self:
             return 'H{}' % ()
         return 'H{%s}' % (', '.join(['%r: %r' % (k, v, ) for k, v in self.iteritems()]), )
     finally:
         del _repr_running[call_key]
예제 #8
0
    def __enter__(self):
        id = _get_ident()
        lock = self.lock

        while True:
            v = _get(lock, 0)
            if not v:
                _set(lock, 0, id)
            elif v == id:
                break
            else:
                sleep(0.000001)
 def __repr__(self, _repr_running={}): #pylint: disable=W0102
     'od.__repr__() <==> repr(od)'
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         if not self:
             return '%s()' % (self.__class__.__name__,)
         return '%s(%r)' % (self.__class__.__name__, self.items())
     finally:
         del _repr_running[call_key]
예제 #10
0
 def __repr__(self, _repr_running={}):
     "od.__repr__() <==> repr(od)"
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return "..."
     _repr_running[call_key] = 1
     try:
         if not self:
             return "%s()" % (self.__class__.__name__,)
         return "%s(%r)" % (self.__class__.__name__, self.items())
     finally:
         del _repr_running[call_key]
예제 #11
0
 def __repr__(self, _repr_running={}):
     'od.__repr__() <==> repr(od)'
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         if not self:
             return '{}'
         return '{%s}' % ", ".join("%s: %s" % (k, v)
                                   for k, v in self.items())
     finally:
         del _repr_running[call_key]
예제 #12
0
 def __repr__(self, _repr_running={}):
     'od.__repr__() <==> repr(od)'
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         if not self:
             return '%s()' % (self.__class__.__name__,)
         items = list(self.items())
         return '%s(%r)' % (self.__class__.__name__, items)
     finally:
         del _repr_running[call_key]
예제 #13
0
파일: orddict.py 프로젝트: ohmu/poni
 def __repr__(self, _repr_running=None):
     'od.__repr__() <==> repr(od)'
     _repr_running = {} if _repr_running is None else _repr_running
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         if not self:
             return '%s()' % (self.__class__.__name__,)
         return '%s(%r)' % (self.__class__.__name__, self.items())
     finally:
         del _repr_running[call_key]
예제 #14
0
 def __repr__(self, _repr_running=None):
     'od.__repr__() <==> repr(od)'
     if not _repr_running: _repr_running = {}
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         if not self:
             return '%s()' % (self.__class__.__name__,)
         return '%s(%r)' % (self.__class__.__name__, self.items())
     finally:
         del _repr_running[call_key]
 def __repr__(self, _repr_running={}):
     '''x.__repr__() <==> repr(x)
     '''
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         if not self:
             return '%s()' % (self.__class__.__name__,)
         return '%s(%r)' % (self.__class__.__name__, self.__values.values())
     finally:
         del _repr_running[call_key]
예제 #16
0
 def __repr__(self, _repr_running=None):
     'od.__repr__() <==> repr(od)'
     if _repr_running is None:
         _repr_running = {}
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         if not self:
             return '{0!s}()'.format(self.__class__.__name__)
         return '{0!s}({1!r})'.format(self.__class__.__name__, self.items())
     finally:
         del _repr_running[call_key]
예제 #17
0
    def __repr__(self, _repr_running={}):
        "od.__repr__() <==> repr(od)"
        call_key = id(self), _get_ident()
        if call_key in _repr_running:
            return "..."

        _repr_running[call_key] = 1
        try:
            if not self:
                return "%s()" % (self.__class__.__name__, )

            return "%s(%r)" % (self.__class__.__name__, self.items())

        finally:
            del _repr_running[call_key]
예제 #18
0
 def __repr__(self, _repr_running={}):
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         if not self:
             return 'H{}' % ()
         return 'H{%s}' % (', '.join(
             ['%r: %r' % (
                 k,
                 v,
             ) for k, v in self.iteritems()]), )
     finally:
         del _repr_running[call_key]
예제 #19
0
    def __repr__(self, _repr_running={}):
        """ Compute the "official" string representation of the dictionary.

        Used by repr(). In this case also used by str() and print since
        __str__() is not implemented.
        """
        call_key = id(self), _get_ident()
        if call_key in _repr_running:
            return '...'
        _repr_running[call_key] = 1
        try:
            if not self:
                return '%s()' % (self.__class__.__name__, )
            return '%s(%r)' % (self.__class__.__name__, self.items())
        finally:
            del _repr_running[call_key]
예제 #20
0
 def __repr__(
     self,
     _repr_running={}
 ):  # [Adapted from]  https://github.com/python/cpython/blob/2.7/Lib/collections.py
     'oedict.__repr__() <==> repr(oedict)'
     # return '@oedict@'
     call_key = id(self), _get_ident()
     if call_key in _repr_running:
         return '...'
     _repr_running[call_key] = 1
     try:
         if not self._odict:
             return '%s()' % (self.__class__.__name__, )
         return '%s(%r)' % (self.__class__.__name__, self.items())
     finally:
         del _repr_running[call_key]
예제 #21
0
    def __repr__(self, _repr_running={}):
        'od.__repr__() <==> repr(od)'
        call_key = id(self), _get_ident()
        if call_key in _repr_running:
            return '...'
        _repr_running[call_key] = 1
        try:
            if not self:
                return u'{}'

            contents = []
            for k,v in self.items():
                contents.append(u'%s:%s'%(k,v))
            return u"{%s}"%", ".join(contents)
            
        finally:
            del _repr_running[call_key]
예제 #22
0
파일: atoms.py 프로젝트: 0x68/corduroy
    def __repr__(self, _repr_running={}):
        'od.__repr__() <==> repr(od)'
        call_key = id(self), _get_ident()
        if call_key in _repr_running:
            return '...'
        _repr_running[call_key] = 1
        try:
            if not self:
                return u'{}'

            contents = []
            for k,v in self.items():
                contents.append(u'%s:%s'%(k,v))
            return u"{%s}"%", ".join(contents)
            
        finally:
            del _repr_running[call_key]
예제 #23
0
        def wrapper(self):
            me = _get_ident()
            try:
                count = self._locking[me]
            except KeyError:
                count = self._locking[me] = 1
            else:
                count = self._locking[me] = count + 1
            if count:
                return

            try:
                return f(self)
            finally:
                count = count - 1
                if not count:
                    del self._locking[me]
                else:
                    self._locking[me] = count
예제 #24
0
파일: dicts.py 프로젝트: HoverHell/pyaux
    def __repr__(self, _repr_running={}, fn=__drepr__):
        """ Wrapped around __drepr__ that makes it possible to
        represent infinitely-recursive dictionaries of this type. """
        # NOTE: version variety; might be a _get_ident or something else.
        try:
            from thread import get_ident as _get_ident
        except ImportError:
            from threading import get_ident as _get_ident

        call_key = (id(self), _get_ident())
        if call_key in _repr_running:
            # TODO?: make a YAML-like naming & referencing?
            # (too complicated for a repr() though)
            return '...'
        _repr_running[call_key] = 1
        try:
            return fn(self)
        finally:
            del _repr_running[call_key]
예제 #25
0
 def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
     if _get_ident() in self.__insertions_running:
         self.__insertions_running[_get_ident()] = key, value
     else:
         super(ListDict, self).__setitem__(key, value, dict_setitem)
예제 #26
0
 def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
     if _get_ident() in self.__insertions_running:
         self.__insertions_running[_get_ident()] = key, value
     else:
         super(ListDict, self).__setitem__(key, value, dict_setitem)