本文整理汇总了Python中collections.UserString方法的典型用法代码示例。如果您正苦于以下问题:Python collections.UserString方法的具体用法?Python collections.UserString怎么用?Python collections.UserString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collections
的用法示例。
在下文中一共展示了collections.UserString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_String_for_subst
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def to_String_for_subst(s,
isinstance=isinstance, str=str, to_String=to_String,
BaseStringTypes=BaseStringTypes, SequenceTypes=SequenceTypes,
UserString=UserString):
# Note that the test cases are sorted by order of probability.
if isinstance(s, BaseStringTypes):
return s
elif isinstance(s, SequenceTypes):
return ' '.join([to_String_for_subst(e) for e in s])
elif isinstance(s, UserString):
# s.data can only be either a unicode or a regular
# string. Please see the UserString initializer.
return s.data
else:
return str(s)
示例2: substitute
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def substitute(self, args, lvars, within_list):
"""Substitute expansions in an argument or list of arguments.
This serves as a wrapper for splitting up a string into
separate tokens.
"""
if is_String(args) and not isinstance(args, CmdStringHolder):
args = str(args) # In case it's a UserString.
args = _separate_args.findall(args)
for a in args:
if a[0] in ' \t\n\r\f\v':
if '\n' in a:
self.next_line()
elif within_list:
self.append(a)
else:
self.next_word()
else:
self.expand(a, lvars, within_list)
else:
self.expand(args, lvars, within_list)
示例3: to_String_for_subst
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def to_String_for_subst(s,
isinstance=isinstance, str=str, to_String=to_String,
BaseStringTypes=BaseStringTypes, SequenceTypes=SequenceTypes,
UserString=UserString):
# Note that the test cases are sorted by order of probability.
if isinstance(s, BaseStringTypes):
return s
elif isinstance(s, SequenceTypes):
l = []
for e in s:
l.append(to_String_for_subst(e))
return ' '.join( s )
elif isinstance(s, UserString):
# s.data can only be either a unicode or a regular
# string. Please see the UserString initializer.
return s.data
else:
return str(s)
示例4: __init__
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def __init__(self, cmd, literal=None):
collections.UserString.__init__(self, cmd)
self.literal = literal
示例5: to_String
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def to_String(s,
isinstance=isinstance, str=str,
UserString=UserString, BaseStringTypes=BaseStringTypes):
if isinstance(s,BaseStringTypes):
# Early out when already a string!
return s
elif isinstance(s, UserString):
# s.data can only be either a unicode or a regular
# string. Please see the UserString initializer.
return s.data
else:
return str(s)
示例6: to_String
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def to_String(s,
isinstance=isinstance, str=str,
UserString=UserString, BaseStringTypes=BaseStringTypes):
if isinstance(s,BaseStringTypes):
# Early out when already a string!
return s
elif isinstance(s, UserString):
# s.data can only be either a unicode or a regular
# string. Please see the UserString initializer.
return s.data
else:
return str(s)
示例7: is_String
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def is_String(e):
return isinstance(e, (str, UserString))
示例8: test_collections_userstuff
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [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)
示例9: test_install_aliases
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [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))
示例10: test_str_protocol
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def test_str_protocol(self):
self._superset_test(UserString, str)
示例11: test_user_string
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def test_user_string(self):
d = collections.UserString('')
self.assertEqual(pprint.pformat(d, width=1), "''")
d = collections.UserString('the quick brown fox jumped over a lazy dog')
self.assertEqual(pprint.pformat(d, width=20),
"""\
('the quick brown '
'fox jumped over '
'a lazy dog')""")
self.assertEqual(pprint.pformat({1: d}, width=20),
"""\
{1: 'the quick '
'brown fox '
'jumped over a '
'lazy dog'}""")
示例12: setUp
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def setUp(self):
# need to keep references to them
self.items = [ustr(c) for c in ('a', 'b', 'c')]
self.items2 = [ustr(c) for c in ('x', 'y', 'z')]
self.ab_items = [ustr(c) for c in 'ab']
self.abcde_items = [ustr(c) for c in 'abcde']
self.def_items = [ustr(c) for c in 'def']
self.ab_weakset = WeakSet(self.ab_items)
self.abcde_weakset = WeakSet(self.abcde_items)
self.def_weakset = WeakSet(self.def_items)
self.letters = [ustr(c) for c in string.ascii_letters]
self.s = WeakSet(self.items)
self.d = dict.fromkeys(self.items)
self.obj = ustr('F')
self.fs = WeakSet([self.obj])
示例13: test_contains
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def test_contains(self):
for c in self.letters:
self.assertEqual(c in self.s, c in self.d)
# 1 is not weakref'able, but that TypeError is caught by __contains__
self.assertNotIn(1, self.s)
self.assertIn(self.obj, self.fs)
del self.obj
self.assertNotIn(ustr('F'), self.fs)
示例14: test_add
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def test_add(self):
x = ustr('Q')
self.s.add(x)
self.assertIn(x, self.s)
dup = self.s.copy()
self.s.add(x)
self.assertEqual(self.s, dup)
self.assertRaises(TypeError, self.s.add, [])
self.fs.add(Foo())
self.assertTrue(len(self.fs) == 1)
self.fs.add(self.obj)
self.assertTrue(len(self.fs) == 1)
示例15: test_discard
# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def test_discard(self):
a, q = ustr('a'), ustr('Q')
self.s.discard(a)
self.assertNotIn(a, self.s)
self.s.discard(q)
self.assertRaises(TypeError, self.s.discard, [])