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


Python util.FancyStrMixin方法代码示例

本文整理汇总了Python中twisted.python.util.FancyStrMixin方法的典型用法代码示例。如果您正苦于以下问题:Python util.FancyStrMixin方法的具体用法?Python util.FancyStrMixin怎么用?Python util.FancyStrMixin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.python.util的用法示例。


在下文中一共展示了util.FancyStrMixin方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: trivialInput

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import FancyStrMixin [as 别名]
def trivialInput(symbol):
    """
    Create a new L{IRichInput} implementation for the given input symbol.

    This creates a new type object and is intended to be used at module scope
    to define rich input types.  Generally, only one use per symbol should be
    required.  For example::

        Apple = trivialInput(Fruit.apple)

    @param symbol: A symbol from some state machine's input alphabet.

    @return: A new type object usable as a rich input for the given symbol.
    @rtype: L{type}
    """
    return implementer(IRichInput)(type(
            symbol.name.title(), (FancyStrMixin, object), {
                "symbol": _symbol(symbol),
                })) 
开发者ID:ScatterHQ,项目名称:machinist,代码行数:21,代码来源:_fsm.py

示例2: test_sequenceOfStrings

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import FancyStrMixin [as 别名]
def test_sequenceOfStrings(self):
        """
        If C{showAttributes} is set to a sequence of strings, C{__str__}
        renders using those by looking them up as attributes on the object.
        """
        class Foo(util.FancyStrMixin):
            showAttributes = ("first", "second")
            first = 1
            second = "hello"
        self.assertEqual(str(Foo()), "<Foo first=1 second='hello'>") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_util.py

示例3: test_formatter

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import FancyStrMixin [as 别名]
def test_formatter(self):
        """
        If C{showAttributes} has an item that is a 2-tuple, C{__str__} renders
        the first item in the tuple as a key and the result of calling the
        second item with the value of the attribute named by the first item as
        the value.
        """
        class Foo(util.FancyStrMixin):
            showAttributes = (
                "first",
                ("second", lambda value: repr(value[::-1])))
            first = "hello"
            second = "world"
        self.assertEqual("<Foo first='hello' second='dlrow'>", str(Foo())) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_util.py

示例4: test_override

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import FancyStrMixin [as 别名]
def test_override(self):
        """
        If C{showAttributes} has an item that is a 3-tuple, C{__str__} renders
        the second item in the tuple as a key, and the contents of the
        attribute named in the first item are rendered as the value. The value
        is formatted using the third item in the tuple.
        """
        class Foo(util.FancyStrMixin):
            showAttributes = ("first", ("second", "2nd", "%.1f"))
            first = 1
            second = 2.111
        self.assertEqual(str(Foo()), "<Foo first=1 2nd=2.1>") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_util.py

示例5: test_fancybasename

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import FancyStrMixin [as 别名]
def test_fancybasename(self):
        """
        If C{fancybasename} is present, C{__str__} uses it instead of the class name.
        """
        class Foo(util.FancyStrMixin):
            fancybasename = "Bar"
        self.assertEqual(str(Foo()), "<Bar>") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_util.py

示例6: test_repr

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import FancyStrMixin [as 别名]
def test_repr(self):
        """
        C{__repr__} outputs the same content as C{__str__}.
        """
        class Foo(util.FancyStrMixin):
            showAttributes = ("first", "second")
            first = 1
            second = "hello"
        obj = Foo()
        self.assertEqual(str(obj), repr(obj)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_util.py


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