Python twisted.protocols.basic.NetstringReceiver() Examples
The following are 4
code examples of twisted.protocols.basic.NetstringReceiver().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.protocols.basic
, or try the search function
.
Example #1
Source File: test_basic.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
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')
Example #2
Source File: test_basic.py From learn_python3_spider with MIT License | 5 votes |
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')
Example #3
Source File: test_protocols.py From python-for-android with Apache License 2.0 | 5 votes |
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)
Example #4
Source File: test_protocols.py From python-for-android with Apache License 2.0 | 5 votes |
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."))