^](dZddlmZddlZddlZ en#eef$reZYnwxYwdZ ddZ ddZ Gdd ej Z Gd d ej Z Gd d ejZGdde ejZGdde ejZdZdS)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. )absolute_importN0123456789ABCDEFstrictctjd|Dt|fS)'40 41 42' -> b'@ab'c.g|]}t|dSint.0hs zhex_encode..(s >>>ASBZZ>>>)serialto_bytessplitlendataerrorss r hex_encoder&s4 O>>>>> ? ?T KKrctddtj|Dt |fS)b'@ab' -> '40 41 42'c3ZK|]&}dt|V'dSz{:02X} Nformatordrbs r zhex_decode..-s6UUI,,SVV44UUUUUUr)unicodejoinr iterbytesrrs r hex_decoder)+sE BGGUUf>Nt>T>TUUUUU V VX[\`XaXa bbrceZdZddZddZdS)Codecrcbtjd|DS)rc.g|]}t|dSr r r s rrz Codec.encode..3s AAAqAr AAAr)rrrselfrrs rencodez Codec.encode1s)AADJJLLAAABBBrc~tddtj|DS)rrc3ZK|]&}dt|V'dSrr r#s rr%zCodec.decode..76XXAy//A77XXXXXXrr&r'rr(r.s rdecodez Codec.decode5s7rwwXXAQRVAWAWXXXXXYYYrNr)__name__ __module__ __qualname__r0r5rrr+r+0sFCCCCZZZZZZrr+c4eZdZdZd dZdZdZdZd dZd S) IncrementalEncoderzIncremental hex encoderrc"||_d|_dSNr)rstate)r/rs r__init__zIncrementalEncoder.__init__=s  rcd|_dSr>r?r/s rresetzIncrementalEncoder.resetAs  rc|jSNrBrCs rgetstatezIncrementalEncoder.getstateDs zrc||_dSrFrB)r/r?s rsetstatezIncrementalEncoder.setstateGs  rFc|j}g}|D]}|tvrCt|}|r|||dzzd}Ed|dzz}N|dkr|r|jdkrt dd}s|jdkr"t d|||_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 UnicodeErrorr!rr)r/rfinalr?encodedczs rr0zIncrementalEncoder.encodeJs   N NAI~~OOA&&-NN1 #5666EE!Q!V,EEcCT[H44&'ABBB;(**&'B'I'I!'L'LMMM+ w'''rNr6F) r7r8r9__doc__r@rDrGrIr0r:rrr<r<:so!!((((((rr<ceZdZdZddZdS)IncrementalDecoderzIncremental decoderFc~tddtj|DS)Nrc3ZK|]&}dt|V'dSrr r#s rr%z,IncrementalDecoder.decode..hr3rr4)r/rrTs rr5zIncrementalDecoder.decodegs7rwwXXAQRVAWAWXXXXXYYYrNrX)r7r8r9rYr5r:rrr[r[es4ZZZZZZrr[ceZdZdZdS) StreamWriterz-Combination of hexlify codec and StreamWriterNr7r8r9rYr:rrr_r_k7777rr_ceZdZdZdS) StreamReaderz-Combination of hexlify codec and StreamReaderNr`r:rrrcrcorarrcc ttjdtttt t tS)zencodings module APIhexlify)namer0r5incrementalencoderincrementaldecoder streamwriter streamreader)codecs CodecInforr)r<r[r_rcr:rr getregentryrmss1   --!!    rr6)rY __future__rrkrr& NameErrorAttributeErrorstrrPrr)r+r<r[r_rcrmr:rrrrs  '&&&&&  GG>"GGG  LLLL cccc ZZZZZFLZZZ((((((((((2((((((VZZZZZ2ZZZ 888885&-888888885&-888     s  !!