本文整理匯總了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))