
    h$                         S r SSKr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  SSKJr  S	/r SSKrS
r\SS/-  r1 Skr " S S\5      r " S S5      rg! \ a    Sr N$f = f)aU  
This module houses the GeoIP2 object, a wrapper for the MaxMind GeoIP2(R)
Python API (https://geoip2.readthedocs.io/). This is an alternative to the
Python GeoIP2 interface provided by MaxMind.

GeoIP(R) is a registered trademark of MaxMind, Inc.

For IP-based geolocation, this module requires the GeoLite2 Country and City
datasets, in binary format (CSV will not work!). The datasets may be
downloaded from MaxMind at https://dev.maxmind.com/geoip/geoip2/geolite2/.
Grab GeoLite2-Country.mmdb.gz and GeoLite2-City.mmdb.gz, and unzip them in the
directory corresponding to settings.GEOIP_PATH.
    N)settings)ValidationError)validate_ipv46_address)to_path)RemovedInDjango60Warning)cached_property
HAS_GEOIP2TGeoIP2GeoIP2ExceptionF>   GeoIP2-CityGeoLite2-CityDBIP-City-LiteGeoIP2-CountryGeoLite2-CountryDBIP-Country-Litec                       \ rS rSrSrg)r   1    N)__name__
__module____qualname____firstlineno____static_attributes__r       K/var/www/html/env/lib/python3.13/site-packages/django/contrib/gis/geoip2.pyr   r   1   s    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S jrS	 rS
 r\S 5       r\S 5       r\S 5       rS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rg)r
   5   r               Nc                 $   X R                   ;  a  [        SU-  5      eU=(       d    [        [        SS5      nU=(       d    [        [        SS5      nU=(       d    [        [        SS5      nU(       d  [        S5      e[	        U5      nXU-  X-  4 HB  nUR                  5       (       d  M  Xl        [        R                  R                  XS	9U l
          O   [        S
5      eU R                  R                  nU[        ;  a  [        SU 35      eg)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: %s
GEOIP_PATHN
GEOIP_CITYzGeoLite2-City.mmdbGEOIP_COUNTRYzGeoLite2-Country.mmdbzDGeoIP path must be provided via parameter or the GEOIP_PATH setting.)modez@Path must be a valid database or directory containing databases.z#Unable to handle database edition: )cache_optionsr   getattrr   r   is_file_pathgeoip2databaseReader_reader	_metadatadatabase_typeSUPPORTED_DATABASE_TYPES)selfpathcachecountrycityr0   s         r   __init__GeoIP2.__init__H   s   . ***!"Du"LMM<wxt<Lwx7KLXWX@WX!V  t} $;7D||~~!
%55d5G	 8 "R  44 88!$G"WXX 9r   c                 \    U R                   (       a  U R                   R                  5         g g N)r.   closer2   s    r   __del__GeoIP2.__del__|   s    <<LL  r   c                     U R                   nSUR                   SUR                   3nSU R                  R                   SU SU R
                   S3$ )Nv.<z [z	] _path='z'>)r/   binary_format_major_versionbinary_format_minor_version	__class__r   r*   )r2   mversions      r   __repr__GeoIP2.__repr__   sU    NNa334Aa6S6S5TU4>>**+2gYi

|2NNr   c                 6    U R                   R                  5       $ r:   )r.   metadatar<   s    r   r/   GeoIP2._metadata   s    ||$$&&r   c                 4    SU R                   R                  ;   $ )NCityr/   r0   r<   s    r   is_cityGeoIP2.is_city   s    5555r   c                 4    SU R                   R                  ;   $ )NCountryrO   r<   s    r   
is_countryGeoIP2.is_country   s    DNN8888r   Frequire_cityc                $   [        U[        [        R                  [        R                  45      (       d!  [        S[        U5      R                  -  5      eU(       a)  U R                  (       d  [        SU R                   35      e[        U[        5      (       a   [        U5        U R                  (       a  U R                  R                   OU R                  R"                  nU" U5      $ ! [         a    [        R                  " U5      n Ngf = f)NzSGeoIP query must be a string or instance of IPv4Address or IPv6Address, not type %szInvalid GeoIP city data file: )
isinstancestr	ipaddressIPv4AddressIPv6Address	TypeErrortyper   rP   r   r*   r   r   socketgethostbynamer.   r6   r5   )r2   queryrW   functions       r   _queryGeoIP2._query   s    %#y'<'<i>S>S!TUU+-1%[-A-AB 
 !$B4::,"OPPeS!!4&u-
 )-4<<$$$,,:N:N # 4,,U34s   C, , DDc                 F   U R                  USS9nUR                  (       a  UR                  S   OSn0 SUR                  R                  _SUR                  R
                  _SUR                  R                  _SUR                  R
                  _S	UR                  R                  _S
UR                  R
                  _SUR                  R                  _SUR                  R                  _SUR                  R                  _SUR                  R                  _SUR                  R                  _SU(       a  UR                  OS_SU(       a  UR
                  OS_SUR                  R                  _SUR                  R                  _SU(       a  UR                  _$ 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).
TrV   r   Naccuracy_radiusr6   continent_codecontinent_namecountry_codecountry_nameis_in_european_unionlatitude	longitude
metro_codepostal_coderegion_coderegion_name	time_zonedma_coderegion)rd   subdivisionslocationrg   r6   name	continentcoder5   iso_coderl   rm   rn   ro   postalrs   )r2   rb   responseru   s       r   r6   GeoIP2.city   s    ;;u4;8-5-B-B&&q)
x00@@
HMM&&
 h0055
 h0055	

 H,,55
 H,,11
 #H$4$4$I$I
 ))22
 **44
 (++66
 8??//
 f6??$
 &6;;d
 **44
  ))44!
" foo#
 	
" 6:#
 	
r   c                 *    U R                  U5      S   $ )z9Return the country code for the given IP Address or FQDN.rj   r5   r2   rb   s     r   rj   GeoIP2.country_code       ||E">22r   c                 *    U R                  U5      S   $ )z9Return the country name for the given IP Address or FQDN.rk   r   r   s     r   rk   GeoIP2.country_name   r   r   c                     U R                  USS9nUR                  R                  UR                  R                  UR                  R
                  UR                  R                  UR                  R                  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.
FrV   )rh   ri   rj   rk   rl   )rd   ry   rz   rx   r5   r{   rl   )r2   rb   r}   s      r   r5   GeoIP2.country   sk     ;;u5;9&0055&0055$,,55$,,11$,$4$4$I$I
 	
r   c                    ^ [         R                  " S[        SS9  U R                  U5      m[	        U4S jU 5       5      $ )Nz<GeoIP2.coords() is deprecated. Use GeoIP2.lon_lat() instead.r   
stacklevelc              3   .   >#    U  H
  nTU   v   M     g 7fr:   r   ).0odatas     r   	<genexpr> GeoIP2.coords.<locals>.<genexpr>   s     /hT!Whs   )warningswarnr   r6   tuple)r2   rb   orderingr   s      @r   coordsGeoIP2.coords   s9    J$	

 yy/h///r   c                 8    U R                  U5      nUS   US   4$ )z@Return a tuple of the (longitude, latitude) for the given query.rn   rm   r6   r2   rb   r   s      r   lon_latGeoIP2.lon_lat   s%    yyK $z"222r   c                 8    U R                  U5      nUS   US   4$ )z@Return a tuple of the (latitude, longitude) for the given query.rm   rn   r   r   s      r   lat_lonGeoIP2.lat_lon   s%    yyJk!222r   c                 :    SSK Jn  U" U R                  U5      SS9$ )z/Return a GEOS Point object for the given query.r   )Pointi  )srid)django.contrib.gis.geosr   r   )r2   rb   r   s      r   geosGeoIP2.geos   s     	2T\\%(t44r   c                 L    [         R                  " S[        SS9  [        X5      $ )Nz2GeoIP2.open() is deprecated. Use GeoIP2() instead.r   r   )r   r   r   r
   )cls	full_pathr4   s      r   openGeoIP2.open   s$    @$	

 i''r   )r*   r.   )Nr   NN))rn   rm   ) r   r   r   r   	MODE_AUTOMODE_MMAP_EXT	MODE_MMAP	MODE_FILEMODE_MEMORY	frozensetr'   r*   r.   r7   r=   rH   r   r/   rP   rT   rd   r6   rj   rk   r5   r   r   r   r   classmethodr   r   r   r   r   r
   r
   5   s     IMIIK	M9iEM EG2Yh!
O
 ' ' 6 6 9 9 -2 (
833
03
3
5 ( (r   )__doc__r[   r`   r   django.confr   django.core.exceptionsr   django.core.validatorsr   django.utils._osr   django.utils.deprecationr   django.utils.functionalr   __all__geoip2.databaser+   r	   ImportErrorr1   	Exceptionr   r
   r   r   r   <module>r      s         2 9 $ = 3.- J+,,G
 	i 	E( E(/  Js   A A)(A)