Ejemplo n.º 1
0
    def __init__(self, lstFn):
        """Construct a new CachedList.  The lstFn is a function that takes
           no parameters and returns a list.  It will be called lazily - the
           list is not constructed until the first access, which could be
           quite a while after this method is called."""
        Sequence.__init__(self)

        self._invalid = True
        self._lst = []
        self._lstFn = lstFn
Ejemplo n.º 2
0
    def __len__(self):
        return self._len()

    def __contains__(self, item):
        return item in self.data

    def __reversed__(self):
        return reversed(self.data)

    def __getitem__(self, index):
        return self.data[index]

    @property
    def _evictcount(self):
        return len(self)
Sequence.register(Messagebuffer)


@python_2_unicode_compatible
class BufferMapping(OrderedDict, Evictable):

    Buffer = Messagebuffer
    Empty = Empty

    maxsize = None
    total = 0
    bufmaxsize = None

    def __init__(self, maxsize, iterable=None, bufmaxsize=1000):
        super(BufferMapping, self).__init__()
        self.maxsize = maxsize
Ejemplo n.º 3
0
        """Return the list of keys as strings represented by this RowProxy."""

        return self._parent.keys

    def iterkeys(self):
        return iter(self._parent.keys)

    def itervalues(self):
        return iter(self)


try:
    # Register RowProxy with Sequence,
    # so sequence protocol is implemented
    from collections import Sequence
    Sequence.register(RowProxy)
except ImportError:
    pass


class ResultMetaData(object):
    """Handle cursor.description, applying additional info from an execution
    context."""
    def __init__(self, parent, metadata):
        self._processors = processors = []

        # We do not strictly need to store the processor in the key mapping,
        # though it is faster in the Python version (probably because of the
        # saved attribute lookup self._processors)
        self._keymap = keymap = {}
        self.keys = []
Ejemplo n.º 4
0
    def __len__(self):
        return self._len()

    def __contains__(self, item):
        return item in self.data

    def __reversed__(self):
        return reversed(self.data)

    def __getitem__(self, index):
        return self.data[index]

    @property
    def _evictcount(self):
        return len(self)
Sequence.register(Messagebuffer)


@python_2_unicode_compatible
class BufferMap(OrderedDict, Evictable):

    Buffer = Messagebuffer
    Empty = Empty

    maxsize = None
    total = 0
    bufmaxsize = None

    def __init__(self, maxsize, iterable=None, bufmaxsize=1000):
        super(BufferMap, self).__init__()
        self.maxsize = maxsize
Ejemplo n.º 5
0
            if index.stop is not None:
                result = result.pop(self._length - (index.stop % self._length))

            return result

        if not isinstance(index, Integral):
            raise TypeError("'%s' object cannot be interpreted as an index" % type(index).__name__)

        if index >= 0:
            return self.popleft(index).left

        return  self.pop(index).right

    index = Sequence.index

Sequence.register(PDeque)
Hashable.register(PDeque)


def pdeque(iterable=(), maxlen=None):
    """
    Return deque containing the elements of iterable. If maxlen is specified then
    len(iterable) - maxlen elements are discarded from the left to if len(iterable) > maxlen.

    >>> pdeque([1, 2, 3])
    pdeque([1, 2, 3])
    >>> pdeque([1, 2, 3, 4], maxlen=2)
    pdeque([3, 4], maxlen=2)
    """
    t = tuple(iterable)
    if maxlen is not None:
Ejemplo n.º 6
0
 def __init__(self, traces):
     Sequence.__init__(self)
     self._traces = traces
Ejemplo n.º 7
0
    def __reversed__(self):
        # type: () -> Iterable
        return reversed(self.data)

    def __getitem__(self, index):
        # type: (Any) -> Any
        return self.data[index]

    @property
    def _evictcount(self):
        # type: () -> int
        return len(self)


Sequence.register(Messagebuffer)  # noqa: E305


@python_2_unicode_compatible
class BufferMap(OrderedDict, Evictable):
    """Map of buffers."""

    Buffer = Messagebuffer
    Empty = Empty

    maxsize = None
    total = 0
    bufmaxsize = None

    def __init__(self, maxsize, iterable=None, bufmaxsize=1000):
        # type: (int, Iterable, int) -> None
Ejemplo n.º 8
0
 def __init__(self, frames):
     Sequence.__init__(self)
     # frames is a tuple of frame tuples: see Frame constructor for the
     # format of a frame tuple
     self._frames = frames
Ejemplo n.º 9
0
    @abstractmethod
    def delete(self, index, stop=None):
        """
        Delete a portion of the vector by index or range.

        >>> v1 = v(1, 2, 3, 4, 5)
        >>> v1.delete(1)
        pvector([1, 3, 4, 5])
        >>> v1.delete(1, 3)
        pvector([1, 4, 5])
        """


_EMPTY_PVECTOR = PythonPVector(0, SHIFT, [], [])
PVector.register(PythonPVector)
Sequence.register(PVector)
Hashable.register(PVector)


def python_pvector(iterable=()):
    """
    Create a new persistent vector containing the elements in iterable.

    >>> v1 = pvector([1, 2, 3])
    >>> v1
    pvector([1, 2, 3])
    """
    return _EMPTY_PVECTOR.extend(iterable)


try:
Ejemplo n.º 10
0
    @abstractmethod
    def delete(self, index, stop=None):
        """
        Delete a portion of the vector by index or range.

        >>> v1 = v(1, 2, 3, 4, 5)
        >>> v1.delete(1)
        pvector([1, 3, 4, 5])
        >>> v1.delete(1, 3)
        pvector([1, 4, 5])
        """

_EMPTY_PVECTOR = PythonPVector(0, SHIFT, [], [])
PVector.register(PythonPVector)
Sequence.register(PVector)
Hashable.register(PVector)

def python_pvector(iterable=()):
    """
    Create a new persistent vector containing the elements in iterable.

    >>> v1 = pvector([1, 2, 3])
    >>> v1
    pvector([1, 2, 3])
    """
    return _EMPTY_PVECTOR.extend(iterable)

try:
    # Use the C extension as underlying trie implementation if it is available
    import os
Ejemplo n.º 11
0
    """
    __slots__ = ('first', 'rest')

    def __new__(cls, first, rest):
        instance = super(PList, cls).__new__(cls)
        instance.first = first
        instance.rest = rest
        return instance

    def __bool__(self):
        return True

    __nonzero__ = __bool__


Sequence.register(PList)
Hashable.register(PList)


class _EmptyPList(_PListBase):
    __slots__ = ()

    def __bool__(self):
        return False

    __nonzero__ = __bool__

    @property
    def first(self):
        raise AttributeError("Empty PList has no first")
Ejemplo n.º 12
0
            raise TypeError("'%s' object cannot be interpreted as an index" %
                            type(index).__name__)

        if index >= 0:
            return self.popleft(index).left

        shifted = len(self) + index
        if shifted < 0:
            raise IndexError(
                "pdeque index {0} out of range {1}".format(index, len(self)), )
        return self.popleft(shifted).left

    index = Sequence.index


Sequence.register(PDeque)
Hashable.register(PDeque)


def pdeque(iterable=(), maxlen=None):
    """
    Return deque containing the elements of iterable. If maxlen is specified then
    len(iterable) - maxlen elements are discarded from the left to if len(iterable) > maxlen.

    >>> pdeque([1, 2, 3])
    pdeque([1, 2, 3])
    >>> pdeque([1, 2, 3, 4], maxlen=2)
    pdeque([3, 4], maxlen=2)
    """
    t = tuple(iterable)
    if maxlen is not None:
Ejemplo n.º 13
0
 def __init__(self, traces):
     Sequence.__init__(self)
     self._traces = traces
Ejemplo n.º 14
0
 def __init__(self, frames):
     Sequence.__init__(self)
     self._frames = frames
Ejemplo n.º 15
0
        represent non-overlapping intervals such that for any start <= x < end
        x in self
        """
        return _intervals(self.wrapped)

    def reversed_intervals(self):
        """Iterator over the reverse of intervals()"""
        return _reversed_intervals(self.wrapped)

    def __reversed__(self):
        for start, end in self.reversed_intervals():
            for i in range(end - 1, start - 1, -1):
                yield i


Sequence.register(IntSet)
Set.register(IntSet)


def _new_maybe_empty_interval(start, end):
    if end <= start:
        return ()
    return _new_interval(start, end)


_START = 0
_END = 1
_SIZE = 2
_PREFIX = 3
_MASK = 4
_LEFT = 5
Ejemplo n.º 16
0
        def __reduce__(self):
            return self.__reduce_ex__(_coconut.pickle.DEFAULT_PROTOCOL)

        def __hash__(self):
            return _coconut.hash(self._args)

        def __copy__(self):
            return self.__class__(*self._args)

        def __eq__(self, other):
            return _coconut.isinstance(
                other, self.__class__) and self._args == other._args

    from collections import Sequence as _coconut_Sequence
    _coconut_Sequence.register(range)

    class int(_coconut_int):
        __slots__ = ()
        if hasattr(_coconut_int, "__doc__"):
            __doc__ = _coconut_int.__doc__

        class __metaclass__(type):
            def __instancecheck__(cls, inst):
                return _coconut.isinstance(inst, (_coconut_int, _coconut_long))

    from functools import wraps as _coconut_wraps

    @_coconut_wraps(_coconut_print)
    def print(*args, **kwargs):
        if _coconut.hasattr(
Ejemplo n.º 17
0
    plist([3, 1])
    """
    __slots__ = ('first', 'rest')

    def __new__(cls, first, rest):
        instance = super(PList, cls).__new__(cls)
        instance.first = first
        instance.rest = rest
        return instance

    def __bool__(self):
        return True
    __nonzero__ = __bool__


Sequence.register(PList)
Hashable.register(PList)


class _EmptyPList(_PListBase):
    __slots__ = ()

    def __bool__(self):
        return False
    __nonzero__ = __bool__

    @property
    def first(self):
        raise AttributeError("Empty PList has no first")

    @property
Ejemplo n.º 18
0
 def __init__(self, attribs=None):
     Sequence.__init__(self)
     self.descriptors = list(attribs or [])
Ejemplo n.º 19
0
 def __init__(self, traces):
     Sequence.__init__(self)
     # traces is a tuple of trace tuples: see Trace constructor
     self._traces = traces
Ejemplo n.º 20
0
        represent non-overlapping intervals such that for any start <= x < end
        x in self
        """
        return _intervals(self.wrapped)

    def reversed_intervals(self):
        """Iterator over the reverse of intervals()"""
        return _reversed_intervals(self.wrapped)

    def __reversed__(self):
        for start, end in self.reversed_intervals():
            for i in range(end - 1, start - 1, -1):
                yield i


Sequence.register(IntSet)
Set.register(IntSet)


def _new_maybe_empty_interval(start, end):
    if end <= start:
        return ()
    return _new_interval(start, end)


_START = 0
_END = 1
_SIZE = 2
_PREFIX = 3
_MASK = 4
_LEFT = 5
Ejemplo n.º 21
0
 def __init__(self, frames):
     Sequence.__init__(self)
     self._frames = frames
Ejemplo n.º 22
0
    def __reversed__(self):
        # type: () -> Iterable
        return reversed(self.data)

    def __getitem__(self, index):
        # type: (Any) -> Any
        return self.data[index]

    @property
    def _evictcount(self):
        # type: () -> int
        return len(self)


Sequence.register(Messagebuffer)  # noqa: E305


@python_2_unicode_compatible
class BufferMap(OrderedDict, Evictable):
    """Map of buffers."""

    Buffer = Messagebuffer
    Empty = Empty

    maxsize = None
    total = 0
    bufmaxsize = None

    def __init__(self, maxsize, iterable=None, bufmaxsize=1000):
        # type: (int, Iterable, int) -> None
Ejemplo n.º 23
0
         else:
             return self._xrange[index]
     def count(self, elem):
         """Count the number of times elem appears in the range."""
         return int(elem in self._xrange)
     def index(self, elem):
         """Find the index of elem in the range."""
         if elem not in self._xrange: raise _coconut.ValueError(_coconut.repr(elem) + " is not in range")
         start, _, step = self._xrange.__reduce_ex__(2)[1]
         return (elem - start) // step
     def __repr__(self):
         return _coconut.repr(self._xrange)[1:]
     def __reduce_ex__(self, protocol):
         return (self.__class__, self._xrange.__reduce_ex__(protocol)[1])
 from collections import Sequence as _coconut_Sequence
 _coconut_Sequence.register(range)
 class int(_coconut_int):
     __slots__ = ()
     __doc__ = _coconut_int.__doc__
     class __metaclass__(type):
         def __instancecheck__(cls, inst):
             return _coconut.isinstance(inst, (_coconut_int, _coconut_long))
 class bytes(_coconut_str):
     __slots__ = ()
     __doc__ = _coconut_str.__doc__
     class __metaclass__(type):
         def __instancecheck__(cls, inst):
             return _coconut.isinstance(inst, _coconut_str)
     def __new__(cls, *args, **kwargs):
         return _coconut_str.__new__(cls, _coconut.bytearray(*args, **kwargs))
 def print(*args, **kwargs):
Ejemplo n.º 24
0
        return self._parent.keys

    def iterkeys(self):
        return iter(self._parent.keys)

    def itervalues(self):
        return iter(self)


try:
    # Register RowProxy with Sequence,
    # so sequence protocol is implemented
    from collections import Sequence

    Sequence.register(RowProxy)
except ImportError:
    pass


class ResultMetaData(object):
    """Handle cursor.description, applying additional info from an execution
    context."""

    def __init__(self, parent, metadata):
        context = parent.context
        dialect = context.dialect
        typemap = dialect.dbapi_type_map
        translate_colname = context._translate_colname
        self.case_sensitive = case_sensitive = dialect.case_sensitive