本文整理汇总了Python中collections.UserList方法的典型用法代码示例。如果您正苦于以下问题:Python collections.UserList方法的具体用法?Python collections.UserList怎么用?Python collections.UserList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collections
的用法示例。
在下文中一共展示了collections.UserList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_user_list
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def test_user_list(self):
d = collections.UserList()
self.assertEqual(pprint.pformat(d, width=1), "[]")
words = 'the quick brown fox jumped over a lazy dog'.split()
d = collections.UserList(zip(words, itertools.count()))
self.assertEqual(pprint.pformat(d),
"""\
[('the', 0),
('quick', 1),
('brown', 2),
('fox', 3),
('jumped', 4),
('over', 5),
('a', 6),
('lazy', 7),
('dog', 8)]""")
示例2: test_compat_pickle
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def test_compat_pickle(self):
tests = [
(range(1, 7), '__builtin__', 'xrange'),
(map(int, '123'), 'itertools', 'imap'),
(functools.reduce, '__builtin__', 'reduce'),
(dbm.whichdb, 'whichdb', 'whichdb'),
(Exception(), 'exceptions', 'Exception'),
(collections.UserDict(), 'UserDict', 'IterableUserDict'),
(collections.UserList(), 'UserList', 'UserList'),
(collections.defaultdict(), 'collections', 'defaultdict'),
]
for val, mod, name in tests:
for proto in range(3):
with self.subTest(type=type(val), proto=proto):
pickled = self.dumps(val, proto)
self.assertIn(('c%s\n%s' % (mod, name)).encode(), pickled)
self.assertIs(type(self.loads(pickled)), type(val))
示例3: test_plain
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def test_plain(self):
f = self.makeCallable('a, b=1')
self.assertEqualCallArgs(f, '2')
self.assertEqualCallArgs(f, '2, 3')
self.assertEqualCallArgs(f, 'a=2')
self.assertEqualCallArgs(f, 'b=3, a=2')
self.assertEqualCallArgs(f, '2, b=3')
# expand *iterable / **mapping
self.assertEqualCallArgs(f, '*(2,)')
self.assertEqualCallArgs(f, '*[2]')
self.assertEqualCallArgs(f, '*(2, 3)')
self.assertEqualCallArgs(f, '*[2, 3]')
self.assertEqualCallArgs(f, '**{"a":2}')
self.assertEqualCallArgs(f, 'b=3, **{"a":2}')
self.assertEqualCallArgs(f, '2, **{"b":3}')
self.assertEqualCallArgs(f, '**{"b":3, "a":2}')
# expand UserList / UserDict
self.assertEqualCallArgs(f, '*collections.UserList([2])')
self.assertEqualCallArgs(f, '*collections.UserList([2, 3])')
self.assertEqualCallArgs(f, '**collections.UserDict(a=2)')
self.assertEqualCallArgs(f, '2, **collections.UserDict(b=3)')
self.assertEqualCallArgs(f, 'b=2, **collections.UserDict(a=3)')
示例4: test_multiple_features
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def test_multiple_features(self):
f = self.makeCallable('a, b=2, *f, **g')
self.assertEqualCallArgs(f, '2, 3, 7')
self.assertEqualCallArgs(f, '2, 3, x=8')
self.assertEqualCallArgs(f, '2, 3, x=8, *[(4,[5,6]), 7]')
self.assertEqualCallArgs(f, '2, x=8, *[3, (4,[5,6]), 7], y=9')
self.assertEqualCallArgs(f, 'x=8, *[2, 3, (4,[5,6])], y=9')
self.assertEqualCallArgs(f, 'x=8, *collections.UserList('
'[2, 3, (4,[5,6])]), **{"y":9, "z":10}')
self.assertEqualCallArgs(f, '2, x=8, *collections.UserList([3, '
'(4,[5,6])]), **collections.UserDict('
'y=9, z=10)')
f = self.makeCallable('a, b=2, *f, x, y=99, **g')
self.assertEqualCallArgs(f, '2, 3, x=8')
self.assertEqualCallArgs(f, '2, 3, x=8, *[(4,[5,6]), 7]')
self.assertEqualCallArgs(f, '2, x=8, *[3, (4,[5,6]), 7], y=9, z=10')
self.assertEqualCallArgs(f, 'x=8, *[2, 3, (4,[5,6])], y=9, z=10')
self.assertEqualCallArgs(f, 'x=8, *collections.UserList('
'[2, 3, (4,[5,6])]), q=0, **{"y":9, "z":10}')
self.assertEqualCallArgs(f, '2, x=8, *collections.UserList([3, '
'(4,[5,6])]), q=0, **collections.UserDict('
'y=9, z=10)')
示例5: _unwrap
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def _unwrap(obj):
if isinstance(obj, UserList) or isinstance(obj, UserDict):
return obj.data
return obj
示例6: __reduce_ex__
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def __reduce_ex__(self, *args, **kwargs):
# The `list` reduce function returns an iterator as the fourth element
# that is normally used for repopulating. Since we only inherit from
# `list` for `isinstance` backward compatibility (Refs #17413) we
# nullify this iterator as it would otherwise result in duplicate
# entries. (Refs #23594)
info = super(UserList, self).__reduce_ex__(*args, **kwargs)
return info[:3] + (None, None)
# Utilities for time zone support in DateTimeField et al.
示例7: __init__
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def __init__(self, initlist=[], allowedElems=[]):
collections.UserList.__init__(self, [_f for _f in initlist if _f])
self.allowedElems = sorted(allowedElems)
示例8: next_line
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def next_line(self):
"""Arrange for the next word to start a new line. This
is like starting a new word, except that we have to append
another line to the result."""
collections.UserList.append(self, [])
self.next_word()
示例9: is_List
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def is_List(e):
return isinstance(e, (list, UserList))
示例10: test_collections_userstuff
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def test_collections_userstuff(self):
"""
UserDict, UserList, and UserString have been moved to the
collections module.
"""
from collections import UserDict
from collections import UserList
from collections import UserString
self.assertTrue(True)
示例11: test_install_aliases
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def test_install_aliases(self):
"""
Does the install_aliases() interface monkey-patch urllib etc. successfully?
"""
from future.standard_library import remove_hooks, install_aliases
remove_hooks()
install_aliases()
from collections import Counter, OrderedDict # backported to Py2.6
from collections import UserDict, UserList, UserString
# Requires Python dbm support:
# import dbm
# import dbm.dumb
# import dbm.gnu
# import dbm.ndbm
from itertools import filterfalse, zip_longest
from subprocess import check_output # backported to Py2.6
from subprocess import getoutput, getstatusoutput
from sys import intern
# test_support may not be available (e.g. on Anaconda Py2.6):
# import test.support
import urllib.error
import urllib.parse
import urllib.request
import urllib.response
import urllib.robotparser
self.assertTrue('urlopen' in dir(urllib.request))
示例12: test_UserList
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def test_UserList(self):
before = """
from UserList import UserList
a = UserList([1, 3, 5])
assert len(a) == 3
"""
after = """
from collections import UserList
a = UserList([1, 3, 5])
assert len(a) == 3
"""
self.convert_check(before, after, stages=(1, 2), ignore_imports=True)
示例13: __init__
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def __init__(self, func=None, args=None, keys=None, detach=False, **kwargs):
super().__init__(**kwargs)
if func is not None and not callable(func):
raise TypeError('func "{}" is not a callable function or class'.format(repr(func)))
if args is not None and not isinstance(args, (collections.Sequence, collections.UserList)):
raise TypeError('args "{}" is not an iterable tuple or list'.format(repr(args)))
if keys is not None and not isinstance(keys, (collections.Sequence, collections.UserList)):
raise TypeError('keys "{}" is not an iterable tuple or list'.format(repr(keys)))
self.__dict__['_func_'] = func
self.__dict__['_args_'] = args
self.__dict__['_detach_'] = detach
self.__dict__['_keys_'] = keys
示例14: __call__
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def __call__(self, *args, **kwargs):
if self._func_ is None:
return self
# override args
if args:
args = list(args)
elif self._args_:
args = list(self._args_)
# override kwargs
for k, v in self.items():
if self._keys_ is None or k in self._keys_:
kwargs.setdefault(k, v)
# recursively call non-detached funcs
queue = collections.deque([args, kwargs])
while queue:
x = queue.popleft()
if isinstance(x, (collections.Sequence, collections.UserList)) and not isinstance(x, six.string_types):
items = enumerate(x)
elif isinstance(x, (collections.Mapping, collections.UserDict)):
items = x.items()
else:
items = []
for k, v in items:
if isinstance(v, tuple):
v = x[k] = list(v)
elif isinstance(v, Config):
if v._detach_:
continue
v = x[k] = v()
queue.append(v)
return self._func_(*args, **kwargs)
示例15: test_writelines_userlist
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserList [as 别名]
def test_writelines_userlist(self):
l = UserList([b'ab', b'cd', b'ef'])
writer = self.MockRawIO()
bufio = self.tp(writer, 8)
bufio.writelines(l)
bufio.flush()
self.assertEqual(b''.join(writer._write_stack), b'abcdef')