
    (ph"                         S SK r S SKrS SKJr  S SKJr  S SKJr  S SK	J
r
  SSKJrJr  \" \SS5      \" \S	S
5      \" \SS5      S.r " S S\5      r " S S5      rg)    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                       \ rS rSrSrg)GeoIP2Exception    N)__name__
__module____qualname____firstlineno____static_attributes__r       Q/var/www/html/venv/lib/python3.13/site-packages/django/contrib/gis/geoip2/base.pyr   r      s    r   r   c                       \ rS rSrSrSrSrSrSr\	" \\\\\45      r
SrSrSrSrSS	 jr\S
 5       r\S 5       rS rS rSS jrS rS rS rS rSS jrS rS rS r\S 5       r\S 5       r Sr!g)GeoIP2   r   r             Nc                    X R                   ;  a  [        SU-  5      eU=(       d	    [        S   nU(       d  [        S5      e[        U5      nUR	                  5       (       a  X=(       d	    [        S   -  nUR                  5       (       a2  [        R                  R                  [        U5      US9U l
        XPl        X=(       d	    [        S   -  nUR                  5       (       a2  [        R                  R                  [        U5      US9U l        X`l        U R                  (       d  [        SU-  5      egUR                  5       (       au  [        R                  R                  [        U5      US9nUR                  5       R                   nSU;   a  Xpl        Xl        gS	U;   a  Xpl
        Xl        g[        S
U-  5      e[        S5      e)a  
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__GeoIP2.__init__0   s   0 ***!"Du"LMM 3~l3!V  t};;== !KN?,KLJ!!## & 6 6s:U 6 S%/"Bn\&BCG  #__33CLu3M
")<<%&JT&QRR  \\^^ __++CIE+BFoo'55G #
"&g% &%)"%>H  ""QRRr   c                 @    U R                   =(       d    U R                  $ N)r)   r+   r0   s    r   r-   GeoIP2._readerx   s    }}*

*r   c                 |    U R                   (       a  U R                   R                  $ U R                  R                  $ r<   )r)   r3   r+   r4   r=   s    r   _country_or_cityGeoIP2._country_or_city|   s'    ====(((::??"r   c                 \    U R                   (       a  U R                   R                  5         g g r<   )r-   closer=   s    r   __del__GeoIP2.__del__   s    <<LL  r   c                     U R                   R                  5       nSUR                  < SUR                  < S3nSU R                  R
                  UU R                  U R                  S.-  $ )Nz[v.]zH<%(cls)s %(version)s _country_file="%(country)s", _city_file="%(city)s">)clsversionr3   r4   )r-   r.   binary_format_major_versionbinary_format_minor_version	__class__r   r*   r,   )r0   metarJ   s      r   __repr__GeoIP2.__repr__   sb    ||$$&,,,,

 W~~.."--		
r   c                    [        U[        5      (       d!  [        S[        U5      R                  -  5      eU(       a-  U R
                  (       d  U R                  (       d  [        S5      eU(       a)  U R                  (       d  [        SU R                  -  5      e [        U5        U$ ! [         a    [        R                  " U5      n U$ f = f)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)r0   queryr4   city_or_countrys       r   _check_queryGeoIP2._check_query   s     %%%;d5k>R>RR 
 DMMTZZ!"NOO$**!"Dt"VWW	0"5)   	0((/E	0s   B) ) CCc                 j    U R                  USS9n[        U R                  R                  U5      5      $ )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)r4   )rY   r   r+   r4   r0   rW   	enc_querys      r   r4   GeoIP2.city   s1     %%e$%7	DJJOOI.//r   c                 *    U R                  U5      S   $ )z9Return the country code for the given IP Address or FQDN.country_coder3   r0   rW   s     r   r`   GeoIP2.country_code       ||E">22r   c                 *    U R                  U5      S   $ )z9Return the country name for the given IP Address or FQDN.country_namera   rb   s     r   rf   GeoIP2.country_name   rd   r   c                 V    U R                  USS9n[        U R                  U5      5      $ )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)rX   )rY   r	   r@   r\   s      r   r3   GeoIP2.country   s/     %%eT%B	t,,Y788r   c                 X   ^ U R                  U5      mTc  g [        U4S jU 5       5      $ )Nc              3   .   >#    U  H
  nTU   v   M     g 7fr<   r   ).0ocdicts     r   	<genexpr> GeoIP2.coords.<locals>.<genexpr>   s     48aq8s   )r4   tuple)r0   rW   orderingrn   s      @r   coordsGeoIP2.coords   s*    		% =48444r   c                 $    U R                  U5      $ )z@Return a tuple of the (longitude, latitude) for the given query.rs   rb   s     r   lon_latGeoIP2.lon_lat   s    {{5!!r   c                 &    U R                  US5      $ )z@Return a tuple of the (latitude, longitude) for the given query.)latitude	longituderv   rb   s     r   lat_lonGeoIP2.lat_lon   s    {{5";<<r   c                 N    U R                  U5      nU(       a  SSKJn  U" USS9$ g)z/Return a GEOS Point object for the given query.r   )Pointi  )sridN)rw   django.contrib.gis.geosr   )r0   rW   llr   s       r   geosGeoIP2.geos   s&    \\% 5$''r   c                 t    U R                   R                  5       nSUR                  < SUR                  < S3$ )z@Return information about the GeoIP library and databases in use.zGeoIP Library:
	rG   
)r-   r.   rK   rL   )r0   rN   s     r   infoGeoIP2.info   s2     ||$$&,,,,
 	
r   c                     [        X5      $ r<   )r   )rI   	full_pathr2   s      r   openGeoIP2.open   s    i''r   )r+   r,   r)   r*   )Nr   NN)FF))r{   rz   )"r   r   r   r   	MODE_AUTOMODE_MMAP_EXT	MODE_MMAP	MODE_FILEMODE_MEMORY	frozensetr!   r,   r*   r+   r)   r9   propertyr-   r@   rD   rO   rY   r4   r`   rf   r3   rs   rw   r|   r   r   classmethodr   r   r   r   r   r   r      s     IMIIK	M9iEM
 JM EHFSP + + # #!

 ,03395"=	 
 
 ( (r   r   )rU   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(L2FGX8OP	i 	X( X(r   