当前位置: 首页>>代码示例>>Python>>正文


Python Sequence.register方法代码示例

本文整理汇总了Python中collections.Sequence.register方法的典型用法代码示例。如果您正苦于以下问题:Python Sequence.register方法的具体用法?Python Sequence.register怎么用?Python Sequence.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在collections.Sequence的用法示例。


在下文中一共展示了Sequence.register方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: count

# 需要导入模块: from collections import Sequence [as 别名]
# 或者: from collections.Sequence import register [as 别名]
         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):
开发者ID:pwjones89,项目名称:coconut_learning,代码行数:33,代码来源:__coconut__.py

示例2: __len__

# 需要导入模块: from collections import Sequence [as 别名]
# 或者: from collections.Sequence import register [as 别名]
    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
开发者ID:lican09,项目名称:celery,代码行数:33,代码来源:datastructures.py

示例3: plist

# 需要导入模块: from collections import Sequence [as 别名]
# 或者: from collections.Sequence import register [as 别名]
    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
开发者ID:RichardFreeman,项目名称:pyrsistent,代码行数:33,代码来源:_plist.py

示例4: iterkeys

# 需要导入模块: from collections import Sequence [as 别名]
# 或者: from collections.Sequence import register [as 别名]
        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
开发者ID:arvindchari88,项目名称:newGitTest,代码行数:31,代码来源:result.py

示例5: __reversed__

# 需要导入模块: from collections import Sequence [as 别名]
# 或者: from collections.Sequence import register [as 别名]
    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
开发者ID:alekibango,项目名称:celery,代码行数:32,代码来源:collections.py

示例6: delete

# 需要导入模块: from collections import Sequence [as 别名]
# 或者: from collections.Sequence import register [as 别名]
    @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
开发者ID:pghfp,项目名称:pyrsistent,代码行数:32,代码来源:_pvector.py

示例7: _intervals

# 需要导入模块: from collections import Sequence [as 别名]
# 或者: from collections.Sequence import register [as 别名]
        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
开发者ID:tomviner,项目名称:intset,代码行数:33,代码来源:intset.py

示例8: isinstance

# 需要导入模块: from collections import Sequence [as 别名]
# 或者: from collections.Sequence import register [as 别名]
            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:
开发者ID:RichardFreeman,项目名称:pyrsistent,代码行数:33,代码来源:_pdeque.py


注:本文中的collections.Sequence.register方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。