當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。