Current File : //usr/lib/python3/dist-packages/serial/tools/__pycache__/hexlify_codec.cpython-312.pyc
�

��^]��8�dZddlmZddlZddlZ	edZ	dd�Z
dd�ZGd�dej�ZGd	�d
ej�Z
Gd�dej�ZGd
�deej�ZGd�deej �Zd�Zy#eef$reZY��wxYw)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_importN�0123456789ABCDEFc	��tj|j�D�cgc]}t|d���c}�t	|�fScc}w�z'40 41 42' -> b'@ab'�)�serial�to_bytes�split�int�len)�data�errors�hs   �</usr/lib/python3/dist-packages/serial/tools/hexlify_codec.py�
hex_encoder&s4���O�O�����>�A�S��B�Z�>�?��T��K�K��>s�Ac��tdjd�tj|�D���t	|�fS)�b'@ab' -> '40 41 42'�c3�PK�|]}djt|����� y�w�z{:02X} N��format�ord��.0�bs  r�	<genexpr>zhex_decode.<locals>.<genexpr>-s����U��I�,�,�S��V�4�U���$&)�unicode�joinr�	iterbytesr)r
rs  r�
hex_decoder"+s3���B�G�G�U�f�>N�>N�t�>T�U�U�V�X[�\`�Xa�b�b�c��eZdZdd�Zdd�Zy)�Codecc	��tj|j�D�cgc]}t|d���c}�Scc}wr)rr	r
r)�selfr
rrs    r�encodezCodec.encode1s+�����D�J�J�L�A�q��A�r�
�A�B�B��As�<c�j�tdjd�tj|�D���S)rrc3�PK�|]}djt|����� y�wrrrs  rrzCodec.decode.<locals>.<genexpr>7�����X�A�y�/�/��A��7�X�r�rr rr!)r'r
rs   r�decodezCodec.decode5s(���r�w�w�X��AQ�AQ�RV�AW�X�X�Y�Yr#N��strict)�__name__�
__module__�__qualname__r(r-�r#rr%r%0s��C�Zr#r%c�2�eZdZdZdd�Zd�Zd�Zd�Zd	d�Zy)
�IncrementalEncoderzIncremental hex encoderc� �||_d|_y�Nr)r�state)r'rs  r�__init__zIncrementalEncoder.__init__=s�������
r#c��d|_yr7�r8�r's r�resetzIncrementalEncoder.resetAs	����
r#c��|jS�Nr;r<s r�getstatezIncrementalEncoder.getstateDs���z�z�r#c��||_yr?r;)r'r8s  r�setstatezIncrementalEncoder.setstateGs	����
r#c��|j}g}|j�D]�}|tvr:tj|�}|r|j	||dzz�d}�<d|dzz}�E|dk(r|r|j
dk(rt
d��d}�i|j
dk(s�yt
dj|���||_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��� r/zodd number of hex digitsznon-hex digit found: {!r})
r8�upper�	HEXDIGITS�index�appendr�UnicodeErrorrrr	)r'r
�finalr8�encoded�c�zs       rr(zIncrementalEncoder.encodeJs����
�
��������	N�A��I�~��O�O�A�&����N�N�1����#5�6��E�!�Q�!�V�,�E��c���T�[�[�H�4�&�'A�B�B����;�;�(�*�&�'B�'I�'I�!�'L�M�M�	N���
����w�'�'r#Nr.�F)	r0r1r2�__doc__r9r=r@rBr(r3r#rr5r5:s��!�����(r#r5c��eZdZdZdd�Zy)�IncrementalDecoderzIncremental decoderc�j�tdjd�tj|�D���S)Nrc3�PK�|]}djt|����� y�wrrrs  rrz,IncrementalDecoder.decode.<locals>.<genexpr>hr+rr,)r'r
rMs   rr-zIncrementalDecoder.decodegs(���r�w�w�X��AQ�AQ�RV�AW�X�X�Y�Yr#NrQ)r0r1r2rRr-r3r#rrTrTes���Zr#rTc��eZdZdZy)�StreamWriterz-Combination of hexlify codec and StreamWriterN�r0r1r2rRr3r#rrXrXk���7r#rXc��eZdZdZy)�StreamReaderz-Combination of hexlify codec and StreamReaderNrYr3r#rr\r\orZr#r\c	�j�tjdtttt
tt��S)zencodings module API�hexlify)�namer(r-�incrementalencoder�incrementaldecoder�streamwriter�streamreader)�codecs�	CodecInforr"r5rTrXr\r3r#r�getregentryrfss*�����
���-�-�!�!�	�	r#r.)rR�
__future__rrdrr�	NameError�AttributeError�strrIrr"r%r5rTrXr\rfr3r#r�<module>rks���
�'�
�
���

�	�
L�
c�
Z�F�L�L�Z�((��2�2�((�VZ��2�2�Z�8�5�&�-�-�8�8�5�&�-�-�8���m	�>�"���G��s�B
�
	B�B