ϪfdZddlmZmZddlmZddlmZddlm Z m Z ddl m Z m Z mZmZee j Gdd Zy ) zD IProxyParser implementation for version one of the PROXY protocol. )TupleUnion) implementer)address)_info _interfaces)InvalidNetworkProtocolInvalidProxyHeaderMissingAddressData convertErrorceZdZdZdZdZdZdZeeefZdZ dd Z d e de e eje fe d ffd Zed e dejfdZy)V1Parserz PROXY protocol version one header parser. Version one of the PROXY protocol is a human readable format represented by a single, newline delimited binary string that contains all of the relevant source and destination data. sPROXYsUNKNOWNsTCP4sTCP6s returnNcd|_y)N)buffer)selfs E/usr/lib/python3/dist-packages/twisted/protocols/haproxy/_v1parser.py__init__zV1Parser.__init__,s  rdataNNc|xj|z c_t|jdkDr"|j|jvr t|jj |jd}t|dkDsyd|_|j }|j }|j |}||fS)a Consume a chunk of data and attempt to parse it. @param data: A bytestring. @type data: L{bytes} @return: A two-tuple containing, in order, a L{_interfaces.IProxyInfo} and any bytes fed to the parser that followed the end of the header. Both of these values are None until a complete header is parsed. @raises InvalidProxyHeader: If the bytes fed to the parser create an invalid PROXY header. krrr)rlenNEWLINEr splitpopparse)rrlines remainingheaderinfos rfeedz V1Parser.feed/s" t t{{ c !dll$++&E$& &##DLL!45zA~ IIK zz&!i  rlinec |}d}d}d}d}d}d}ttt5|jdd\}}ddd||jk7r tttt 5|jdd\}}ddd||j vr t ||jk(rtj|ddSttt5|jdd\}}dddttt5|jdd\}}dddttt5|jdd\}}dddttt5|jdd}ddd||jk(rotj|tjd|jt|tjd|jt|Stj|tj d|jt|tj d|jt|S#1swYGxYw#1swY xYw#1swYxYw#1swYxYw#1swY\xYw#1swY8xYw)a Parse a bytestring as a full PROXY protocol header line. @param line: A bytestring that represents a valid HAProxy PROXY protocol header line. @type line: bytes @return: A L{_interfaces.IProxyInfo} containing the parsed data. @raises InvalidProxyHeader: If the bytestring does not represent a valid PROXY header. @raises InvalidNetworkProtocol: When no protocol can be parsed or is not one of the allowed values. @raises MissingAddressData: When the protocol is TCP* but the header does not contain a complete set of addresses and ports. N rrTCP)r ValueErrorr rPROXYSTRr ALLOWED_NET_PROTOS UNKNOWN_PROTOr ProxyInfor TCP4_PROTOr IPv4Addressdecodeint IPv6Address) clsr% originalLineproxyStrnetworkProtocol sourceAddr sourcePortdestAddrdestPorts rrzV1Parser.parseLsi(    *&8 9 1!ZZa0NHd 1 s|| #$& & *&< = 8$(JJtQ$7 !OT 8 #"8"8 8(* * c// /??<t< < *&8 9 3#zz$2 J 3*&8 9 1!ZZa0NHd 1*&8 9 3#zz$2 J 3*&8 9 +zz$'*H + cnn ,??##E:+<+<+>JP##E8??+.J JJ%J24J?>J JJ"%J/2J<?K )rN)__name__ __module__ __qualname____doc__r*r,r. TCP6_PROTOr+rrbytesrrrr-r$ classmethodrrrrrsHMJJ G!! uU__e+,eJ.?? @!:A A 5??A A rrN)r>typingrrzope.interfacertwisted.internetrrr _exceptionsr r r r IProxyParserrrBrrrIsI  &$  [ % %&v v 'v r