當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。