U
    [e#                     @   s   d Z ddlZddlZddlmZmZmZmZmZm	Z	m
Z
mZ ddlZddlmZmZmZmZmZmZ ddlZddlZddlZddlmZ ddlmZmZmZmZmZmZmZmZ ddd	d
dddgZ G dd dZ!dS )zG
======================
GeoIP2 Database Reader
======================

    N)AnyAnyStrcastIOListOptionalTypeUnion)	MODE_AUTO	MODE_MMAPMODE_MMAP_EXT	MODE_FILEMODE_MEMORYMODE_FD)	IPAddress)ASNAnonymousIPCityConnectionTypeCountryDomain
EnterpriseISPr
   r   r   r   r   r   Readerc                	   @   s  e Zd ZdZdefeeeej	e
f eee  eddddZd dddZddddd	d
dZeedddZeedddZeedddZeedddZeedddZeedddZeedddZee dddZ!eee"dddZ#ee$e e$e e$e f eeeeeef d d!d"Z%ee$e e$e  e$e e$e e$e f eeeee eeef d d#d$Z&e'j(j)dd%d&Z*ddd'd(Z+dS ))r   a
  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 or file descriptor.
    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.
    N)fileishlocalesmodereturnc                 C   s4   |dkrdg}t ||| _| j j| _|| _dS )a]  Create GeoIP2 Reader.

        :param fileish: A path to the GeoIP2 database or an existing file
          descriptor pointing to the database. Note that a file descriptor
          is only valid when mode is MODE_FD.
        :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_FD - the param passed via fileish is a file descriptor, not a
             path. This mode implies MODE_MEMORY. Pure Python.
          * MODE_AUTO - try MODE_MMAP_EXT, MODE_MMAP, MODE_FILE in that order.
             Default.

        Nen)	maxminddbZopen_database
_db_readermetadatadatabase_type_db_type_locales)selfr   r   r    r&   Q/var/www/html/services/stratfitenv/lib/python3.8/site-packages/geoip2/database.py__init__G   s
    .zReader.__init__)r   c                 C   s   | S Nr&   r%   r&   r&   r'   	__enter__{   s    zReader.__enter__)exc_type	exc_value	tracebackr   c                 C   s   |    d S r)   )close)r%   r,   r-   r.   r&   r&   r'   __exit__~   s    zReader.__exit__)
ip_addressr   c                 C   s   t t| tjjd|S )zGet the Country object for the IP address.

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

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

        r   )r   r   
_model_forgeoip2modelsr%   r1   r&   r&   r'   country   s    	 zReader.countryc                 C   s   t t| tjjd|S )zGet the City object for the IP address.

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

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

        r   )r   r   r2   r3   r4   r5   r&   r&   r'   city   s    zReader.cityc                 C   s   t t| tjjd|S )zGet the AnonymousIP object for the IP address.

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

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

        zGeoIP2-Anonymous-IP)r   r   _flat_model_forr3   r4   r5   r&   r&   r'   anonymous_ip   s      zReader.anonymous_ipc                 C   s   t t| tjjd|S )zGet the ASN object for the IP address.

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

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

        zGeoLite2-ASN)r   r   r8   r3   r4   r5   r&   r&   r'   asn   s     z
Reader.asnc                 C   s   t t| tjjd|S )zGet the ConnectionType object for the IP address.

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

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

        zGeoIP2-Connection-Type)r   r   r8   r3   r4   r5   r&   r&   r'   connection_type   s      zReader.connection_typec                 C   s   t t| tjjd|S )zGet 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   r   r8   r3   r4   r5   r&   r&   r'   domain   s    zReader.domainc                 C   s   t t| tjjd|S )zGet the Enterprise object for the IP address.

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

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

        r   )r   r   r2   r3   r4   r5   r&   r&   r'   
enterprise   s    zReader.enterprisec                 C   s   t t| tjjd|S )zGet 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   r   r8   r3   r4   r5   r&   r&   r'   isp   s     z
Reader.isp)r"   r1   r   c                 C   sn   || j kr2t d d }td| d| j  d| j|\}}|d krftjd| dt	||||fS )N      zThe z  method cannot be used with the z	 databasezThe address z is not in the database.)
r#   inspectstack	TypeErrorr    Zget_with_prefix_lenr3   errorsZAddressNotFoundErrorstr)r%   r"   r1   Zcallerrecord
prefix_lenr&   r&   r'   _get   s    

zReader._get)model_classtypesr1   r   c                 C   s:   |  ||\}}|di }||d< ||d< ||| jdS )Ntraitsr1   rG   )r   )rH   
setdefaultr$   )r%   rI   rJ   r1   rF   rG   rK   r&   r&   r'   r2      s
    zReader._model_forc                 C   s(   |  ||\}}||d< ||d< ||S )Nr1   rG   )rH   )r%   rI   rJ   r1   rF   rG   r&   r&   r'   r8     s    zReader._flat_model_forc                 C   s
   | j  S )zlThe metadata for the open database.

        :returns: :py:class:`maxminddb.reader.Metadata` object
        )r    r!   r*   r&   r&   r'   r!     s    zReader.metadatac                 C   s   | j   dS )zCloses the GeoIP2 database.N)r    r/   r*   r&   r&   r'   r/     s    zReader.close),__name__
__module____qualname____doc__r
   r	   r   intosPathLiker   r   r   rE   r(   r+   r0   r   r   r6   r   r7   r   r9   r   r:   r   r;   r   r<   r   r=   r   r>   r   rH   r   r2   r8   r   readerZMetadatar!   r/   r&   r&   r&   r'   r   0   sF   
4
 	)"rP   rA   rR   typingr   r   r   r   r   r   r   r	   r   r
   r   r   r   r   r   r3   Zgeoip2.modelsZgeoip2.errorsZgeoip2.typesr   r   r   r   r   r   r   r   r   __all__r   r&   r&   r&   r'   <module>   s&   ( 	(