
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
MÊ]W5  ã               @   s¼   d Z ddlZddlZye W n eefk
r8   eZY nX dZddd„Zddd„Z	G d	d
„ d
ej
ƒZ
G dd„ dejƒZG dd„ dejƒZG dd„ de
ejƒZG dd„ de
ejƒZdd„ ZdS )aL  Python '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.

é    NZ0123456789ABCDEFÚstrictc             C   s    t jdd„ | jƒ D ƒƒt| ƒfS )z'40 41 42' -> b'@ab'c             S   s   g | ]}t |d ƒ‘qS )é   )Úint)Ú.0Úh© r   ú#/usr/lib/python3.6/hexlify_codec.pyú
<listcomp>&   s    zhex_encode.<locals>.<listcomp>)ÚserialÚto_bytesÚsplitÚlen)ÚdataÚerrorsr   r   r   Ú
hex_encode$   s    r   c             C   s&   t djdd„ tj| ƒD ƒƒƒt| ƒfS )zb'@ab' -> '40 41 42'Ú c             s   s   | ]}d j t|ƒƒV  qdS )z{:02X} N)ÚformatÚord)r   Úbr   r   r   ú	<genexpr>+   s    zhex_decode.<locals>.<genexpr>)ÚunicodeÚjoinr
   Ú	iterbytesr   )r   r   r   r   r   Ú
hex_decode)   s    r   c               @   s    e Zd Zddd„Zddd„ZdS )	ÚCodecr   c             C   s   t jdd„ |jƒ D ƒƒS )z'40 41 42' -> b'@ab'c             S   s   g | ]}t |d ƒ‘qS )r   )r   )r   r   r   r   r   r	   1   s    z Codec.encode.<locals>.<listcomp>)r
   r   r   )Úselfr   r   r   r   r   Úencode/   s    zCodec.encodec             C   s   t djdd„ tj|ƒD ƒƒƒS )zb'@ab' -> '40 41 42'r   c             s   s   | ]}d j t|ƒƒV  qdS )z{:02X} N)r   r   )r   r   r   r   r   r   5   s    zCodec.decode.<locals>.<genexpr>)r   r   r
   r   )r   r   r   r   r   r   Údecode3   s    zCodec.decodeN)r   )r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   .   s   
r   c               @   s<   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zddd„ZdS )ÚIncrementalEncoderzIncremental hex encoderr   c             C   s   || _ d| _d S )Nr   )r   Ústate)r   r   r   r   r   Ú__init__;   s    zIncrementalEncoder.__init__c             C   s
   d| _ d S )Nr   )r"   )r   r   r   r   Úreset?   s    zIncrementalEncoder.resetc             C   s   | j S )N)r"   )r   r   r   r   ÚgetstateB   s    zIncrementalEncoder.getstatec             C   s
   || _ d S )N)r"   )r   r"   r   r   r   ÚsetstateE   s    zIncrementalEncoder.setstateFc             C   s¤   | j }g }xˆ|jƒ D ]|}|tkrTtj|ƒ}|rF|j||d@  ƒ d}q�d|d>  }q|dkrx|rr| jdkrrtdƒ‚d}q| jdkrtdj|ƒƒ‚qW || _ tj	|ƒ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   zodd number of hex digitsznon-hex digit found: {!r})
r"   ÚupperÚ	HEXDIGITSÚindexÚappendr   ÚUnicodeErrorr   r
   r   )r   r   Úfinalr"   ZencodedÚcÚzr   r   r   r   H   s"    

zIncrementalEncoder.encodeN)r   )F)	r   r   r    Ú__doc__r#   r$   r%   r&   r   r   r   r   r   r!   8   s   
r!   c               @   s   e Zd ZdZddd„ZdS )ÚIncrementalDecoderzIncremental decoderFc             C   s   t djdd„ tj|ƒD ƒƒƒS )Nr   c             s   s   | ]}d j t|ƒƒV  qdS )z{:02X} N)r   r   )r   r   r   r   r   r   f   s    z,IncrementalDecoder.decode.<locals>.<genexpr>)r   r   r
   r   )r   r   r0   r   r   r   r   e   s    zIncrementalDecoder.decodeN)F)r   r   r    r3   r   r   r   r   r   r4   c   s   r4   c               @   s   e Zd ZdZdS )ÚStreamWriterz-Combination of hexlify codec and StreamWriterN)r   r   r    r3   r   r   r   r   r5   i   s   r5   c               @   s   e Zd ZdZdS )ÚStreamReaderz-Combination of hexlify codec and StreamReaderN)r   r   r    r3   r   r   r   r   r6   m   s   r6   c            	   C   s   t jdttttttd�S )zencodings module APIZhexlify)Únamer   r   ÚincrementalencoderÚincrementaldecoderÚstreamwriterÚstreamreader)ÚcodecsÚ	CodecInfor   r   r!   r4   r5   r6   r   r   r   r   Úgetregentryq   s    r>   )r   )r   )r3   r<   r
   r   Ú	NameErrorÚAttributeErrorÚstrr,   r   r   r   r!   r4   r5   r6   r>   r   r   r   r   Ú<module>   s   



+