本文整理汇总了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):
示例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
示例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
示例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
示例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
示例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
示例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
示例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: