本文整理汇总了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),
}))
示例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'>")
示例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()))
示例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>")
示例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>")
示例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))