当前位置: 首页>>代码示例>>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;未经允许,请勿转载。