Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
maxminddb
/
__pycache__
/
File Content:
reader.cpython-35.pyc
�jvXn � @ s� d Z d d l m Z y d d l Z Wn e k r@ d Z Yn Xd d l Z d d l m Z m Z d d l m Z m Z m Z m Z d d l m Z d d l m Z d d l m Z Gd d � d e � Z Gd d � d e � Z d S) zo maxminddb.reader ~~~~~~~~~~~~~~~~ This module contains the pure Python database reader and related classes. � )�unicode_literalsN)� byte_from_int�compat_ip_address)� MODE_AUTO� MODE_MMAP� MODE_FILE�MODE_MEMORY)�Decoder)�InvalidDatabaseError)� FileBufferc @ s� e Z d Z d Z d Z d Z d Z e d d � Z d d � Z d d � Z d d � Z d d � Z d d � Z d d � Z d d � Z d S)�Readerz� Instances of this class provide a reader for the MaxMind DB format. IP addresses can be looked up using the ``get`` method. � s ���MaxMind.comNc C s� | t k r t s | t k rp t | d � �= } t j | j � d d t j �| _ | j j � | _ Wd QRXn� | t t f k r� t | � | _ | j j � | _ n^ | t k r� t | d � �( } | j � | _ t | j � | _ Wd QRXn t d j | � � � | j j | j t d | j d � � } | d k rW| j � t d j | � � � | t | j � 7} t | j | � } | j | � \ } } t | � | _ t | j | j j | j � | _ d S)a� Reader for the MaxMind DB file format Arguments: database -- A path to a valid MaxMind DB file such as a GeoIP2 database file. mode -- mode to open the database with. Valid mode are: * MODE_MMAP - read from memory map. * MODE_FILE - read database as standard file. * MODE_MEMORY - load database into memory. * MODE_AUTO - tries MODE_MMAP and then MODE_FILE. Default. �rbr �accessNznUnsupported open mode ({0}). Only MODE_AUTO, MODE_FILE, and MODE_MEMORY are support by the pure Python Reader� i � zCError opening database file ({0}). Is this a valid MaxMind DB file?i ���)r �mmapr �open�filenoZACCESS_READ�_buffer�size�_buffer_sizer r r �read�len� ValueError�format�rfind�_METADATA_START_MARKER�max�closer r �decode�Metadata� _metadata�search_tree_size�_DATA_SECTION_SEPARATOR_SIZE�_decoder)�selfZdatabase�modeZdb_fileZmetadata_startZmetadata_decoder�metadata�_� r+ � /reader.py�__init__$ s8 zReader.__init__c C s | j S)z7Return the metadata associated with the MaxMind DB file)r# )r'