當前位置: 首頁>>代碼示例>>Python>>正文


Python UserString.UserString方法代碼示例

本文整理匯總了Python中UserString.UserString方法的典型用法代碼示例。如果您正苦於以下問題:Python UserString.UserString方法的具體用法?Python UserString.UserString怎麽用?Python UserString.UserString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UserString的用法示例。


在下文中一共展示了UserString.UserString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: to_String_for_subst

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString 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: to_String

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString 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

示例3: checkequal

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def checkequal(self, result, object, methodname, *args):
        result = self.fixtype(result)
        object = self.fixtype(object)
        # we don't fix the arguments, because UserString can't cope with it
        realresult = getattr(object, methodname)(*args)
        self.assertEqual(
            result,
            realresult
        ) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_userstring.py

示例4: checkraises

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def checkraises(self, exc, obj, methodname, *args):
        obj = self.fixtype(obj)
        # we don't fix the arguments, because UserString can't cope with it
        with self.assertRaises(exc) as cm:
            getattr(obj, methodname)(*args)
        self.assertNotEqual(cm.exception.args[0], '') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_userstring.py

示例5: checkcall

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def checkcall(self, object, methodname, *args):
        object = self.fixtype(object)
        # we don't fix the arguments, because UserString can't cope with it
        getattr(object, methodname)(*args) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_userstring.py

示例6: test_setslice

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def test_setslice(self):
        s = self.type2test("foo")
        s[:] = "bar"
        self.assertEqual(s, "bar")
        s[1:2] = "foo"
        self.assertEqual(s, "bfoor")
        s[1:-1] = UserString("a")
        self.assertEqual(s, "bar")
        s[0:10] = 42
        self.assertEqual(s, "42") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_userstring.py

示例7: test_immutable

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def test_immutable(self):
        s = self.type2test("foobar")
        s2 = s.immutable()
        self.assertEqual(s, s2)
        self.assertIsInstance(s2, UserString) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_userstring.py

示例8: checkraises

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def checkraises(self, exc, object, methodname, *args):
        object = self.fixtype(object)
        # we don't fix the arguments, because UserString can't cope with it
        self.assertRaises(
            exc,
            getattr(object, methodname),
            *args
        ) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:10,代碼來源:test_userstring.py

示例9: __init__

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def __init__(self, cmd, literal=None):
        UserString.UserString.__init__(self, cmd)
        self.literal = literal 
開發者ID:coin3d,項目名稱:pivy,代碼行數:5,代碼來源:Subst.py

示例10: is_String

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def is_String(obj):
            t = type(obj)
            return t is StringType \
                or t is UnicodeType \
                or (t is InstanceType and isinstance(obj, UserString)) 
開發者ID:coin3d,項目名稱:pivy,代碼行數:7,代碼來源:Util.py

示例11: to_String

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def to_String(s):
            if isinstance(s, UserString):
                t = type(s.data)
            else:
                t = type(s)
            if t is UnicodeType:
                return unicode(s)
            else:
                return str(s) 
開發者ID:coin3d,項目名稱:pivy,代碼行數:11,代碼來源:Util.py

示例12: isstringtype

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def isstringtype( obj ):
    """Is the object of a Python string type?"""
    if isinstance(obj, basestring):
        return True
    # Must also check for some other pseudo-string types
    import types, UserString
    return isinstance(obj, types.StringTypes) \
           or isinstance(obj, UserString.UserString) \
           or isinstance(obj, UserString.MutableString)


# ----------------------------------------------------------------------
# Numeric helpers 
開發者ID:teamtachyon,項目名稱:Quillpad-Server,代碼行數:15,代碼來源:demjson.py

示例13: is_String

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def is_String(e):
    return isinstance(e, basestring) or isinstance(e, UserString) 
開發者ID:turbulenz,項目名稱:gyp,代碼行數:4,代碼來源:TestCmd.py

示例14: test_weak_destroy_while_iterating

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def test_weak_destroy_while_iterating(self):
        # Issue #7105: iterators shouldn't crash when a key is implicitly removed
        # Create new items to be sure no-one else holds a reference
        items = [ustr(c) for c in ('a', 'b', 'c')]
        s = WeakSet(items)
        it = iter(s)
        next(it)             # Trigger internal iteration
        # Destroy an item
        del items[-1]
        gc.collect()    # just in case
        # We have removed either the first consumed items, or another one
        self.assertIn(len(list(it)), [len(items), len(items) - 1])
        del it
        # The removal has been committed
        self.assertEqual(len(s), len(items)) 
開發者ID:gcblue,項目名稱:gcblue,代碼行數:17,代碼來源:test_weakset.py

示例15: test_weak_destroy_and_mutate_while_iterating

# 需要導入模塊: import UserString [as 別名]
# 或者: from UserString import UserString [as 別名]
def test_weak_destroy_and_mutate_while_iterating(self):
        # Issue #7105: iterators shouldn't crash when a key is implicitly removed
        items = [ustr(c) for c in string.ascii_letters]
        s = WeakSet(items)
        @contextlib.contextmanager
        def testcontext():
            try:
                it = iter(s)
                # Start iterator
                yielded = ustr(str(next(it)))
                # Schedule an item for removal and recreate it
                u = ustr(str(items.pop()))
                if yielded == u:
                    # The iterator still has a reference to the removed item,
                    # advance it (issue #20006).
                    next(it)
                gc.collect()      # just in case
                yield u
            finally:
                it = None           # should commit all removals

        with testcontext() as u:
            self.assertFalse(u in s)
        with testcontext() as u:
            self.assertRaises(KeyError, s.remove, u)
        self.assertFalse(u in s)
        with testcontext() as u:
            s.add(u)
        self.assertTrue(u in s)
        t = s.copy()
        with testcontext() as u:
            s.update(t)
        self.assertEqual(len(s), len(t))
        with testcontext() as u:
            s.clear()
        self.assertEqual(len(s), 0) 
開發者ID:gcblue,項目名稱:gcblue,代碼行數:38,代碼來源:test_weakset.py


注:本文中的UserString.UserString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。