3 M]W5 @sdZddlZddlZyeWneefk r8eZYnXdZdddZdddZ Gd d d ej Z Gd d d ej Z Gd ddej Z Gddde ej Z Gddde ejZddZdS)aLPython 'hex' Codec - 2-digit hex with spaces content transfer encoding. Encode and decode may be a bit missleading at first sight... The textual representation is a hex dump: e.g. "40 41" The "encoded" data of this is the binary form, e.g. b"@A" Therefore decoding is binary to text and thus converting binary data to hex dump. NZ0123456789ABCDEFstrictcCs tjdd|jDt|fS)z'40 41 42' -> b'@ab'cSsg|]}t|dqS))int).0hr#/usr/lib/python3.6/hexlify_codec.py &szhex_encode..)serialto_bytessplitlen)dataerrorsrrr hex_encode$srcCs&tdjddtj|Dt|fS)zb'@ab' -> '40 41 42'css|]}djt|VqdS)z{:02X} N)formatord)rbrrr +szhex_decode..)unicodejoinr iterbytesr )rrrrr hex_decode)src@s eZdZdddZdddZdS) CodecrcCstjdd|jDS)z'40 41 42' -> b'@ab'cSsg|]}t|dqS)r)r)rrrrrr 1sz Codec.encode..)r r r )selfrrrrrencode/sz Codec.encodecCstdjddtj|DS)zb'@ab' -> '40 41 42'rcss|]}djt|VqdS)z{:02X} N)rr)rrrrrr5szCodec.decode..)rrr r)rrrrrrdecode3sz Codec.decodeN)r)r)__name__ __module__ __qualname__rrrrrrr.s rc@s<eZdZdZdddZddZddZd d Zdd d ZdS)IncrementalEncoderzIncremental hex encoderrcCs||_d|_dS)Nr)rstate)rrrrr__init__;szIncrementalEncoder.__init__cCs d|_dS)Nr)r")rrrrreset?szIncrementalEncoder.resetcCs|jS)N)r")rrrrgetstateBszIncrementalEncoder.getstatecCs ||_dS)N)r")rr"rrrsetstateEszIncrementalEncoder.setstateFcCs|j}g}x|jD]|}|tkrTtj|}|rF|j||d@d}qd|d>}q|dkrx|rr|jdkrrtdd}q|jdkrtdj|qW||_tj |S) z Incremental encode, keep track of digits and emit a byte when a pair of hex digits is found. The space is optional unless the error handling is defined to be 'strict'. r rzodd number of hex digitsznon-hex digit found: {!r}) r"upper HEXDIGITSindexappendr UnicodeErrorrr r )rrfinalr"ZencodedczrrrrHs"  zIncrementalEncoder.encodeN)r)F) rrr __doc__r#r$r%r&rrrrrr!8s  r!c@seZdZdZdddZdS)IncrementalDecoderzIncremental decoderFcCstdjddtj|DS)Nrcss|]}djt|VqdS)z{:02X} N)rr)rrrrrrfsz,IncrementalDecoder.decode..)rrr r)rrr0rrrreszIncrementalDecoder.decodeN)F)rrr r3rrrrrr4csr4c@seZdZdZdS) StreamWriterz-Combination of hexlify codec and StreamWriterN)rrr r3rrrrr5isr5c@seZdZdZdS) StreamReaderz-Combination of hexlify codec and StreamReaderN)rrr r3rrrrr6msr6c CstjdttttttdS)zencodings module APIZhexlify)namerrincrementalencoderincrementaldecoder streamwriter streamreader)codecs CodecInforrr!r4r5r6rrrr getregentryqsr>)r)r)r3r<r r NameErrorAttributeErrorstrr,rrrr!r4r5r6r>rrrrs    +