当前位置: 首页>>代码示例>>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;未经允许,请勿转载。