code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
182
| url
stringlengths 46
251
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def test_localCommandUnix(self):
"""
Test that local does not return endpoint data for UNIX connections.
"""
header = _makeHeaderUnix(verCom=b'\x20')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination) | Test that local does not return endpoint data for UNIX connections. | test_localCommandUnix | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | MIT |
def test_proxyCommandIpv4(self):
"""
Test that proxy returns endpoint data for IPv4 connections.
"""
header = _makeHeaderIPv4(verCom=b'\x21')
info = _v2parser.V2Parser.parse(header)
self.assertTrue(info.source)
self.assertIsInstance(info.source, address.IPv4Address)
self.assertTrue(info.destination)
self.assertIsInstance(info.destination, address.IPv4Address) | Test that proxy returns endpoint data for IPv4 connections. | test_proxyCommandIpv4 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | MIT |
def test_proxyCommandIpv6(self):
"""
Test that proxy returns endpoint data for IPv6 connections.
"""
header = _makeHeaderIPv6(verCom=b'\x21')
info = _v2parser.V2Parser.parse(header)
self.assertTrue(info.source)
self.assertIsInstance(info.source, address.IPv6Address)
self.assertTrue(info.destination)
self.assertIsInstance(info.destination, address.IPv6Address) | Test that proxy returns endpoint data for IPv6 connections. | test_proxyCommandIpv6 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | MIT |
def test_proxyCommandUnix(self):
"""
Test that proxy returns endpoint data for UNIX connections.
"""
header = _makeHeaderUnix(verCom=b'\x21')
info = _v2parser.V2Parser.parse(header)
self.assertTrue(info.source)
self.assertIsInstance(info.source, address.UNIXAddress)
self.assertTrue(info.destination)
self.assertIsInstance(info.destination, address.UNIXAddress) | Test that proxy returns endpoint data for UNIX connections. | test_proxyCommandUnix | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | MIT |
def test_unspecFamilyIpv4(self):
"""
Test that UNSPEC does not return endpoint data for IPv4 connections.
"""
header = _makeHeaderIPv4(famProto=b'\x01')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination) | Test that UNSPEC does not return endpoint data for IPv4 connections. | test_unspecFamilyIpv4 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | MIT |
def test_unspecFamilyIpv6(self):
"""
Test that UNSPEC does not return endpoint data for IPv6 connections.
"""
header = _makeHeaderIPv6(famProto=b'\x01')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination) | Test that UNSPEC does not return endpoint data for IPv6 connections. | test_unspecFamilyIpv6 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | MIT |
def test_unspecFamilyUnix(self):
"""
Test that UNSPEC does not return endpoint data for UNIX connections.
"""
header = _makeHeaderUnix(famProto=b'\x01')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination) | Test that UNSPEC does not return endpoint data for UNIX connections. | test_unspecFamilyUnix | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | MIT |
def test_overflowIpv4(self):
"""
Test that overflow bits are preserved during feed parsing for IPv4.
"""
testValue = b'TEST DATA\r\n\r\nTEST DATA'
header = _makeHeaderIPv4() + testValue
parser = _v2parser.V2Parser()
info, overflow = parser.feed(header)
self.assertTrue(info)
self.assertEqual(overflow, testValue) | Test that overflow bits are preserved during feed parsing for IPv4. | test_overflowIpv4 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | MIT |
def test_overflowIpv6(self):
"""
Test that overflow bits are preserved during feed parsing for IPv6.
"""
testValue = b'TEST DATA\r\n\r\nTEST DATA'
header = _makeHeaderIPv6() + testValue
parser = _v2parser.V2Parser()
info, overflow = parser.feed(header)
self.assertTrue(info)
self.assertEqual(overflow, testValue) | Test that overflow bits are preserved during feed parsing for IPv6. | test_overflowIpv6 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | MIT |
def test_overflowUnix(self):
"""
Test that overflow bits are preserved during feed parsing for Unix.
"""
testValue = b'TEST DATA\r\n\r\nTEST DATA'
header = _makeHeaderUnix() + testValue
parser = _v2parser.V2Parser()
info, overflow = parser.feed(header)
self.assertTrue(info)
self.assertEqual(overflow, testValue) | Test that overflow bits are preserved during feed parsing for Unix. | test_overflowUnix | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | MIT |
def test_segmentTooSmall(self):
"""
Test that an initial payload of less than 16 bytes fails.
"""
testValue = b'NEEDMOREDATA'
parser = _v2parser.V2Parser()
self.assertRaises(
InvalidProxyHeader,
parser.feed,
testValue,
) | Test that an initial payload of less than 16 bytes fails. | test_segmentTooSmall | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_v2parser.py | MIT |
def check(self, input):
"""
Check that the input unparses into the output, raising an assertion
error if it doesn't.
@param input: an input in endpoint-string-description format. (To
ensure determinism, keyword arguments should be in alphabetical
order.)
@type input: native L{str}
"""
self.assertEqual(unparseEndpoint(*parseEndpoint(input)), input) | Check that the input unparses into the output, raising an assertion
error if it doesn't.
@param input: an input in endpoint-string-description format. (To
ensure determinism, keyword arguments should be in alphabetical
order.)
@type input: native L{str} | check | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | MIT |
def test_basicUnparse(self):
"""
An individual word.
"""
self.check("word") | An individual word. | test_basicUnparse | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | MIT |
def test_multipleArguments(self):
"""
Multiple arguments.
"""
self.check("one:two") | Multiple arguments. | test_multipleArguments | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | MIT |
def test_keywords(self):
"""
Keyword arguments.
"""
self.check("aleph=one:bet=two") | Keyword arguments. | test_keywords | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | MIT |
def test_colonInArgument(self):
"""
Escaped ":".
"""
self.check("hello\\:colon\\:world") | Escaped ":". | test_colonInArgument | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | MIT |
def test_colonInKeywordValue(self):
"""
Escaped ":" in keyword value.
"""
self.check("hello=\\:") | Escaped ":" in keyword value. | test_colonInKeywordValue | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | MIT |
def test_colonInKeywordName(self):
"""
Escaped ":" in keyword name.
"""
self.check("\\:=hello") | Escaped ":" in keyword name. | test_colonInKeywordName | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | MIT |
def onePrefix(self, description, expectedClass):
"""
Test the C{haproxy} enpdoint prefix against one sub-endpoint type.
@param description: A string endpoint description beginning with
C{haproxy}.
@type description: native L{str}
@param expectedClass: the expected sub-endpoint class given the
description.
@type expectedClass: L{type}
@return: the parsed endpoint
@rtype: L{IStreamServerEndpoint}
@raise twisted.trial.unittest.Failtest: if the parsed endpoint doesn't
match expectations.
"""
reactor = MemoryReactor()
endpoint = serverFromString(reactor, description)
self.assertIsInstance(endpoint, _WrapperServerEndpoint)
self.assertIsInstance(endpoint._wrappedEndpoint, expectedClass)
self.assertIs(endpoint._wrapperFactory, HAProxyWrappingFactory)
return endpoint | Test the C{haproxy} enpdoint prefix against one sub-endpoint type.
@param description: A string endpoint description beginning with
C{haproxy}.
@type description: native L{str}
@param expectedClass: the expected sub-endpoint class given the
description.
@type expectedClass: L{type}
@return: the parsed endpoint
@rtype: L{IStreamServerEndpoint}
@raise twisted.trial.unittest.Failtest: if the parsed endpoint doesn't
match expectations. | onePrefix | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | MIT |
def test_tcp4(self):
"""
Test if the parser generates a wrapped TCP4 endpoint.
"""
self.onePrefix('haproxy:tcp:8080', TCP4ServerEndpoint) | Test if the parser generates a wrapped TCP4 endpoint. | test_tcp4 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | MIT |
def test_tcp6(self):
"""
Test if the parser generates a wrapped TCP6 endpoint.
"""
self.onePrefix('haproxy:tcp6:8080', TCP6ServerEndpoint) | Test if the parser generates a wrapped TCP6 endpoint. | test_tcp6 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | MIT |
def test_unix(self):
"""
Test if the parser generates a wrapped UNIX endpoint.
"""
self.onePrefix('haproxy:unix:address=/tmp/socket', UNIXServerEndpoint) | Test if the parser generates a wrapped UNIX endpoint. | test_unix | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_parser.py | MIT |
def test_invalidHeaderDisconnects(self):
"""
Test if invalid headers result in connectionLost events.
"""
factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
proto = factory.buildProtocol(
address.IPv4Address('TCP', b'127.1.1.1', 8080),
)
transport = StringTransportWithDisconnection()
transport.protocol = proto
proto.makeConnection(transport)
proto.dataReceived(b'NOTPROXY anything can go here\r\n')
self.assertFalse(transport.connected) | Test if invalid headers result in connectionLost events. | test_invalidHeaderDisconnects | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | MIT |
def test_validIPv4HeaderResolves_getPeerHost(self):
"""
Test if IPv4 headers result in the correct host and peer data.
"""
factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
proto = factory.buildProtocol(
address.IPv4Address('TCP', b'127.0.0.1', 8080),
)
transport = StringTransportWithDisconnection()
proto.makeConnection(transport)
proto.dataReceived(b'PROXY TCP4 1.1.1.1 2.2.2.2 8080 8888\r\n')
self.assertEqual(proto.getPeer().host, b'1.1.1.1')
self.assertEqual(proto.getPeer().port, 8080)
self.assertEqual(
proto.wrappedProtocol.transport.getPeer().host,
b'1.1.1.1',
)
self.assertEqual(
proto.wrappedProtocol.transport.getPeer().port,
8080,
)
self.assertEqual(proto.getHost().host, b'2.2.2.2')
self.assertEqual(proto.getHost().port, 8888)
self.assertEqual(
proto.wrappedProtocol.transport.getHost().host,
b'2.2.2.2',
)
self.assertEqual(
proto.wrappedProtocol.transport.getHost().port,
8888,
) | Test if IPv4 headers result in the correct host and peer data. | test_validIPv4HeaderResolves_getPeerHost | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | MIT |
def test_validIPv6HeaderResolves_getPeerHost(self):
"""
Test if IPv6 headers result in the correct host and peer data.
"""
factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
proto = factory.buildProtocol(
address.IPv6Address('TCP', b'::1', 8080),
)
transport = StringTransportWithDisconnection()
proto.makeConnection(transport)
proto.dataReceived(b'PROXY TCP6 ::1 ::2 8080 8888\r\n')
self.assertEqual(proto.getPeer().host, b'::1')
self.assertEqual(proto.getPeer().port, 8080)
self.assertEqual(
proto.wrappedProtocol.transport.getPeer().host,
b'::1',
)
self.assertEqual(
proto.wrappedProtocol.transport.getPeer().port,
8080,
)
self.assertEqual(proto.getHost().host, b'::2')
self.assertEqual(proto.getHost().port, 8888)
self.assertEqual(
proto.wrappedProtocol.transport.getHost().host,
b'::2',
)
self.assertEqual(
proto.wrappedProtocol.transport.getHost().port,
8888,
) | Test if IPv6 headers result in the correct host and peer data. | test_validIPv6HeaderResolves_getPeerHost | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | MIT |
def test_overflowBytesSentToWrappedProtocol(self):
"""
Test if non-header bytes are passed to the wrapped protocol.
"""
factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
proto = factory.buildProtocol(
address.IPv6Address('TCP', b'::1', 8080),
)
transport = StringTransportWithDisconnection()
proto.makeConnection(transport)
proto.dataReceived(b'PROXY TCP6 ::1 ::2 8080 8888\r\nHTTP/1.1 / GET')
self.assertEqual(proto.wrappedProtocol.data, b'HTTP/1.1 / GET') | Test if non-header bytes are passed to the wrapped protocol. | test_overflowBytesSentToWrappedProtocol | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | MIT |
def test_overflowBytesSentToWrappedProtocolChunks(self):
"""
Test if header streaming passes extra data appropriately.
"""
factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
proto = factory.buildProtocol(
address.IPv6Address('TCP', b'::1', 8080),
)
transport = StringTransportWithDisconnection()
proto.makeConnection(transport)
proto.dataReceived(b'PROXY TCP6 ::1 ::2 ')
proto.dataReceived(b'8080 8888\r\nHTTP/1.1 / GET')
self.assertEqual(proto.wrappedProtocol.data, b'HTTP/1.1 / GET') | Test if header streaming passes extra data appropriately. | test_overflowBytesSentToWrappedProtocolChunks | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | MIT |
def test_overflowBytesSentToWrappedProtocolAfter(self):
"""
Test if wrapper writes all data to wrapped protocol after parsing.
"""
factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
proto = factory.buildProtocol(
address.IPv6Address('TCP', b'::1', 8080),
)
transport = StringTransportWithDisconnection()
proto.makeConnection(transport)
proto.dataReceived(b'PROXY TCP6 ::1 ::2 ')
proto.dataReceived(b'8080 8888\r\nHTTP/1.1 / GET')
proto.dataReceived(b'\r\n\r\n')
self.assertEqual(proto.wrappedProtocol.data, b'HTTP/1.1 / GET\r\n\r\n') | Test if wrapper writes all data to wrapped protocol after parsing. | test_overflowBytesSentToWrappedProtocolAfter | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | MIT |
def test_validUNIXHeaderResolves_getPeerHost(self):
"""
Test if UNIX headers result in the correct host and peer data.
"""
factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
proto = factory.buildProtocol(
address.UNIXAddress(b'/home/test/sockets/server.sock'),
)
transport = StringTransportWithDisconnection()
proto.makeConnection(transport)
proto.dataReceived(self.UNIXHEADER)
self.assertEqual(proto.getPeer().name, b'/home/tests/mysockets/sock')
self.assertEqual(
proto.wrappedProtocol.transport.getPeer().name,
b'/home/tests/mysockets/sock',
)
self.assertEqual(proto.getHost().name, b'/home/tests/mysockets/sock')
self.assertEqual(
proto.wrappedProtocol.transport.getHost().name,
b'/home/tests/mysockets/sock',
) | Test if UNIX headers result in the correct host and peer data. | test_validUNIXHeaderResolves_getPeerHost | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/haproxy/test/test_wrapper.py | MIT |
def lineReceived(self, line):
"""
Set the mode to raw.
"""
self.lines.append(line)
self.setRawMode() | Set the mode to raw. | lineReceived | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def rawDataReceived(self, data):
"""
Set the mode back to line.
"""
self.setLineMode(data[1:]) | Set the mode back to line. | rawDataReceived | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def __init__(self, clock=None):
"""
If given, use a clock to make callLater calls.
"""
self.clock = clock | If given, use a clock to make callLater calls. | __init__ | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def connectionMade(self):
"""
Create/clean data received on connection.
"""
self.received = [] | Create/clean data received on connection. | connectionMade | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def lineReceived(self, line):
"""
Receive line and make some action for some tokens: pause, rawpause,
stop, len, produce, unproduce.
"""
self.received.append(line)
if line == b'':
self.setRawMode()
elif line == b'pause':
self.pauseProducing()
self.clock.callLater(0, self.resumeProducing)
elif line == b'rawpause':
self.pauseProducing()
self.setRawMode()
self.received.append(b'')
self.clock.callLater(0, self.resumeProducing)
elif line == b'stop':
self.stopProducing()
elif line[:4] == b'len ':
self.length = int(line[4:])
elif line.startswith(b'produce'):
self.transport.registerProducer(self, False)
elif line.startswith(b'unproduce'):
self.transport.unregisterProducer() | Receive line and make some action for some tokens: pause, rawpause,
stop, len, produce, unproduce. | lineReceived | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def rawDataReceived(self, data):
"""
Read raw data, until the quantity specified by a previous 'len' line is
reached.
"""
data, rest = data[:self.length], data[self.length:]
self.length = self.length - len(data)
self.received[-1] = self.received[-1] + data
if self.length == 0:
self.setLineMode(rest) | Read raw data, until the quantity specified by a previous 'len' line is
reached. | rawDataReceived | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def lineLengthExceeded(self, line):
"""
Adjust line mode when long lines received.
"""
if len(line) > self.MAX_LENGTH + 1:
self.setLineMode(line[self.MAX_LENGTH + 1:]) | Adjust line mode when long lines received. | lineLengthExceeded | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def lineReceived(self, line):
"""
Save received data.
"""
self.received.append(line) | Save received data. | lineReceived | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_buffer(self):
"""
Test buffering for different packet size, checking received matches
expected data.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
a = LineTester()
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.buffer) // packet_size + 1):
s = self.buffer[i * packet_size:(i + 1) * packet_size]
a.dataReceived(s)
self.assertEqual(self.output, a.received) | Test buffering for different packet size, checking received matches
expected data. | test_buffer | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_pausing(self):
"""
Test pause inside data receiving. It uses fake clock to see if
pausing/resuming work.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
clock = task.Clock()
a = LineTester(clock)
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.pauseBuf) // packet_size + 1):
s = self.pauseBuf[i * packet_size:(i + 1) * packet_size]
a.dataReceived(s)
self.assertEqual(self.pauseOutput1, a.received)
clock.advance(0)
self.assertEqual(self.pauseOutput2, a.received) | Test pause inside data receiving. It uses fake clock to see if
pausing/resuming work. | test_pausing | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_rawPausing(self):
"""
Test pause inside raw date receiving.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
clock = task.Clock()
a = LineTester(clock)
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.rawpauseBuf) // packet_size + 1):
s = self.rawpauseBuf[i * packet_size:(i + 1) * packet_size]
a.dataReceived(s)
self.assertEqual(self.rawpauseOutput1, a.received)
clock.advance(0)
self.assertEqual(self.rawpauseOutput2, a.received) | Test pause inside raw date receiving. | test_rawPausing | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_stopProducing(self):
"""
Test stop inside producing.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
a = LineTester()
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.stop_buf) // packet_size + 1):
s = self.stop_buf[i * packet_size:(i + 1) * packet_size]
a.dataReceived(s)
self.assertEqual(self.stop_output, a.received) | Test stop inside producing. | test_stopProducing | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_lineReceiverAsProducer(self):
"""
Test produce/unproduce in receiving.
"""
a = LineTester()
t = proto_helpers.StringIOWithoutClosing()
a.makeConnection(protocol.FileWrapper(t))
a.dataReceived(b'produce\nhello world\nunproduce\ngoodbye\n')
self.assertEqual(
a.received, [b'produce', b'hello world', b'unproduce', b'goodbye']) | Test produce/unproduce in receiving. | test_lineReceiverAsProducer | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_clearLineBuffer(self):
"""
L{LineReceiver.clearLineBuffer} removes all buffered data and returns
it as a C{bytes} and can be called from beneath C{dataReceived}.
"""
class ClearingReceiver(basic.LineReceiver):
def lineReceived(self, line):
self.line = line
self.rest = self.clearLineBuffer()
protocol = ClearingReceiver()
protocol.dataReceived(b'foo\r\nbar\r\nbaz')
self.assertEqual(protocol.line, b'foo')
self.assertEqual(protocol.rest, b'bar\r\nbaz')
# Deliver another line to make sure the previously buffered data is
# really gone.
protocol.dataReceived(b'quux\r\n')
self.assertEqual(protocol.line, b'quux')
self.assertEqual(protocol.rest, b'') | L{LineReceiver.clearLineBuffer} removes all buffered data and returns
it as a C{bytes} and can be called from beneath C{dataReceived}. | test_clearLineBuffer | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_stackRecursion(self):
"""
Test switching modes many times on the same data.
"""
proto = FlippingLineTester()
transport = proto_helpers.StringIOWithoutClosing()
proto.makeConnection(protocol.FileWrapper(transport))
limit = sys.getrecursionlimit()
proto.dataReceived(b'x\nx' * limit)
self.assertEqual(b'x' * limit, b''.join(proto.lines)) | Test switching modes many times on the same data. | test_stackRecursion | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_maximumLineLength(self):
"""
C{LineReceiver} disconnects the transport if it receives a line longer
than its C{MAX_LENGTH}.
"""
proto = basic.LineReceiver()
transport = proto_helpers.StringTransport()
proto.makeConnection(transport)
proto.dataReceived(b'x' * (proto.MAX_LENGTH + 1) + b'\r\nr')
self.assertTrue(transport.disconnecting) | C{LineReceiver} disconnects the transport if it receives a line longer
than its C{MAX_LENGTH}. | test_maximumLineLength | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_maximumLineLengthPartialDelimiter(self):
"""
C{LineReceiver} doesn't disconnect the transport when it
receives a finished line as long as its C{MAX_LENGTH}, when
the second-to-last packet ended with a pattern that could have
been -- and turns out to have been -- the start of a
delimiter, and that packet causes the total input to exceed
C{MAX_LENGTH} + len(delimiter).
"""
proto = LineTester()
proto.MAX_LENGTH = 4
t = proto_helpers.StringTransport()
proto.makeConnection(t)
line = b'x' * (proto.MAX_LENGTH - 1)
proto.dataReceived(line)
proto.dataReceived(proto.delimiter[:-1])
proto.dataReceived(proto.delimiter[-1:] + line)
self.assertFalse(t.disconnecting)
self.assertEqual(len(proto.received), 1)
self.assertEqual(line, proto.received[0]) | C{LineReceiver} doesn't disconnect the transport when it
receives a finished line as long as its C{MAX_LENGTH}, when
the second-to-last packet ended with a pattern that could have
been -- and turns out to have been -- the start of a
delimiter, and that packet causes the total input to exceed
C{MAX_LENGTH} + len(delimiter). | test_maximumLineLengthPartialDelimiter | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_notQuiteMaximumLineLengthUnfinished(self):
"""
C{LineReceiver} doesn't disconnect the transport it if
receives a non-finished line whose length, counting the
delimiter, is longer than its C{MAX_LENGTH} but shorter than
its C{MAX_LENGTH} + len(delimiter). (When the first part that
exceeds the max is the beginning of the delimiter.)
"""
proto = basic.LineReceiver()
# '\r\n' is the default, but we set it just to be explicit in
# this test.
proto.delimiter = b'\r\n'
transport = proto_helpers.StringTransport()
proto.makeConnection(transport)
proto.dataReceived((b'x' * proto.MAX_LENGTH)
+ proto.delimiter[:len(proto.delimiter)-1])
self.assertFalse(transport.disconnecting) | C{LineReceiver} doesn't disconnect the transport it if
receives a non-finished line whose length, counting the
delimiter, is longer than its C{MAX_LENGTH} but shorter than
its C{MAX_LENGTH} + len(delimiter). (When the first part that
exceeds the max is the beginning of the delimiter.) | test_notQuiteMaximumLineLengthUnfinished | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_rawDataError(self):
"""
C{LineReceiver.dataReceived} forwards errors returned by
C{rawDataReceived}.
"""
proto = basic.LineReceiver()
proto.rawDataReceived = lambda data: RuntimeError("oops")
transport = proto_helpers.StringTransport()
proto.makeConnection(transport)
proto.setRawMode()
why = proto.dataReceived(b'data')
self.assertIsInstance(why, RuntimeError) | C{LineReceiver.dataReceived} forwards errors returned by
C{rawDataReceived}. | test_rawDataError | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_rawDataReceivedNotImplemented(self):
"""
When L{LineReceiver.rawDataReceived} is not overridden in a
subclass, calling it raises C{NotImplementedError}.
"""
proto = basic.LineReceiver()
self.assertRaises(NotImplementedError, proto.rawDataReceived, 'foo') | When L{LineReceiver.rawDataReceived} is not overridden in a
subclass, calling it raises C{NotImplementedError}. | test_rawDataReceivedNotImplemented | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_lineReceivedNotImplemented(self):
"""
When L{LineReceiver.lineReceived} is not overridden in a subclass,
calling it raises C{NotImplementedError}.
"""
proto = basic.LineReceiver()
self.assertRaises(NotImplementedError, proto.lineReceived, 'foo') | When L{LineReceiver.lineReceived} is not overridden in a subclass,
calling it raises C{NotImplementedError}. | test_lineReceivedNotImplemented | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def lineReceived(self, line):
"""
Disregard any received lines.
""" | Disregard any received lines. | lineReceived | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def lineLengthExceeded(self, data):
"""
Record any data that exceeds the line length limits.
"""
self.longLines.append(data) | Record any data that exceeds the line length limits. | lineLengthExceeded | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_longUnendedLine(self):
"""
If more bytes than C{LineReceiver.MAX_LENGTH} arrive containing no line
delimiter, all of the bytes are passed as a single string to
L{LineReceiver.lineLengthExceeded}.
"""
excessive = b'x' * (self.proto.MAX_LENGTH * 2 + 2)
self.proto.dataReceived(excessive)
self.assertEqual([excessive], self.proto.longLines) | If more bytes than C{LineReceiver.MAX_LENGTH} arrive containing no line
delimiter, all of the bytes are passed as a single string to
L{LineReceiver.lineLengthExceeded}. | test_longUnendedLine | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_longLineAfterShortLine(self):
"""
If L{LineReceiver.dataReceived} is called with bytes representing a
short line followed by bytes that exceed the length limit without a
line delimiter, L{LineReceiver.lineLengthExceeded} is called with all
of the bytes following the short line's delimiter.
"""
excessive = b'x' * (self.proto.MAX_LENGTH * 2 + 2)
self.proto.dataReceived(b'x' + self.proto.delimiter + excessive)
self.assertEqual([excessive], self.proto.longLines) | If L{LineReceiver.dataReceived} is called with bytes representing a
short line followed by bytes that exceed the length limit without a
line delimiter, L{LineReceiver.lineLengthExceeded} is called with all
of the bytes following the short line's delimiter. | test_longLineAfterShortLine | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_longLineWithDelimiter(self):
"""
If L{LineReceiver.dataReceived} is called with more than
C{LineReceiver.MAX_LENGTH} bytes containing a line delimiter somewhere
not in the first C{MAX_LENGTH} bytes, the entire byte string is passed
to L{LineReceiver.lineLengthExceeded}.
"""
excessive = self.proto.delimiter.join(
[b'x' * (self.proto.MAX_LENGTH * 2 + 2)] * 2)
self.proto.dataReceived(excessive)
self.assertEqual([excessive], self.proto.longLines) | If L{LineReceiver.dataReceived} is called with more than
C{LineReceiver.MAX_LENGTH} bytes containing a line delimiter somewhere
not in the first C{MAX_LENGTH} bytes, the entire byte string is passed
to L{LineReceiver.lineLengthExceeded}. | test_longLineWithDelimiter | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_multipleLongLines(self):
"""
If L{LineReceiver.dataReceived} is called with more than
C{LineReceiver.MAX_LENGTH} bytes containing multiple line delimiters
somewhere not in the first C{MAX_LENGTH} bytes, the entire byte string
is passed to L{LineReceiver.lineLengthExceeded}.
"""
excessive = (
b'x' * (self.proto.MAX_LENGTH * 2 + 2) + self.proto.delimiter) * 2
self.proto.dataReceived(excessive)
self.assertEqual([excessive], self.proto.longLines) | If L{LineReceiver.dataReceived} is called with more than
C{LineReceiver.MAX_LENGTH} bytes containing multiple line delimiters
somewhere not in the first C{MAX_LENGTH} bytes, the entire byte string
is passed to L{LineReceiver.lineLengthExceeded}. | test_multipleLongLines | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_maximumLineLengthRemaining(self):
"""
C{LineReceiver} disconnects the transport it if receives a non-finished
line longer than its C{MAX_LENGTH}.
"""
proto = basic.LineReceiver()
transport = proto_helpers.StringTransport()
proto.makeConnection(transport)
proto.dataReceived(b'x' * (proto.MAX_LENGTH + len(proto.delimiter)))
self.assertTrue(transport.disconnecting) | C{LineReceiver} disconnects the transport it if receives a non-finished
line longer than its C{MAX_LENGTH}. | test_maximumLineLengthRemaining | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_buffer(self):
"""
Test buffering over line protocol: data received should match buffer.
"""
t = proto_helpers.StringTransport()
a = LineOnlyTester()
a.makeConnection(t)
for c in iterbytes(self.buffer):
a.dataReceived(c)
self.assertEqual(a.received, self.buffer.split(b'\n')[:-1]) | Test buffering over line protocol: data received should match buffer. | test_buffer | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_greaterThanMaximumLineLength(self):
"""
C{LineOnlyReceiver} disconnects the transport if it receives a
line longer than its C{MAX_LENGTH} + len(delimiter).
"""
proto = LineOnlyTester()
transport = proto_helpers.StringTransport()
proto.makeConnection(transport)
proto.dataReceived(b'x' * (proto.MAX_LENGTH
+ len(proto.delimiter) + 1) + b'\r\nr')
self.assertTrue(transport.disconnecting) | C{LineOnlyReceiver} disconnects the transport if it receives a
line longer than its C{MAX_LENGTH} + len(delimiter). | test_greaterThanMaximumLineLength | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_lineReceivedNotImplemented(self):
"""
When L{LineOnlyReceiver.lineReceived} is not overridden in a subclass,
calling it raises C{NotImplementedError}.
"""
proto = basic.LineOnlyReceiver()
self.assertRaises(NotImplementedError, proto.lineReceived, 'foo') | When L{LineOnlyReceiver.lineReceived} is not overridden in a subclass,
calling it raises C{NotImplementedError}. | test_lineReceivedNotImplemented | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def getProtocol(self):
"""
Return a new instance of C{self.protocol} connected to a new instance
of L{proto_helpers.StringTransport}.
"""
t = proto_helpers.StringTransport()
a = self.protocol()
a.makeConnection(t)
return a | Return a new instance of C{self.protocol} connected to a new instance
of L{proto_helpers.StringTransport}. | getProtocol | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_illegal(self):
"""
Assert that illegal strings cause the transport to be closed.
"""
for s in self.illegalStrings:
r = self.getProtocol()
for c in iterbytes(s):
r.dataReceived(c)
self.assertTrue(r.transport.disconnecting) | Assert that illegal strings cause the transport to be closed. | test_illegal | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_buffer(self):
"""
Strings can be received in chunks of different lengths.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringTransport()
a = TestNetstring()
a.MAX_LENGTH = 699
a.makeConnection(t)
for s in self.strings:
a.sendString(s)
out = t.value()
for i in range(len(out) // packet_size + 1):
s = out[i * packet_size:(i + 1) * packet_size]
if s:
a.dataReceived(s)
self.assertEqual(a.received, self.strings) | Strings can be received in chunks of different lengths. | test_buffer | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_receiveEmptyNetstring(self):
"""
Empty netstrings (with length '0') can be received.
"""
self.netstringReceiver.dataReceived(b"0:,")
self.assertEqual(self.netstringReceiver.received, [b""]) | Empty netstrings (with length '0') can be received. | test_receiveEmptyNetstring | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_receiveOneCharacter(self):
"""
One-character netstrings can be received.
"""
self.netstringReceiver.dataReceived(b"1:a,")
self.assertEqual(self.netstringReceiver.received, [b"a"]) | One-character netstrings can be received. | test_receiveOneCharacter | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_receiveTwoCharacters(self):
"""
Two-character netstrings can be received.
"""
self.netstringReceiver.dataReceived(b"2:ab,")
self.assertEqual(self.netstringReceiver.received, [b"ab"]) | Two-character netstrings can be received. | test_receiveTwoCharacters | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_receiveNestedNetstring(self):
"""
Netstrings with embedded netstrings. This test makes sure that
the parser does not become confused about the ',' and ':'
characters appearing inside the data portion of the netstring.
"""
self.netstringReceiver.dataReceived(b"4:1:a,,")
self.assertEqual(self.netstringReceiver.received, [b"1:a,"]) | Netstrings with embedded netstrings. This test makes sure that
the parser does not become confused about the ',' and ':'
characters appearing inside the data portion of the netstring. | test_receiveNestedNetstring | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_moreDataThanSpecified(self):
"""
Netstrings containing more data than expected are refused.
"""
self.netstringReceiver.dataReceived(b"2:aaa,")
self.assertTrue(self.transport.disconnecting) | Netstrings containing more data than expected are refused. | test_moreDataThanSpecified | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_moreDataThanSpecifiedBorderCase(self):
"""
Netstrings that should be empty according to their length
specification are refused if they contain data.
"""
self.netstringReceiver.dataReceived(b"0:a,")
self.assertTrue(self.transport.disconnecting) | Netstrings that should be empty according to their length
specification are refused if they contain data. | test_moreDataThanSpecifiedBorderCase | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_missingNumber(self):
"""
Netstrings without leading digits that specify the length
are refused.
"""
self.netstringReceiver.dataReceived(b":aaa,")
self.assertTrue(self.transport.disconnecting) | Netstrings without leading digits that specify the length
are refused. | test_missingNumber | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_missingColon(self):
"""
Netstrings without a colon between length specification and
data are refused.
"""
self.netstringReceiver.dataReceived(b"3aaa,")
self.assertTrue(self.transport.disconnecting) | Netstrings without a colon between length specification and
data are refused. | test_missingColon | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_missingNumberAndColon(self):
"""
Netstrings that have no leading digits nor a colon are
refused.
"""
self.netstringReceiver.dataReceived(b"aaa,")
self.assertTrue(self.transport.disconnecting) | Netstrings that have no leading digits nor a colon are
refused. | test_missingNumberAndColon | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_onlyData(self):
"""
Netstrings consisting only of data are refused.
"""
self.netstringReceiver.dataReceived(b"aaa")
self.assertTrue(self.transport.disconnecting) | Netstrings consisting only of data are refused. | test_onlyData | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_receiveNetstringPortions_1(self):
"""
Netstrings can be received in two portions.
"""
self.netstringReceiver.dataReceived(b"4:aa")
self.netstringReceiver.dataReceived(b"aa,")
self.assertEqual(self.netstringReceiver.received, [b"aaaa"])
self.assertTrue(self.netstringReceiver._payloadComplete()) | Netstrings can be received in two portions. | test_receiveNetstringPortions_1 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_receiveNetstringPortions_2(self):
"""
Netstrings can be received in more than two portions, even if
the length specification is split across two portions.
"""
for part in [b"1", b"0:01234", b"56789", b","]:
self.netstringReceiver.dataReceived(part)
self.assertEqual(self.netstringReceiver.received, [b"0123456789"]) | Netstrings can be received in more than two portions, even if
the length specification is split across two portions. | test_receiveNetstringPortions_2 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_receiveNetstringPortions_3(self):
"""
Netstrings can be received one character at a time.
"""
for part in [b"2", b":", b"a", b"b", b","]:
self.netstringReceiver.dataReceived(part)
self.assertEqual(self.netstringReceiver.received, [b"ab"]) | Netstrings can be received one character at a time. | test_receiveNetstringPortions_3 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_receiveTwoNetstrings(self):
"""
A stream of two netstrings can be received in two portions,
where the first portion contains the complete first netstring
and the length specification of the second netstring.
"""
self.netstringReceiver.dataReceived(b"1:a,1")
self.assertTrue(self.netstringReceiver._payloadComplete())
self.assertEqual(self.netstringReceiver.received, [b"a"])
self.netstringReceiver.dataReceived(b":b,")
self.assertEqual(self.netstringReceiver.received, [b"a", b"b"]) | A stream of two netstrings can be received in two portions,
where the first portion contains the complete first netstring
and the length specification of the second netstring. | test_receiveTwoNetstrings | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_maxReceiveLimit(self):
"""
Netstrings with a length specification exceeding the specified
C{MAX_LENGTH} are refused.
"""
tooLong = self.netstringReceiver.MAX_LENGTH + 1
self.netstringReceiver.dataReceived(b"".join(
(bytes(tooLong), b":", b"a" * tooLong)))
self.assertTrue(self.transport.disconnecting) | Netstrings with a length specification exceeding the specified
C{MAX_LENGTH} are refused. | test_maxReceiveLimit | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_consumeLength(self):
"""
C{_consumeLength} returns the expected length of the
netstring, including the trailing comma.
"""
self.netstringReceiver._remainingData = b"12:"
self.netstringReceiver._consumeLength()
self.assertEqual(self.netstringReceiver._expectedPayloadSize, 13) | C{_consumeLength} returns the expected length of the
netstring, including the trailing comma. | test_consumeLength | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_consumeLengthBorderCase1(self):
"""
C{_consumeLength} works as expected if the length specification
contains the value of C{MAX_LENGTH} (border case).
"""
self.netstringReceiver._remainingData = b"12:"
self.netstringReceiver.MAX_LENGTH = 12
self.netstringReceiver._consumeLength()
self.assertEqual(self.netstringReceiver._expectedPayloadSize, 13) | C{_consumeLength} works as expected if the length specification
contains the value of C{MAX_LENGTH} (border case). | test_consumeLengthBorderCase1 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_consumeLengthBorderCase2(self):
"""
C{_consumeLength} raises a L{basic.NetstringParseError} if
the length specification exceeds the value of C{MAX_LENGTH}
by 1 (border case).
"""
self.netstringReceiver._remainingData = b"12:"
self.netstringReceiver.MAX_LENGTH = 11
self.assertRaises(basic.NetstringParseError,
self.netstringReceiver._consumeLength) | C{_consumeLength} raises a L{basic.NetstringParseError} if
the length specification exceeds the value of C{MAX_LENGTH}
by 1 (border case). | test_consumeLengthBorderCase2 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_consumeLengthBorderCase3(self):
"""
C{_consumeLength} raises a L{basic.NetstringParseError} if
the length specification exceeds the value of C{MAX_LENGTH}
by more than 1.
"""
self.netstringReceiver._remainingData = b"1000:"
self.netstringReceiver.MAX_LENGTH = 11
self.assertRaises(basic.NetstringParseError,
self.netstringReceiver._consumeLength) | C{_consumeLength} raises a L{basic.NetstringParseError} if
the length specification exceeds the value of C{MAX_LENGTH}
by more than 1. | test_consumeLengthBorderCase3 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
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') | When L{NetstringReceiver.stringReceived} is not overridden in a
subclass, calling it raises C{NotImplementedError}. | test_stringReceivedNotImplemented | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_receive(self):
"""
Test receiving data find the same data send.
"""
r = self.getProtocol()
for s in self.strings:
for c in iterbytes(struct.pack(r.structFormat,len(s)) + s):
r.dataReceived(c)
self.assertEqual(r.received, self.strings) | Test receiving data find the same data send. | test_receive | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_partial(self):
"""
Send partial data, nothing should be definitely received.
"""
for s in self.partialStrings:
r = self.getProtocol()
for c in iterbytes(s):
r.dataReceived(c)
self.assertEqual(r.received, []) | Send partial data, nothing should be definitely received. | test_partial | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_send(self):
"""
Test sending data over protocol.
"""
r = self.getProtocol()
r.sendString(b"b" * 16)
self.assertEqual(r.transport.value(),
struct.pack(r.structFormat, 16) + b"b" * 16) | Test sending data over protocol. | test_send | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_lengthLimitExceeded(self):
"""
When a length prefix is received which is greater than the protocol's
C{MAX_LENGTH} attribute, the C{lengthLimitExceeded} method is called
with the received length prefix.
"""
length = []
r = self.getProtocol()
r.lengthLimitExceeded = length.append
r.MAX_LENGTH = 10
r.dataReceived(struct.pack(r.structFormat, 11))
self.assertEqual(length, [11]) | When a length prefix is received which is greater than the protocol's
C{MAX_LENGTH} attribute, the C{lengthLimitExceeded} method is called
with the received length prefix. | test_lengthLimitExceeded | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_longStringNotDelivered(self):
"""
If a length prefix for a string longer than C{MAX_LENGTH} is delivered
to C{dataReceived} at the same time as the entire string, the string is
not passed to C{stringReceived}.
"""
r = self.getProtocol()
r.MAX_LENGTH = 10
r.dataReceived(
struct.pack(r.structFormat, 11) + b'x' * 11)
self.assertEqual(r.received, []) | If a length prefix for a string longer than C{MAX_LENGTH} is delivered
to C{dataReceived} at the same time as the entire string, the string is
not passed to C{stringReceived}. | test_longStringNotDelivered | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_stringReceivedNotImplemented(self):
"""
When L{IntNStringReceiver.stringReceived} is not overridden in a
subclass, calling it raises C{NotImplementedError}.
"""
proto = basic.IntNStringReceiver()
self.assertRaises(NotImplementedError, proto.stringReceived, 'foo') | When L{IntNStringReceiver.stringReceived} is not overridden in a
subclass, calling it raises C{NotImplementedError}. | test_stringReceivedNotImplemented | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def makeMessage(self, protocol, data):
"""
Return C{data} prefixed with message length in C{protocol.structFormat}
form.
"""
return struct.pack(protocol.structFormat, len(data)) + data | Return C{data} prefixed with message length in C{protocol.structFormat}
form. | makeMessage | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_recvdContainsRemainingData(self):
"""
In stringReceived, recvd contains the remaining data that was passed to
dataReceived that was not part of the current message.
"""
result = []
r = self.getProtocol()
def stringReceived(receivedString):
result.append(r.recvd)
r.stringReceived = stringReceived
completeMessage = (struct.pack(r.structFormat, 5) + (b'a' * 5))
incompleteMessage = (struct.pack(r.structFormat, 5) + (b'b' * 4))
# Receive a complete message, followed by an incomplete one
r.dataReceived(completeMessage + incompleteMessage)
self.assertEqual(result, [incompleteMessage]) | In stringReceived, recvd contains the remaining data that was passed to
dataReceived that was not part of the current message. | test_recvdContainsRemainingData | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_recvdChanged(self):
"""
In stringReceived, if recvd is changed, messages should be parsed from
it rather than the input to dataReceived.
"""
r = self.getProtocol()
result = []
payloadC = b'c' * 5
messageC = self.makeMessage(r, payloadC)
def stringReceived(receivedString):
if not result:
r.recvd = messageC
result.append(receivedString)
r.stringReceived = stringReceived
payloadA = b'a' * 5
payloadB = b'b' * 5
messageA = self.makeMessage(r, payloadA)
messageB = self.makeMessage(r, payloadB)
r.dataReceived(messageA + messageB)
self.assertEqual(result, [payloadA, payloadC]) | In stringReceived, if recvd is changed, messages should be parsed from
it rather than the input to dataReceived. | test_recvdChanged | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_switching(self):
"""
Data already parsed by L{IntNStringReceiver.dataReceived} is not
reparsed if C{stringReceived} consumes some of the
L{IntNStringReceiver.recvd} buffer.
"""
proto = self.getProtocol()
mix = []
SWITCH = b"\x00\x00\x00\x00"
for s in self.strings:
mix.append(self.makeMessage(proto, s))
mix.append(SWITCH)
result = []
def stringReceived(receivedString):
result.append(receivedString)
proto.recvd = proto.recvd[len(SWITCH):]
proto.stringReceived = stringReceived
proto.dataReceived(b"".join(mix))
# Just another byte, to trigger processing of anything that might have
# been left in the buffer (should be nothing).
proto.dataReceived(b"\x01")
self.assertEqual(result, self.strings)
# And verify that another way
self.assertEqual(proto.recvd, b"\x01") | Data already parsed by L{IntNStringReceiver.dataReceived} is not
reparsed if C{stringReceived} consumes some of the
L{IntNStringReceiver.recvd} buffer. | test_switching | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_recvdInLengthLimitExceeded(self):
"""
The L{IntNStringReceiver.recvd} buffer contains all data not yet
processed by L{IntNStringReceiver.dataReceived} if the
C{lengthLimitExceeded} event occurs.
"""
proto = self.getProtocol()
DATA = b"too long"
proto.MAX_LENGTH = len(DATA) - 1
message = self.makeMessage(proto, DATA)
result = []
def lengthLimitExceeded(length):
result.append(length)
result.append(proto.recvd)
proto.lengthLimitExceeded = lengthLimitExceeded
proto.dataReceived(message)
self.assertEqual(result[0], len(DATA))
self.assertEqual(result[1], message) | The L{IntNStringReceiver.recvd} buffer contains all data not yet
processed by L{IntNStringReceiver.dataReceived} if the
C{lengthLimitExceeded} event occurs. | test_recvdInLengthLimitExceeded | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_data(self):
"""
Test specific behavior of the 32-bits length.
"""
r = self.getProtocol()
r.sendString(b"foo")
self.assertEqual(r.transport.value(), b"\x00\x00\x00\x03foo")
r.dataReceived(b"\x00\x00\x00\x04ubar")
self.assertEqual(r.received, [b"ubar"]) | Test specific behavior of the 32-bits length. | test_data | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_data(self):
"""
Test specific behavior of the 16-bits length.
"""
r = self.getProtocol()
r.sendString(b"foo")
self.assertEqual(r.transport.value(), b"\x00\x03foo")
r.dataReceived(b"\x00\x04ubar")
self.assertEqual(r.received, [b"ubar"]) | Test specific behavior of the 16-bits length. | test_data | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_tooLongSend(self):
"""
Send too much data: that should cause an error.
"""
r = self.getProtocol()
tooSend = b"b" * (2**(r.prefixLength * 8) + 1)
self.assertRaises(AssertionError, r.sendString, tooSend) | Send too much data: that should cause an error. | test_tooLongSend | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_data(self):
"""
Test specific behavior of the 8-bits length.
"""
r = self.getProtocol()
r.sendString(b"foo")
self.assertEqual(r.transport.value(), b"\x03foo")
r.dataReceived(b"\x04ubar")
self.assertEqual(r.received, [b"ubar"]) | Test specific behavior of the 8-bits length. | test_data | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_pauseResume(self):
"""
When L{basic.LineReceiver} is paused, it doesn't deliver lines to
L{basic.LineReceiver.lineReceived} and delivers them immediately upon
being resumed.
L{ConsumingProtocol} is a L{LineReceiver} that pauses itself after
every line, and writes that line to its transport.
"""
p = ConsumingProtocol()
t = OnlyProducerTransport()
p.makeConnection(t)
# Deliver a partial line.
# This doesn't trigger a pause and doesn't deliver a line.
p.dataReceived(b'hello, ')
self.assertEqual(t.data, [])
self.assertFalse(t.paused)
self.assertFalse(p.paused)
# Deliver the rest of the line.
# This triggers the pause, and the line is echoed.
p.dataReceived(b'world\r\n')
self.assertEqual(t.data, [b'hello, world'])
self.assertTrue(t.paused)
self.assertTrue(p.paused)
# Unpausing doesn't deliver more data, and the protocol is unpaused.
p.resumeProducing()
self.assertEqual(t.data, [b'hello, world'])
self.assertFalse(t.paused)
self.assertFalse(p.paused)
# Deliver two lines at once.
# The protocol is paused after receiving and echoing the first line.
p.dataReceived(b'hello\r\nworld\r\n')
self.assertEqual(t.data, [b'hello, world', b'hello'])
self.assertTrue(t.paused)
self.assertTrue(p.paused)
# Unpausing delivers the waiting line, and causes the protocol to
# pause again.
p.resumeProducing()
self.assertEqual(t.data, [b'hello, world', b'hello', b'world'])
self.assertTrue(t.paused)
self.assertTrue(p.paused)
# Deliver a line while paused.
# This doesn't have a visible effect.
p.dataReceived(b'goodbye\r\n')
self.assertEqual(t.data, [b'hello, world', b'hello', b'world'])
self.assertTrue(t.paused)
self.assertTrue(p.paused)
# Unpausing delivers the waiting line, and causes the protocol to
# pause again.
p.resumeProducing()
self.assertEqual(
t.data, [b'hello, world', b'hello', b'world', b'goodbye'])
self.assertTrue(t.paused)
self.assertTrue(p.paused)
# Unpausing doesn't deliver more data, and the protocol is unpaused.
p.resumeProducing()
self.assertEqual(
t.data, [b'hello, world', b'hello', b'world', b'goodbye'])
self.assertFalse(t.paused)
self.assertFalse(p.paused) | When L{basic.LineReceiver} is paused, it doesn't deliver lines to
L{basic.LineReceiver.lineReceived} and delivers them immediately upon
being resumed.
L{ConsumingProtocol} is a L{LineReceiver} that pauses itself after
every line, and writes that line to its transport. | test_pauseResume | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
def test_interface(self):
"""
L{basic.FileSender} implements the L{IPullProducer} interface.
"""
sender = basic.FileSender()
self.assertTrue(verifyObject(IProducer, sender)) | L{basic.FileSender} implements the L{IPullProducer} interface. | test_interface | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_basic.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.