ok

Mini Shell

Direktori : /opt/alt/python38/lib64/python3.8/site-packages/maxminddb/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/site-packages/maxminddb/__pycache__/decoder.cpython-38.pyc

U

 ��^��@sLdZddlmZddlZddlmZmZmZddlm	Z	Gdd�de
�ZdS)zl
maxminddb.decoder
~~~~~~~~~~~~~~~~~

This package contains code for decoding the MaxMind DB data section.

�)�unicode_literalsN)�
byte_from_int�
int_from_byte�int_from_bytes��InvalidDatabaseErrorc@s�eZdZdZd$dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zeeeee
e
ee
e
e
eee	d�
Zdd�Zdd�Zdd �Zd!d"�Zd#S)%�Decoderz.Decoder for the data section of the MaxMind DBrFcCs||_||_||_dS)aCreated a Decoder for a MaxMind DB

        Arguments:
        database_buffer -- an mmap'd MaxMind DB file.
        pointer_base -- the base number to use when decoding a pointer
        pointer_test -- used for internal unit testing of pointer code
        N)�
_pointer_test�_buffer�
_pointer_base)�selfZdatabase_bufferZpointer_baseZpointer_test�r
�/decoder.py�__init__szDecoder.__init__cCs2g}t|�D]}|�|�\}}|�|�q||fS�N)�range�decode�append)r�size�offsetZarray�_�valuer
r
r�
_decode_arrays
zDecoder._decode_arraycCs|dk|fS)Nrr
)rrrr
r
r�_decode_boolean&szDecoder._decode_booleancCs||}|j||�|fSr)r
�rrr�
new_offsetr
r
r�
_decode_bytes)szDecoder._decode_bytescCs8|�|d�||}|j||�}t�d|�\}||fS)N�s!d��_verify_sizer
�struct�unpack�rrrrZpacked_bytesrr
r
r�_decode_double-s
zDecoder._decode_doublecCs8|�|d�||}|j||�}t�d|�\}||fS)N�s!frr"r
r
r�
_decode_float4s
zDecoder._decode_floatcCsP|dkrd|fS||}|j||�}|dkr:|�dd�}t�d|�\}||fS)Nrr$�s!i)r
�rjustr r!r"r
r
r�
_decode_int32;szDecoder._decode_int32cCs>i}t|�D](}|�|�\}}|�|�\}}|||<q||fSr)rr)rrrZ	containerr�keyrr
r
r�_decode_mapFs
zDecoder._decode_mapc	Cs�|d?d}|j|||�}||}|dkrVt|d@�|}t�d|�d|j}n�|dkr�dt|d@�|}t�d|�dd	|j}nJ|dkr�t|d@�|}t�d|�dd
|j}nt�d|�d|j}|jr�||fS|�|�\}}||fS)N����!Hr�r&�!Iii)r
rr r!rr	r)	rrrZpointer_sizeZbufrZpointerrrr
r
r�_decode_pointerNs"zDecoder._decode_pointercCs"||}|j||�}t|�|fSr)r
r)rrrrZ
uint_bytesr
r
r�_decode_uinteszDecoder._decode_uintcCs ||}|j||��d�|fS)Nzutf-8)r
rrr
r
r�_decode_utf8_stringjszDecoder._decode_utf8_string)
r,r/r+r$��r-r�	�
���cCs�|d}t|j|�}|d?}|s0|�|�\}}z|j|}Wn$tk
rbtdj|d���YnX|�|||�\}}||||�S)z�Decode a section of the data section starting at offset

        Arguments:
        offset -- the location of the data structure to decode
        r,r4z+Unexpected type number ({type}) encountered��type)rr
�_read_extended�
_type_decoder�KeyErrorr�format�_size_from_ctrl_byte)rrr�	ctrl_byte�type_num�decoderrr
r
rr~s
�
zDecoder.decodecCs:t|j|�}|d}|dkr.tdj|d���||dfS)Nr-zeSomething went horribly wrong in the decoder. An extended type resolved to a type number < 8 ({type})r;r,)rr
rr@)rrZ	next_byterCr
r
rr=�s��zDecoder._read_extendedcCs||krtd��dS)NzXThe MaxMind DB file's data section contains bad data (unknown data type or corrupt data)r)rZexpected�actualr
r
rr�s�zDecoder._verify_sizecCs�|d@}|dks|dkr ||fS|dkrFdt|j|�}||dfS|dkr�|d}|j||�}dt�d|�d}||fS|d	}|j||�}t�d
d|�dd}||fS)
N�r,��r/ir.rr+r0r&i)rr
r r!)rrBrrCrrZ
size_bytesr
r
rrA�szDecoder._size_from_ctrl_byteN)rF)�__name__�
__module__�__qualname__�__doc__rrrrr#r%r(r*r1r2r3r>rr=rrAr
r
r
rrs<
�r)rLZ
__future__rr Zmaxminddb.compatrrrZmaxminddb.errorsr�objectrr
r
r
r�<module>s


Zerion Mini Shell 1.0