Ë
    ¹ûàg·$  ã                   óÖ   — d Z ddlZ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 ddlmZ d	gZ	 ddlZd
Zeddgz  Zh d£Z G d„ de«      Z G d„ d«      Zy# e$ r dZY Œ#w xY w)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                   ó   — e Zd Zy)r   N)Ú__name__Ú
__module__Ú__qualname__© ó    úW/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/django/contrib/gis/geoip2.pyr   r   1   s   „ Ø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d„Zd„ Zd	„ Zed
„ «       Zed„ «       Zed„ «       Zddœd„Zd„ Zd„ Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zed„ «       Zy)r
   r   é   é   é   é   Nc                 óö  — || j                   vrt        d|z  «      ‚|xs t        t        dd«      }|xs t        t        dd«      }|xs t        t        dd«      }|st        d«      ‚t	        |«      }|||z  ||z  fD ]A  }|j                  «       sŒ|| _        t        j                  j                  ||¬	«      | _
         n t        d
«      ‚| j                  j                  }|t        vrt        d|› �«      ‚y)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: %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Úcityr,   s         r   Ú__init__zGeoIP2.__init__H   s  € ð. ˜×*Ñ*Ñ*Ü!Ð"DÀuÑ"LÓMÐMàÒ<”wœx¨°tÓ<ˆØÒL”wœx¨Ð7KÓLˆØÒXœW¤X¨Ð@WÓXˆáÜ!ØVóð ô �t‹}ˆð ˜4 $™;¨¨w©Ð7ò 	ˆDØ�|‰|�~Ø!�”
Ü%Ÿ™×5Ñ5°dÀÐ5ÓG�”Ùð		ô "ØRóð ð Ÿ™×4Ñ4ˆØÔ 8Ñ8Ü!Ð$GÈÀÐ"WÓXÐXð 9r   c                 óR   — | j                   r| j                   j                  «        y y ©N)r*   Úclose©r.   s    r   Ú__del__zGeoIP2.__del__|   s   € à�<Š<Ø�L‰L×ÑÕ ð r   c                 ó¦   — | j                   }d|j                  › d|j                  › �}d| j                  j                  › d|› d| j
                  › d�S )NÚvú.ú<z [z	] _path='z'>)r+   Úbinary_format_major_versionÚbinary_format_minor_versionÚ	__class__r   r&   )r.   ÚmÚversions      r   Ú__repr__zGeoIP2.__repr__�   sU   € Ø�N‰NˆØ�a×3Ñ3Ð4°A°a×6SÑ6SÐ5TÐUˆØ�4—>‘>×*Ñ*Ð+¨2¨g¨Y°iÀÇ
Á
¸|È2ÐNÐNr   c                 ó6   — | j                   j                  «       S r5   )r*   Úmetadatar7   s    r   r+   zGeoIP2._metadata†   s   € à�|‰|×$Ñ$Ó&Ð&r   c                 ó2   — d| j                   j                  v S )NÚCity©r+   r,   r7   s    r   Úis_cityzGeoIP2.is_cityŠ   s   € à˜Ÿ™×5Ñ5Ð5Ð5r   c                 ó2   — d| j                   j                  v S )NÚCountryrG   r7   s    r   Ú
is_countryzGeoIP2.is_countryŽ   s   € à˜DŸN™N×8Ñ8Ð8Ð8r   F©Úrequire_cityc                óî  — t        |t        t        j                  t        j                  f«      s!t        dt        |«      j                  z  «      ‚|r$| j                  st        d| j                  › �«      ‚t        |t        «      r	 t        |«       | j                  r| j                  j                   n| j                  j"                  } ||«      S # t        $ r t        j                  |«      }Y Œ`w xY w)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   rH   r   r&   r   r   ÚsocketÚgethostbynamer*   r2   r1   )r.   ÚqueryrM   Úfunctions       r   Ú_queryzGeoIP2._query’   sË   € Ü˜%¤#¤y×'<Ñ'<¼i×>SÑ>SÐ!TÔUÜð+Ü-1°%«[×-AÑ-AñBóð ñ
  §¢Ü!Ð$BÀ4Ç:Á:À,Ð"OÓPÐPä�eœSÔ!ð4Ü& uÔ-ð
 )-¯ª�4—<‘<×$Ò$¸$¿,¹,×:NÑ:NˆÙ˜‹Ðøô #ò 4ä×,Ñ,¨UÓ3’ð4ús   ÂC ÃC4Ã3C4c                 ó$  — | j                  |d¬«      }|j                  r|j                  d   nd}i d|j                  j                  “d|j                  j
                  “d|j                  j                  “d|j                  j
                  “d	|j                  j                  “d
|j                  j
                  “d|j                  j                  “d|j                  j                  “d|j                  j                  “d|j                  j                  “d|j                  j                  “d|r|j                  nd“d|r|j
                  nd“d|j                  j                  “d|j                  j                  “d|r|j                  “S d“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).
        TrL   r   NÚaccuracy_radiusr2   Ú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)rZ   ÚsubdivisionsÚlocationr\   r2   ÚnameÚ	continentÚcoder1   Úiso_codera   rb   rc   rd   Úpostalrh   )r.   rX   Úresponserj   s       r   r2   zGeoIP2.city¦   s³  € ð —;‘;˜u°4�;Ó8ˆØ-5×-BÒ-B�×&Ñ& qÒ)Èˆð
Ø˜x×0Ñ0×@Ñ@ð
à�H—M‘M×&Ñ&ð
ð ˜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Ÿ?™?×/Ñ/ð
ð ©f˜6Ÿ?š?¸$ð
ð ©&˜6Ÿ;š;°dð
ð ˜×*Ñ*×4Ñ4ð
ð  ˜×)Ñ)×4Ñ4ð!
ð" ©�f—o‘oð#
ð 	
ð" 6:ð#
ð 	
r   c                 ó*   — | j                  |«      d   S )z9Return the country code for the given IP Address or FQDN.r_   ©r1   ©r.   rX   s     r   r_   zGeoIP2.country_codeÂ   ó   € à�|‰|˜EÓ" >Ñ2Ð2r   c                 ó*   — | j                  |«      d   S )z9Return the country name for the given IP Address or FQDN.r`   rt   ru   s     r   r`   zGeoIP2.country_nameÆ   rv   r   c                 ó   — | j                  |d¬«      }|j                  j                  |j                  j                  |j                  j
                  |j                  j                  |j                  j                  dœ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.
        FrL   )r]   r^   r_   r`   ra   )rZ   rn   ro   rm   r1   rp   ra   )r.   rX   rr   s      r   r1   zGeoIP2.countryÊ   sk   € ð —;‘;˜u°5�;Ó9ˆà&×0Ñ0×5Ñ5Ø&×0Ñ0×5Ñ5Ø$×,Ñ,×5Ñ5Ø$×,Ñ,×1Ñ1Ø$,×$4Ñ$4×$IÑ$Iñ
ð 	
r   c                 ó†   ‡— t        j                  dt        d¬«       | j                  |«      Št	        ˆfd„|D «       «      S )Nz<GeoIP2.coords() is deprecated. Use GeoIP2.lon_lat() instead.r   ©Ú
stacklevelc              3   ó(   •K  — | ]	  }‰|   –— Œ y ­wr5   r   )Ú.0ÚoÚdatas     €r   ú	<genexpr>z GeoIP2.coords.<locals>.<genexpr>à   s   øè ø€ Ò/ �T˜!•WÑ/ùs   ƒ)ÚwarningsÚwarnr   r2   Útuple)r.   rX   Úorderingr   s      @r   ÚcoordszGeoIP2.coordsÙ   s9   ø€ Ü�‰ØJÜ$Øõ	
ð
 �y‰y˜ÓˆÜÓ/ hÔ/Ó/Ð/r   c                 ó8   — | j                  |«      }|d   |d   fS )z@Return a tuple of the (longitude, latitude) for the given query.rc   rb   ©r2   ©r.   rX   r   s      r   Úlon_latzGeoIP2.lon_latâ   s%   € à�y‰y˜ÓˆØ�KÑ  $ zÑ"2Ð2Ð2r   c                 ó8   — | j                  |«      }|d   |d   fS )z@Return a tuple of the (latitude, longitude) for the given query.rb   rc   r‡   rˆ   s      r   Úlat_lonzGeoIP2.lat_lonç   s%   € à�y‰y˜ÓˆØ�JÑ  kÑ!2Ð2Ð2r   c                 ó@   — ddl m}  || j                  |«      d¬«      S )z/Return a GEOS Point object for the given query.r   )ÚPointiæ  )Úsrid)Údjango.contrib.gis.geosr�   r‰   )r.   rX   r�   s      r   ÚgeoszGeoIP2.geosì   s   € õ 	2á�T—\‘\ %Ó(¨tÔ4Ð4r   c                 óR   — t        j                  dt        d¬«       t        ||«      S )Nz2GeoIP2.open() is deprecated. Use GeoIP2() instead.r   rz   )r�   r‚   r   r
   )ÚclsÚ	full_pathr0   s      r   ÚopenzGeoIP2.openó   s&   € ä�‰Ø@Ü$Øõ	
ô
 �i Ó'Ð'r   )Nr   NN))rc   rb   )r   r   r   Ú	MODE_AUTOÚMODE_MMAP_EXTÚ	MODE_MMAPÚ	MODE_FILEÚMODE_MEMORYÚ	frozensetr#   r&   r*   r3   r8   rB   r   r+   rH   rK   rZ   r2   r_   r`   r1   r…   r‰   r‹   r�   Úclassmethodr”   r   r   r   r
   r
   5   sÕ   „ ð €Ià€Mà€Ià€Ià€KÙØ	�M 9¨i¸ÐEó€Mð €EØ€Gó2Yòh!ò
Oð
 ñ'ó ð'ð ñ6ó ð6ð ñ9ó ð9ð -2ô ò(
ò83ò3ò
ó0ò3ò
3ò
5ð ñ(ó ñ(r   )Ú__doc__rQ   rV   r�   Údjango.confr   Údjango.core.exceptionsr   Údjango.core.validatorsr   Údjango.utils._osr   Údjango.utils.deprecationr   Údjango.utils.functionalr   Ú__all__Úgeoip2.databaser'   r	   ÚImportErrorr-   Ú	Exceptionr   r
   r   r   r   ú<module>r§      sƒ   ðñó Û Û å  Ý 2Ý 9Ý $Ý =Ý 3àˆ.€ð-Ûð €JØ�Ð+Ð,Ñ,€Gò
Ð ô	�iô 	÷E(ò E(øð/ ò Ø‚Jðús   ·A ÁA(Á'A(