當前位置: 首頁>>代碼示例>>Python>>正文


Python basic.NetstringReceiver方法代碼示例

本文整理匯總了Python中twisted.protocols.basic.NetstringReceiver方法的典型用法代碼示例。如果您正苦於以下問題:Python basic.NetstringReceiver方法的具體用法?Python basic.NetstringReceiver怎麽用?Python basic.NetstringReceiver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.protocols.basic的用法示例。


在下文中一共展示了basic.NetstringReceiver方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_stringReceivedNotImplemented

# 需要導入模塊: from twisted.protocols import basic [as 別名]
# 或者: from twisted.protocols.basic import NetstringReceiver [as 別名]
def test_stringReceivedNotImplemented(self):
        """
        When L{NetstringReceiver.stringReceived} is not overridden in a
        subclass, calling it raises C{NotImplementedError}.
        """
        proto = basic.NetstringReceiver()
        self.assertRaises(NotImplementedError, proto.stringReceived, 'foo') 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:9,代碼來源:test_basic.py

示例2: test_sendNonStrings

# 需要導入模塊: from twisted.protocols import basic [as 別名]
# 或者: from twisted.protocols.basic import NetstringReceiver [as 別名]
def test_sendNonStrings(self):
        """
        L{basic.NetstringReceiver.sendString} will send objects that are not
        strings by sending their string representation according to str().
        """
        nonStrings = [ [], { 1 : 'a', 2 : 'b' }, ['a', 'b', 'c'], 673,
                       (12, "fine", "and", "you?") ]
        a = TestNetstring()
        t = proto_helpers.StringTransport()
        a.MAX_LENGTH = 100
        a.makeConnection(t)
        for s in nonStrings:
            a.sendString(s)
            out = t.value()
            t.clear()
            length = out[:out.find(":")]
            data = out[out.find(":") + 1:-1] #[:-1] to ignore the trailing ","
            self.assertEquals(int(length), len(str(s)))
            self.assertEquals(data, str(s))

        warnings = self.flushWarnings(
            offendingFunctions=[self.test_sendNonStrings])
        self.assertEqual(len(warnings), 5)
        self.assertEqual(
            warnings[0]["message"],
            "Data passed to sendString() must be a string. Non-string support "
            "is deprecated since Twisted 10.0")
        self.assertEqual(
            warnings[0]['category'],
            DeprecationWarning) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:32,代碼來源:test_protocols.py

示例3: test_deprecatedModuleAttributes

# 需要導入模塊: from twisted.protocols import basic [as 別名]
# 或者: from twisted.protocols.basic import NetstringReceiver [as 別名]
def test_deprecatedModuleAttributes(self):
        """
        Accessing one of the old module attributes used by the
        NetstringReceiver parser emits a deprecation warning.
        """
        basic.LENGTH, basic.DATA, basic.COMMA, basic.NUMBER
        warnings = self.flushWarnings(
            offendingFunctions=[self.test_deprecatedModuleAttributes])

        self.assertEquals(len(warnings), 4)
        for warning in warnings:
            self.assertEquals(warning['category'], DeprecationWarning)
        self.assertEquals(
            warnings[0]['message'],
            ("twisted.protocols.basic.LENGTH was deprecated in Twisted 10.2.0: "
             "NetstringReceiver parser state is private."))
        self.assertEquals(
            warnings[1]['message'],
            ("twisted.protocols.basic.DATA was deprecated in Twisted 10.2.0: "
             "NetstringReceiver parser state is private."))
        self.assertEquals(
            warnings[2]['message'],
            ("twisted.protocols.basic.COMMA was deprecated in Twisted 10.2.0: "
             "NetstringReceiver parser state is private."))
        self.assertEquals(
            warnings[3]['message'],
            ("twisted.protocols.basic.NUMBER was deprecated in Twisted 10.2.0: "
             "NetstringReceiver parser state is private.")) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:30,代碼來源:test_protocols.py


注:本文中的twisted.protocols.basic.NetstringReceiver方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。