Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/geoip2/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/geoip2/__pycache__/database.cpython-35.pyc



�IX*�@s�dZddlZddlZddlmZmZmZmZmZddlZddl	Zddl
ZGdd�de�ZdS)zG
======================
GeoIP2 Database Reader
======================

�N)�	MODE_AUTO�	MODE_MMAP�
MODE_MMAP_EXT�	MODE_FILE�MODE_MEMORYc@s�eZdZdZdedd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �ZdS)!�Readera�GeoIP2 database Reader object.

    Instances of this class provide a reader for the GeoIP2 database format.
    IP addresses can be looked up using the ``country`` and ``city`` methods.

    The basic API for this class is the same for every database. First, you
    create a reader object, specifying a file name. You then call the method
    corresponding to the specific database, passing it the IP address you want
    to look up.

    If the request succeeds, the method call will return a model class for the
    method you called. This model in turn contains multiple record classes,
    each of which represents part of the data returned by the database. If the
    database does not contain the requested information, the attributes on the
    record class will have a ``None`` value.

    If the address is not in the database, an
    ``geoip2.errors.AddressNotFoundError`` exception will be thrown. If the
    database is corrupt or invalid, a ``maxminddb.InvalidDatabaseError`` will
    be thrown.

NcCs7|dkrdg}tj||�|_||_dS)aFCreate GeoIP2 Reader.

        :param filename: The path to the GeoIP2 database.
        :param locales: This is list of locale codes. This argument will be
          passed on to record classes to use when their name properties are
          called. The default value is ['en'].

          The order of the locales is significant. When a record class has
          multiple names (country, city, etc.), its name property will return
          the name in the first locale that has one.

          Note that the only locale which is always present in the GeoIP2
          data is "en". If you do not include this locale, the name property
          may end up returning None even when the record has an English name.

          Currently, the valid locale codes are:

          * de -- German
          * en -- English names may still include accented characters if that
            is the accepted spelling in English. In other words, English does
            not mean ASCII.
          * es -- Spanish
          * fr -- French
          * ja -- Japanese
          * pt-BR -- Brazilian Portuguese
          * ru -- Russian
          * zh-CN -- Simplified Chinese.
        :param mode: The mode to open the database with. Valid mode are:
          * MODE_MMAP_EXT - use the C extension with memory map.
          * MODE_MMAP - read from memory map. Pure Python.
          * MODE_FILE - read database as standard file. Pure Python.
          * MODE_MEMORY - load database into memory. Pure Python.
          * MODE_AUTO - try MODE_MMAP_EXT, MODE_MMAP, MODE_FILE in that order.
             Default.

        N�en)�	maxminddbZ
open_database�
_db_reader�_locales)�self�filename�locales�mode�r�@/opt/alt/python35/lib/python3.5/site-packages/geoip2/database.py�__init__+s%	zReader.__init__cCs|S)Nr)rrrr�	__enter__UszReader.__enter__cCs|j�dS)N)�close)r�exc_type�	exc_value�	tracebackrrr�__exit__XszReader.__exit__cCs|jtjjd|�S)z�Get the Country object for the IP address.

        :param ip_address: IPv4 or IPv6 address as a string.

        :returns: :py:class:`geoip2.models.Country` object

        �Country)�
_model_for�geoip2�modelsr)r�
ip_addressrrr�country[s	zReader.countrycCs|jtjjd|�S)z�Get the City object for the IP address.

        :param ip_address: IPv4 or IPv6 address as a string.

        :returns: :py:class:`geoip2.models.City` object

        �City)rrrr)rrrrr�cityfszReader.citycCs|jtjjd|�S)z�Get the AnonymousIP object for the IP address.

        :param ip_address: IPv4 or IPv6 address as a string.

        :returns: :py:class:`geoip2.models.AnonymousIP` object

        zGeoIP2-Anonymous-IP)�_flat_model_forrrZAnonymousIP)rrrrr�anonymous_ippszReader.anonymous_ipcCs|jtjjd|�S)z�Get the ConnectionType object for the IP address.

        :param ip_address: IPv4 or IPv6 address as a string.

        :returns: :py:class:`geoip2.models.ConnectionType` object

        zGeoIP2-Connection-Type)r!rrZConnectionType)rrrrr�connection_type{szReader.connection_typecCs|jtjjd|�S)z�Get the Domain object for the IP address.

        :param ip_address: IPv4 or IPv6 address as a string.

        :returns: :py:class:`geoip2.models.Domain` object

        z
GeoIP2-Domain)r!rrZDomain)rrrrr�domain�sz
Reader.domaincCs|jtjjd|�S)z�Get the Enterprise object for the IP address.

        :param ip_address: IPv4 or IPv6 address as a string.

        :returns: :py:class:`geoip2.models.Enterprise` object

        �
Enterprise)rrrr%)rrrrr�
enterprise�szReader.enterprisecCs|jtjjd|�S)z�Get the ISP object for the IP address.

        :param ip_address: IPv4 or IPv6 address as a string.

        :returns: :py:class:`geoip2.models.ISP` object

        z
GeoIP2-ISP)r!rrZISP)rrrrr�isp�sz
Reader.ispcCs�||j�jkrHtj�dd}td||j�jf��|jj|�}|dkr|tjj	d|��|S)N��z1The %s method cannot be used with the %s databasez&The address %s is not in the database.)
�metadata�
database_type�inspect�stack�	TypeErrorr
�getr�errorsZAddressNotFoundError)rr+r�caller�recordrrr�_get�s	
zReader._getcCs;|j||�}||jdi�d<||d|j�S)NZtraitsrr)r3�
setdefaultr)r�model_class�typesrr2rrrr�szReader._model_forcCs&|j||�}||d<||�S)Nr)r3)rr5r6rr2rrrr!�s
zReader._flat_model_forcCs
|jj�S)zlThe metadata for the open database.

        :returns: :py:class:`maxminddb.reader.Metadata` object
        )r
r*)rrrrr*�szReader.metadatacCs|jj�dS)zCloses the GeoIP2 database.N)r
r)rrrrr�szReader.close)�__name__�
__module__�__qualname__�__doc__rrrrrr r"r#r$r&r'r3rr!r*rrrrrrs *
r)
r:r,r	rrrrrrZ
geoip2.modelsZ
geoip2.errors�objectrrrrr�<module>s(