g~ddlZddlmZmZmZddlmZmZGddejZGddej Z Gd d ej Z Gd d eej Z Gd deej Z dZ dZdS)N)byte2intint2byteunichr)BASIC_CHARACTER_SETBASIC_CHARACTER_SET_EXTENSIONc2eZdZdZdZdZd dZd dZd dZdS) Codecz5 Stateless encoder and decoder for GSM 03.38 zgsm03.38Nc|t}|t}|_jt fd|Dt jj_dS)Nc3<K|]\}}jdz|z|fVdS)N)_ESCAPE).0keyvalueselfs ]/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/gsm0338/codec.py z!Codec.__init__..sTFF!c5<1$s*U3FFFFFF) rr _decode_mapupdatedictitemscodecsmake_encoding_map _encoding_map)rlocking_shift_decode_mapsingle_shift_decode_maps` r__init__zCodec.__init__s # +': $ " *&C #3  FFFF%<%B%B%D%DFFF F F G G G$5d6FGGrstrictc Bd}d}|D]}|dz }d} |jt|}n=#t$r0|dkrd}n$|dkrntd|j||dz fzYnwxYw|1|d zr|t |jz }|t |d zz }||fS) z Encode string to byte array :param input: string (unicode) object to convert to byte array :param errors: defines the error handling to apply :return: returns a tuple (output object, length consumed) rrrNreplace?ignorez3'%s' codec can't encode character %r in position %di)rordKeyError ValueErrorNAMErr)rinputerrors encode_bufferconsumed characternums rencodez Codec.encodes  6 6I MHC K(Y8 K K KY&&CCx''$%Z&*iHqL%I&JKKK  K<<!Xdl%;%;;M#*!5!55 h&&s,7A&%A&c d}d}d}|D]}|dz }|t|gz}||jkr|dz}+ |t|j|z }n#t$r}}|dkr|dz }ng|dkrn`||jdzzr+t d|j|jdd z|dz fzt d|j|jd|dz fzYd }~nd }~wwxYwd}||fS) z Decode byte array to string :param input: byte array to convert to unicode string :param errors: defines the error handling to apply :return: returns a tuple (output object, length consumed) rrrr#u�r%z0'%s' codec can't decode byte 0x%x in position %dr&N)rrrrr(r)r*args)rr+r, decode_bufferr.r0rexs rdecodez Codec.decode9s`   E MH 8UG$$ $Cdl""  P(8(=!>!>>  P P PY&&!Y.MMx''dla/0P()[*.)RWQZ$5FST )U*VWWW))[*.)RWQZA)N*OPPP PCCh&&sA CA3CC)NN)r!) __name__ __module__ __qualname____doc__r*rr r1r7rrr r sj DG H H H H''''8 ' ' ' ' ' 'rr ceZdZddZdS)IncrementalEncoderFcNtj||j|jdSNr)rcharmap_encoder,rrr+finals rr1zIncrementalEncoder.encode^s!$UDK9KLLQOOrNF)r8r9r:r1r<rrr>r>\s.PPPPPPrr>ceZdZddZdS)IncrementalDecoderFcNtj||j|jdSr@)rcharmap_decoder,rrBs rr7zIncrementalDecoder.decodeds!$UDK9IJJ1MMrNrD)r8r9r:r7r<rrrFrFbs.NNNNNNrrFceZdZdZdS) StreamWriterz+ StreamWriter: for GSM 03.38 codec Nr8r9r:r;r<rrrJrJh DrrJceZdZdZdS) StreamReaderz+ StreamReader: for GSM 03.38 codec NrKr<rrrNrNorLrrNc tjtjtjtjt tttS)zH encodings module API :return: CodecInfo for gsm03.38 codec )namer1r7incrementalencoderincrementaldecoder streamwriter streamreader) r CodecInfor r*r1r7r>rFrJrNr<rrget_codec_inforVwsA   Zww~ww~--!!   rcf|tjkrtSdS)z] Return codec info for 'gsm03.38' :param encoding: name of the searched encoding N)lowerr r*rV)encodings r find_gsm0338rZs, ~~5:%% 4r)rsixrrrcharsetrrr r>rFrJrNrVrZr<rrr]si **********GGGGGGGG Q'Q'Q'Q'Q'FLQ'Q'Q'hPPPPP2PPP NNNNN2NNN      5&-        5&-       r