Ë
    øi¯eî"  ã                   óº   — d dl Z d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 ddlmZmZ  eedd«       eed	d
«       eedd«      dœZ G d„ de«      Z G d„ d«      Zy)é    N)Úsettings)ÚValidationError)Úvalidate_ipv46_address)Úto_pathé   )ÚCityÚCountryÚ
GEOIP_PATHÚ
GEOIP_CITYzGeoLite2-City.mmdbÚGEOIP_COUNTRYzGeoLite2-Country.mmdb)r
   r   r   c                   ó   — e Zd Zy)ÚGeoIP2ExceptionN)Ú__name__Ú
__module__Ú__qualname__© ó    úGE:\TRUCKING_PROJECT\Lib\site-packages\django/contrib/gis/geoip2/base.pyr   r      s   „ Ør   r   c                   óØ   — e Zd ZdZdZdZdZdZ eeeeeef«      Z	dZ
dZdZdZdd„Zed	„ «       Zed
„ «       Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zed„ «       Zed„ «       Zy)ÚGeoIP2r   r   é   é   é   Ú Nc                 óX  — || j                   vrt        d|z  «      ‚|xs	 t        d   }|st        d«      ‚t        |«      }|j	                  «       rÇ||xs	 t        d   z  }|j                  «       r6t        j                  j                  t        |«      |¬«      | _
        || _        ||xs	 t        d   z  }|j                  «       r6t        j                  j                  t        |«      |¬«      | _        || _        | j                  st        d|z  «      ‚y|j                  «       rxt        j                  j                  t        |«      |¬«      }|j                  «       j                   }d|v r|| _        || _        yd	|v r|| _
        || _        yt        d
|z  «      ‚t        d«      ‚)aI  
        Initialize the GeoIP object. No parameters are required to use default
        settings. Keyword arguments may be passed in to customize the locations
        of the GeoIP datasets.

        * path: Base directory to where GeoIP data is located or the full path
            to where the city or country data files (*.mmdb) are located.
            Assumes that both the city and country data sets are located in
            this directory; overrides the GEOIP_PATH setting.

        * cache: The cache settings when opening up the GeoIP datasets. May be
            an integer in (0, 1, 2, 4, 8) corresponding to the MODE_AUTO,
            MODE_MMAP_EXT, MODE_MMAP, MODE_FILE, and MODE_MEMORY,
            `GeoIPOptions` C API settings,  respectively. Defaults to 0,
            meaning MODE_AUTO.

        * country: The name of the GeoIP country data file. Defaults to
            'GeoLite2-Country.mmdb'; overrides the GEOIP_COUNTRY setting.

        * city: The name of the GeoIP city data file. Defaults to
            'GeoLite2-City.mmdb'; overrides the GEOIP_CITY setting.
        z Invalid GeoIP caching option: %sr
   zDGeoIP path must be provided via parameter or the GEOIP_PATH setting.r   )Úmoder   z"Could not load a database from %s.r   r	   z(Unable to recognize database edition: %sz-GeoIP path must be a valid file or directory.N)Úcache_optionsr   ÚGEOIP_SETTINGSr   Úis_dirÚis_fileÚgeoip2ÚdatabaseÚReaderÚstrÚ_countryÚ_country_fileÚ_cityÚ
_city_fileÚ_readerÚmetadataÚdatabase_type)	ÚselfÚpathÚcacheÚcountryÚcityÚ
country_dbÚcity_dbÚreaderÚdb_types	            r   Ú__init__zGeoIP2.__init__0   s�  € ð0 ˜×*Ñ*Ñ*Ü!Ð"DÀuÑ"LÓMÐMð Ò3”~ lÑ3ˆÙÜ!ØVóð ô �t‹}ˆØ�;‰;Œ=ð  Ò!K¬N¸?Ñ,KÑLˆJØ×!Ñ!Ô#Ü &§¡× 6Ñ 6´s¸:³ÈUÐ 6Ó S�”Ø%/�Ô"à˜dÒB¤n°\Ñ&BÑCˆGØ�‰Ô Ü#Ÿ_™_×3Ñ3´C¸³LÀuÐ3ÓM�”
Ø")�”Ø—<’<Ü%Ð&JÈTÑ&QÓRÐRð  à�\‰\Œ^ô —_‘_×+Ñ+¬C°«I¸EÐ+ÓBˆFØ—o‘oÓ'×5Ñ5ˆGà˜Ñ à#�”
Ø"&�•Ø˜gÑ%à &�”Ø%)�Õ"ä%Ø>ÀÑHóð ô "Ð"QÓRÐRr   c                 ó6   — | j                   xs | j                  S ©N)r%   r'   ©r,   s    r   r)   zGeoIP2._readerx   s   € à�}‰}Ò* §
¡
Ð*r   c                 ór   — | j                   r| j                   j                  S | j                  j                  S r7   )r%   r/   r'   r0   r8   s    r   Ú_country_or_cityzGeoIP2._country_or_city|   s'   € à�=Š=Ø—=‘=×(Ñ(Ð(à—:‘:—?‘?Ð"r   c                 óR   — | j                   r| j                   j                  «        y y r7   )r)   Úcloser8   s    r   Ú__del__zGeoIP2.__del__ƒ   s   € à�<Š<Ø�L‰L×ÑÕ ð r   c                 óÔ   — | j                   j                  «       }d|j                  ›d|j                  ›d�}d| j                  j
                  || j                  | j                  dœz  S )Nz[vú.ú]zH<%(cls)s %(version)s _country_file="%(country)s", _city_file="%(city)s">)ÚclsÚversionr/   r0   )r)   r*   Úbinary_format_major_versionÚbinary_format_minor_versionÚ	__class__r   r&   r(   )r,   ÚmetarB   s      r   Ú__repr__zGeoIP2.__repr__ˆ   sb   € Ø�|‰|×$Ñ$Ó&‰à×,Ó,Ø×,Ó,ð
ˆð
 Wà—~‘~×.Ñ.Ø"Ø×-Ñ-ØŸ™ñ	ñð	
r   c                 ó`  — t        |t        «      s!t        dt        |«      j                  z  «      ‚|r#| j
                  s| j                  st        d«      ‚|r$| j                  st        d| j                  z  «      ‚	 t        |«       |S # t        $ r t        j                  |«      }Y |S w xY w)z*Check the query and database availability.z)GeoIP query must be a string, not type %sz*Invalid GeoIP country and city data files.z Invalid GeoIP city data file: %s)Ú
isinstancer$   Ú	TypeErrorÚtyper   r%   r'   r   r(   r   r   ÚsocketÚgethostbyname)r,   Úqueryr0   Úcity_or_countrys       r   Ú_check_queryzGeoIP2._check_query˜   s¢   € ô ˜%¤Ô%ÜØ;¼dÀ5»k×>RÑ>RÑRóð ñ
  D§M¢M°T·Z²ZÜ!Ð"NÓOÐOÙ˜$Ÿ*š*Ü!Ð"DÀtÇÁÑ"VÓWÐWð	0Ü" 5Ô)ð ˆøô ò 	0Ü×(Ñ(¨Ó/‰Eàˆð	0ús   Á>B ÂB-Â,B-c                 óp   — | j                  |d¬«      }t        | j                  j                  |«      «      S )zÅ
        Return a dictionary of city information for the given IP address or
        Fully Qualified Domain Name (FQDN). Some information in the dictionary
        may be undefined (None).
        T)r0   )rP   r   r'   r0   ©r,   rN   Ú	enc_querys      r   r0   zGeoIP2.city®   s1   € ð ×%Ñ% e°$Ð%Ó7ˆ	Ü�D—J‘J—O‘O IÓ.Ó/Ð/r   c                 ó*   — | j                  |«      d   S )z9Return the country code for the given IP Address or FQDN.Úcountry_code©r/   ©r,   rN   s     r   rU   zGeoIP2.country_code·   ó   € à�|‰|˜EÓ" >Ñ2Ð2r   c                 ó*   — | j                  |«      d   S )z9Return the country name for the given IP Address or FQDN.Úcountry_namerV   rW   s     r   rZ   zGeoIP2.country_name»   rX   r   c                 ó\   — | j                  |d¬«      }t        | j                  |«      «      S )zä
        Return a dictionary with the country code and name when given an
        IP address or a Fully Qualified Domain Name (FQDN). For example, both
        '24.124.1.80' and 'djangoproject.com' are valid parameters.
        T)rO   )rP   r	   r:   rR   s      r   r/   zGeoIP2.country¿   s/   € ð ×%Ñ% e¸TÐ%ÓBˆ	Ü�t×,Ñ,¨YÓ7Ó8Ð8r   c                 óT   ‡— | j                  |«      Š‰€y t        ˆfd„|D «       «      S )Nc              3   ó(   •K  — | ]	  }‰|   –— Œ y ­wr7   r   )Ú.0ÚoÚcdicts     €r   ú	<genexpr>z GeoIP2.coords.<locals>.<genexpr>Ï   s   øè ø€ Ò4 a˜˜q�Ñ4ùs   ƒ)r0   Útuple)r,   rN   Úorderingr`   s      @r   ÚcoordszGeoIP2.coordsÊ   s*   ø€ Ø—	‘	˜%Ó ˆØˆ=ØäÓ4¨8Ô4Ó4Ð4r   c                 ó$   — | j                  |«      S )z@Return a tuple of the (longitude, latitude) for the given query.©rd   rW   s     r   Úlon_latzGeoIP2.lon_latÑ   s   € à�{‰{˜5Ó!Ð!r   c                 ó&   — | j                  |d«      S )z@Return a tuple of the (latitude, longitude) for the given query.)ÚlatitudeÚ	longituderf   rW   s     r   Úlat_lonzGeoIP2.lat_lonÕ   s   € à�{‰{˜5Ð";Ó<Ð<r   c                 óJ   — | j                  |«      }|rddlm}  ||d¬«      S y)z/Return a GEOS Point object for the given query.r   )ÚPointiæ  )ÚsridN)rg   Údjango.contrib.gis.geosrm   )r,   rN   Úllrm   s       r   ÚgeoszGeoIP2.geosÙ   s&   € à�\‰\˜%Ó ˆÙå5á˜ $Ô'Ð'àr   c                 óp   — | j                   j                  «       }d|j                  ›d|j                  ›d�S )z@Return information about the GeoIP library and databases in use.zGeoIP Library:
	r?   ú
)r)   r*   rC   rD   )r,   rF   s     r   ÚinfozGeoIP2.infoå   s2   € ð �|‰|×$Ñ$Ó&‰à×,Ó,Ø×,Ó,ð
ð 	
r   c                 ó   — t        ||«      S r7   )r   )rA   Ú	full_pathr.   s      r   ÚopenzGeoIP2.openî   s   € ä�i Ó'Ð'r   )Nr   NN)FF))rj   ri   ) r   r   r   Ú	MODE_AUTOÚMODE_MMAP_EXTÚ	MODE_MMAPÚ	MODE_FILEÚMODE_MEMORYÚ	frozensetr   r(   r&   r'   r%   r5   Úpropertyr)   r:   r=   rG   rP   r0   rU   rZ   r/   rd   rg   rk   rq   rt   Úclassmethodrw   r   r   r   r   r      sÜ   „ ð €Ià€Mà€Ià€Ià€KÙØ	�M 9¨i¸ÐEó€Mð
 €JØ€Mð €EØ€HóFSðP ñ+ó ð+ð ñ#ó ð#ò!ò

ó ò,0ò3ò3ò9ó5ò"ò=ò	ð ñ
ó ð
ð ñ(ó ñ(r   r   )rL   Úgeoip2.databaser!   Údjango.confr   Údjango.core.exceptionsr   Údjango.core.validatorsr   Údjango.utils._osr   Ú	resourcesr   r	   Úgetattrr   Ú	Exceptionr   r   r   r   r   ú<module>rˆ      sa   ðÛ ã å  Ý 2Ý 9Ý $ç $ñ ˜( L°$Ó7Ù˜( LÐ2FÓGÙ˜X Ð8OÓPñ€ô	�iô 	÷X(ò X(r   