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


Python collections.UserString方法代码示例

本文整理汇总了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) 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:18,代码来源:Util.py

示例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) 
开发者ID:bq,项目名称:web2board,代码行数:24,代码来源:Subst.py

示例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) 
开发者ID:bq,项目名称:web2board,代码行数:21,代码来源:Util.py

示例4: __init__

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def __init__(self, cmd, literal=None):
        collections.UserString.__init__(self, cmd)
        self.literal = literal 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:5,代码来源:Subst.py

示例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) 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:14,代码来源:Util.py

示例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) 
开发者ID:bq,项目名称:web2board,代码行数:14,代码来源:Util.py

示例7: is_String

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def is_String(e):
        return isinstance(e, (str, UserString)) 
开发者ID:refack,项目名称:GYP3,代码行数:4,代码来源:TestCmd.py

示例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) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:11,代码来源:test_standard_library.py

示例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)) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:36,代码来源:test_standard_library.py

示例10: test_str_protocol

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserString [as 别名]
def test_str_protocol(self):
        self._superset_test(UserString, str) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:test_collections.py

示例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'}""") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_pprint.py

示例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]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_weakset.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_weakset.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_weakset.py

示例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, []) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_weakset.py


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