r47160 - convert inline comments into twistedchecker-friendly epydoc
glyph-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Tue, 5 Apr 2016 15:00:30 -0600 (MDT)
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: glyph
Date: Tue Apr 5 15:00:25 2016
New Revision: 47160
Modified:
branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_v2parser.py
Log:
convert inline comments into twistedchecker-friendly epydoc
Modified: branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_v2parser.py
==============================================================================
--- branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_v2parser.py (original)
+++ branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_v2parser.py Tue Apr 5 15:00:25 2016
@@ -11,96 +11,120 @@
from .. import _exc
from .. import _v2parser
+V2_SIGNATURE = b'\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A'
-class V2ParserTests(unittest.TestCase):
+def _makeHeaderIPv6(sig=V2_SIGNATURE, verCom=b'\x21', famProto=b'\x21',
+ addrLength=b'\x00\x24',
+ addrs=((b'\x00' * 15) + b'\x01') * 2,
+ ports=b'\x1F\x90\x22\xB8'):
"""
- Test L{twisted.protocols.haproxy.V2Parser} behaviour.
+ Construct a version 2 IPv6 header with custom bytes.
+
+ @param sig: The protocol signature; defaults to valid L{V2_SIGNATURE}.
+ @type sig: L{bytes}
+
+ @param verCom: Protocol version and command. Defaults to V2 PROXY.
+ @type verCom: L{bytes}
+
+ @param famProto: Address family and protocol. Defaults to AF_INET6/STREAM.
+ @type famProto: L{bytes}
+
+ @param addrLength: Network-endian byte length of payload. Defaults to
+ description of default addrs/ports.
+ @type addrLength: L{bytes}
+
+ @param addrs: Address payload. Defaults to C{::1} for source and
+ destination.
+ @type addrs: L{bytes}
+
+ @param ports: Source and destination ports. Defaults to 8080 for source
+ 8888 for destination.
+ @type ports: L{bytes}
+
+ @return: A packet with header, addresses, and ports.
+ @rtype: L{bytes}
"""
+ return sig + verCom + famProto + addrLength + addrs + ports
+
- def _makeHeaderIPv6(
- self,
- sig=None,
- verCom=None,
- famProto=None,
- addrLength=None,
- addrs=None,
- ports=None,
- ):
- """
- Construct a version 2 header with custom bytes.
- """
- sig = sig or b'\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A'
- # V2 PROXY
- verCom = verCom or b'\x21'
- # AF_INET6/STREAM
- famProto = famProto or b'\x21'
- # 16 bytes for 2 IPv6 addresses and two ports
- addrLength = addrLength or b'\x00\x24'
- # ::1 for source and destination
- addrs = addrs or ((b'\x00' * 15) + b'\x01') * 2
- # 8080 for source 8888 for destination
- ports = ports or b'\x1F\x90\x22\xB8'
- return sig + verCom + famProto + addrLength + addrs + ports
-
-
- def _makeHeaderIPv4(
- self,
- sig=None,
- verCom=None,
- famProto=None,
- addrLength=None,
- addrs=None,
- ports=None,
- ):
- """
- Construct a version 2 header with custom bytes.
- """
- sig = sig or b'\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A'
- # V2 PROXY
- verCom = verCom or b'\x21'
- # AF_INET/STREAM
- famProto = famProto or b'\x11'
- # 12 bytes for 2 IPv4 addresses and two ports
- addrLength = addrLength or b'\x00\x0C'
- # 127.0.0.1 for source and destination
- addrs = addrs or b'\x7F\x00\x00\x01\x7F\x00\x00\x01'
- # 8080 for source 8888 for destination
- ports = ports or b'\x1F\x90\x22\xB8'
- return sig + verCom + famProto + addrLength + addrs + ports
-
-
- def _makeHeaderUnix(
- self,
- sig=None,
- verCom=None,
- famProto=None,
- addrLength=None,
- addrs=None,
- ):
- """
- Construct a version 2 header with custom bytes.
- """
- sig = sig or b'\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A'
- # V2 PROXY
- verCom = verCom or b'\x21'
- # AF_UNIX/STREAM
- famProto = famProto or b'\x31'
- # 108 bytes for 2 null terminated paths
- addrLength = addrLength or b'\x00\xD8'
- # /home/tests/mysockets/sock for source and destination paths
- defaultAddrs = (
- b'\x2F\x68\x6F\x6D\x65\x2F\x74\x65\x73\x74\x73\x2F\x6D\x79\x73\x6F'
- b'\x63\x6B\x65\x74\x73\x2F\x73\x6F\x63\x6B' + (b'\x00' * 82)
- ) * 2
- addrs = addrs or defaultAddrs
- return sig + verCom + famProto + addrLength + addrs
+def _makeHeaderIPv4(sig=V2_SIGNATURE, verCom=b'\x21', famProto=b'\x11',
+ addrLength=b'\x00\x0C',
+ addrs=b'\x7F\x00\x00\x01\x7F\x00\x00\x01',
+ ports=b'\x1F\x90\x22\xB8'):
+ """
+ Construct a version 2 IPv4 header with custom bytes.
+
+ @param sig: The protocol signature; defaults to valid L{V2_SIGNATURE}.
+ @type sig: L{bytes}
+
+ @param verCom: Protocol version and command. Defaults to V2 PROXY.
+ @type verCom: L{bytes}
+
+ @param famProto: Address family and protocol. Defaults to AF_INET/STREAM.
+ @type famProto: L{bytes}
+
+ @param addrLength: Network-endian byte length of payload. Defaults to
+ description of default addrs/ports.
+ @type addrLength: L{bytes}
+
+ @param addrs: Address payload. Defaults to 127.0.0.1 for source and
+ destination.
+ @type addrs: L{bytes}
+
+ @param ports: Source and destination ports. Defaults to 8080 for source
+ 8888 for destination.
+ @type ports: L{bytes}
+
+ @return: A packet with header, addresses, and ports.
+ @rtype: L{bytes}
+ """
+ return sig + verCom + famProto + addrLength + addrs + ports
+
+
+
+def _makeHeaderUnix(sig=V2_SIGNATURE, verCom=b'\x21', famProto=b'\x31',
+ addrLength=b'\x00\xD8',
+ addrs=(b'\x2F\x68\x6F\x6D\x65\x2F\x74\x65\x73\x74\x73\x2F'
+ b'\x6D\x79\x73\x6F\x63\x6B\x65\x74\x73\x2F\x73\x6F'
+ b'\x63\x6B' + (b'\x00' * 82)) * 2):
+ """
+ Construct a version 2 IPv4 header with custom bytes.
+
+ @param sig: The protocol signature; defaults to valid L{V2_SIGNATURE}.
+ @type sig: L{bytes}
+
+ @param verCom: Protocol version and command. Defaults to V2 PROXY.
+ @type verCom: L{bytes}
+
+ @param famProto: Address family and protocol. Defaults to AF_UNIX/STREAM.
+ @type famProto: L{bytes}
+
+ @param addrLength: Network-endian byte length of payload. Defaults to 108
+ bytes for 2 null terminated paths.
+ @type addrLength: L{bytes}
+
+ @param addrs: Address payload. Defaults to C{/home/tests/mysockets/sock}
+ for source and destination paths.
+ @type addrs: L{bytes}
+
+ @return: A packet with header, addresses, and8 ports.
+ @rtype: L{bytes}
+ """
+ return sig + verCom + famProto + addrLength + addrs
+
+
+
+class V2ParserTests(unittest.TestCase):
+ """
+ Test L{twisted.protocols.haproxy.V2Parser} behaviour.
+ """
def test_happyPathIPv4(self):
"""
Test if a well formed IPv4 header is parsed without error.
"""
- header = self._makeHeaderIPv4()
+ header = _makeHeaderIPv4()
self.assertTrue(_v2parser.V2Parser.parse(header))
@@ -108,7 +132,7 @@
"""
Test if a well formed IPv6 header is parsed without error.
"""
- header = self._makeHeaderIPv6()
+ header = _makeHeaderIPv6()
self.assertTrue(_v2parser.V2Parser.parse(header))
@@ -116,7 +140,7 @@
"""
Test if a well formed UNIX header is parsed without error.
"""
- header = self._makeHeaderUnix()
+ header = _makeHeaderUnix()
self.assertTrue(_v2parser.V2Parser.parse(header))
@@ -124,7 +148,7 @@
"""
Test if an invalid signature block raises InvalidProxyError.
"""
- header = self._makeHeaderIPv4(sig=b'\x00'*12)
+ header = _makeHeaderIPv4(sig=b'\x00'*12)
self.assertRaises(
_exc.InvalidProxyHeader,
_v2parser.V2Parser.parse,
@@ -136,7 +160,7 @@
"""
Test if an invalid version raises InvalidProxyError.
"""
- header = self._makeHeaderIPv4(verCom=b'\x11')
+ header = _makeHeaderIPv4(verCom=b'\x11')
self.assertRaises(
_exc.InvalidProxyHeader,
_v2parser.V2Parser.parse,
@@ -148,7 +172,7 @@
"""
Test if an invalid command raises InvalidProxyError.
"""
- header = self._makeHeaderIPv4(verCom=b'\x23')
+ header = _makeHeaderIPv4(verCom=b'\x23')
self.assertRaises(
_exc.InvalidProxyHeader,
_v2parser.V2Parser.parse,
@@ -160,7 +184,7 @@
"""
Test if an invalid family raises InvalidProxyError.
"""
- header = self._makeHeaderIPv4(famProto=b'\x40')
+ header = _makeHeaderIPv4(famProto=b'\x40')
self.assertRaises(
_exc.InvalidProxyHeader,
_v2parser.V2Parser.parse,
@@ -172,7 +196,7 @@
"""
Test if an invalid protocol raises InvalidProxyError.
"""
- header = self._makeHeaderIPv4(famProto=b'\x24')
+ header = _makeHeaderIPv4(famProto=b'\x24')
self.assertRaises(
_exc.InvalidProxyHeader,
_v2parser.V2Parser.parse,
@@ -184,7 +208,7 @@
"""
Test that local does not return endpoint data for IPv4 connections.
"""
- header = self._makeHeaderIPv4(verCom=b'\x20')
+ header = _makeHeaderIPv4(verCom=b'\x20')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination)
@@ -194,7 +218,7 @@
"""
Test that local does not return endpoint data for IPv6 connections.
"""
- header = self._makeHeaderIPv6(verCom=b'\x20')
+ header = _makeHeaderIPv6(verCom=b'\x20')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination)
@@ -204,7 +228,7 @@
"""
Test that local does not return endpoint data for UNIX connections.
"""
- header = self._makeHeaderUnix(verCom=b'\x20')
+ header = _makeHeaderUnix(verCom=b'\x20')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination)
@@ -214,7 +238,7 @@
"""
Test that proxy returns endpoint data for IPv4 connections.
"""
- header = self._makeHeaderIPv4(verCom=b'\x21')
+ header = _makeHeaderIPv4(verCom=b'\x21')
info = _v2parser.V2Parser.parse(header)
self.assertTrue(info.source)
self.assertTrue(isinstance(info.source, address.IPv4Address))
@@ -226,7 +250,7 @@
"""
Test that proxy returns endpoint data for IPv6 connections.
"""
- header = self._makeHeaderIPv6(verCom=b'\x21')
+ header = _makeHeaderIPv6(verCom=b'\x21')
info = _v2parser.V2Parser.parse(header)
self.assertTrue(info.source)
self.assertTrue(isinstance(info.source, address.IPv6Address))
@@ -238,7 +262,7 @@
"""
Test that proxy returns endpoint data for UNIX connections.
"""
- header = self._makeHeaderUnix(verCom=b'\x21')
+ header = _makeHeaderUnix(verCom=b'\x21')
info = _v2parser.V2Parser.parse(header)
self.assertTrue(info.source)
self.assertTrue(isinstance(info.source, address.UNIXAddress))
@@ -250,7 +274,7 @@
"""
Test that UNSPEC does not return endpoint data for IPv4 connections.
"""
- header = self._makeHeaderIPv4(famProto=b'\x01')
+ header = _makeHeaderIPv4(famProto=b'\x01')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination)
@@ -260,7 +284,7 @@
"""
Test that UNSPEC does not return endpoint data for IPv6 connections.
"""
- header = self._makeHeaderIPv6(famProto=b'\x01')
+ header = _makeHeaderIPv6(famProto=b'\x01')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination)
@@ -270,7 +294,7 @@
"""
Test that UNSPEC does not return endpoint data for UNIX connections.
"""
- header = self._makeHeaderUnix(famProto=b'\x01')
+ header = _makeHeaderUnix(famProto=b'\x01')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination)
@@ -280,7 +304,7 @@
"""
Test that UNSPEC does not return endpoint data for IPv4 connections.
"""
- header = self._makeHeaderIPv4(famProto=b'\x10')
+ header = _makeHeaderIPv4(famProto=b'\x10')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination)
@@ -290,7 +314,7 @@
"""
Test that UNSPEC does not return endpoint data for IPv6 connections.
"""
- header = self._makeHeaderIPv6(famProto=b'\x20')
+ header = _makeHeaderIPv6(famProto=b'\x20')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination)
@@ -300,7 +324,7 @@
"""
Test that UNSPEC does not return endpoint data for UNIX connections.
"""
- header = self._makeHeaderUnix(famProto=b'\x30')
+ header = _makeHeaderUnix(famProto=b'\x30')
info = _v2parser.V2Parser.parse(header)
self.assertFalse(info.source)
self.assertFalse(info.destination)
@@ -311,7 +335,7 @@
Test that overflow bits are preserved during feed parsing for IPv4.
"""
testValue = b'TEST DATA\r\n\r\nTEST DATA'
- header = self._makeHeaderIPv4() + testValue
+ header = _makeHeaderIPv4() + testValue
parser = _v2parser.V2Parser()
info, overflow = parser.feed(header)
self.assertTrue(info)
@@ -323,7 +347,7 @@
Test that overflow bits are preserved during feed parsing for IPv6.
"""
testValue = b'TEST DATA\r\n\r\nTEST DATA'
- header = self._makeHeaderIPv6() + testValue
+ header = _makeHeaderIPv6() + testValue
parser = _v2parser.V2Parser()
info, overflow = parser.feed(header)
self.assertTrue(info)
@@ -335,7 +359,7 @@
Test that overflow bits are preserved during feed parsing for Unix.
"""
testValue = b'TEST DATA\r\n\r\nTEST DATA'
- header = self._makeHeaderUnix() + testValue
+ header = _makeHeaderUnix() + testValue
parser = _v2parser.V2Parser()
info, overflow = parser.feed(header)
self.assertTrue(info)