§
    Ÿj·$  ã                   óæ   — 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n# e$ r dZY nw xY wh d£Z G d„ de¦  «        Z G d„ d¦  «        ZdS )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dS )r   N)Ú__name__Ú
__module__Ú__qualname__© ó    úf/var/www/finuniver-perm.ru/html/student/venv/lib/python3.11/site-packages/django/contrib/gis/geoip2.pyr   r   1   s   € € € € € Ø€Dr   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dS )r
   r   é   é   é   é   Nc                 ó  — || j         vrt          d|z  ¦  «        ‚|pt          t          dd¦  «        }|pt          t          dd¦  «        }|pt          t          dd¦  «        }|st          d¦  «        ‚t	          |¦  «        }|||z  ||z  fD ]E}|                     ¦   «         r/|| _        t          j         	                    ||¬	¦  «        | _
         nŒFt          d
¦  «        ‚| j        j        }|t          vrt          d|› �¦  «        ‚dS )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ÐMàÐ<•w�x¨°tÑ<Ô<ˆØÐL•w�x¨Ð7KÑLÔLˆØÐX�W¥X¨Ð@WÑXÔXˆàð 	Ý!ØVñô ð õ �t‰}Œ}ˆð ˜4 $™;¨¨w©Ð7ð 	ð 	ˆDØ�|Š|‰~Œ~ð Ø!�”
Ý%œ×5Ò5°dÀÐ5ÑGÔG�”Ø�ðõ
 "ØRñô ð ð œÔ4ˆØÕ 8Ð8Ð8Ý!Ð"WÈÐ"WÐ"WÑXÔXÐXð 9Ð8r   c                 óJ   — | j         r| j                              ¦   «          d S d S ©N)r*   Úclose©r.   s    r   Ú__del__zGeoIP2.__del__|   s0   € àŒ<ð 	!ØŒL×ÒÑ Ô Ð Ð Ð ð	!ð 	!r   c                 ój   — | 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__�   sL   € ØŒNˆØU�aÔ3ÐUÐU°aÔ6SÐUÐUˆØN�4”>Ô*ÐNÐN¨gÐNÐNÀÄ
ÐNÐNÐNÐNr   c                 ó4   — | j                              ¦   «         S r5   )r*   Úmetadatar7   s    r   r+   zGeoIP2._metadata†   s   € àŒ|×$Ò$Ñ&Ô&Ð&r   c                 ó   — d| j         j        v S )NÚCity©r+   r,   r7   s    r   Úis_cityzGeoIP2.is_cityŠ   s   € à˜œÔ5Ð5Ð5r   c                 ó   — d| j         j        v S )NÚCountryrG   r7   s    r   Ú
is_countryzGeoIP2.is_countryŽ   s   € à˜DœNÔ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          ¦  «        r5	 t          |¦  «         n$# t          $ r t          j        |¦  «        }Y nw xY w| j        r| j        j        n| j        j        } ||¦  «        S )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Ð!TÑUÔUð 	Ýð+Ý-1°%©[¬[Ô-AñBñô ð ð
 ð 	Q ¤ð 	QÝ!Ð"OÀ4Ä:Ð"OÐ"OÑPÔPÐPå�e�SÑ!Ô!ð 	4ð4Ý& uÑ-Ô-Ð-Ð-øÝ"ð 4ð 4ð 4åÔ,¨UÑ3Ô3���ð4øøøð )-¬ÐN�4”<Ô$Ð$¸$¼,Ô:NˆØˆx˜‰ŒÐs   ÂB ÂB8Â7B8c                 óú  — |                       |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	        n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¦   sf  € ð —;’;˜u°4�;Ñ8Ô8ˆØ-5Ô-BÐL�Ô& qÔ)Ð)Èˆð
Ø˜xÔ0Ô@ð
à�H”MÔ&ð
ð ˜hÔ0Ô5ð
ð ˜hÔ0Ô5ð	
ð
 ˜HÔ,Ô5ð
ð ˜HÔ,Ô1ð
ð # HÔ$4Ô$Ið
ð ˜Ô)Ô2ð
ð ˜Ô*Ô4ð
ð ˜(Ô+Ô6ð
ð ˜8œ?Ô/ð
ð ¨fÐ>˜6œ?˜?¸$ð
ð ¨&Ð:˜6œ;˜;°dð
ð ˜Ô*Ô4ð
ð  ˜Ô)Ô4ð!
ð" ¨Ð9�f”o�o°Tð#
ð 	
r   c                 ó8   — |                       |¦  «        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                 ó8   — |                       |¦  «        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                 ó¤   — |                       |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Ê   sU   € ð —;’;˜u°5�;Ñ9Ô9ˆà&Ô0Ô5Ø&Ô0Ô5Ø$Ô,Ô5Ø$Ô,Ô1Ø$,Ô$4Ô$Ið
ð 
ð 	
r   ©rc   rb   c                 óœ   ‡— t          j        dt          d¬¦  «         |                      |¦  «        Št	          ˆfd„|D ¦   «         ¦  «        S )Nz<GeoIP2.coords() is deprecated. Use GeoIP2.lon_lat() instead.r   ©Ú
stacklevelc              3   ó(   •K  — | ]}‰|         V — Œd S r5   r   )Ú.0ÚoÚdatas     €r   ú	<genexpr>z GeoIP2.coords.<locals>.<genexpr>à   s'   øè è € Ð/Ð/ �T˜!”WÐ/Ð/Ð/Ð/Ð/Ð/r   )ÚwarningsÚwarnr   r2   Útuple)r.   rX   Úorderingr€   s      @r   ÚcoordszGeoIP2.coordsÙ   s[   ø€ ÝŒØJÝ$Øð	
ñ 	
ô 	
ð 	
ð
 �yŠy˜ÑÔˆÝÐ/Ð/Ð/Ð/ hÐ/Ñ/Ô/Ñ/Ô/Ð/r   c                 óL   — |                       |¦  «        }|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                 óL   — |                       |¦  «        }|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                 óN   — ddl m}  ||                      |¦  «        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ì   s7   € ð 	2Ð1Ð1Ð1Ð1Ð1àˆu�T—\’\ %Ñ(Ô(¨tÐ4Ñ4Ô4Ð4r   c                 óZ   — t          j        dt          d¬¦  «         t          ||¦  «        S )Nz2GeoIP2.open() is deprecated. Use GeoIP2() instead.r   r{   )r‚   rƒ   r   r
   )ÚclsÚ	full_pathr0   s      r   ÚopenzGeoIP2.openó   s6   € åŒØ@Ý$Øð	
ñ 	
ô 	
ð 	
õ
 �i Ñ'Ô'Ð'r   )Nr   NN)ry   )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Ø�IØ	�M 9¨i¸ÐEñô €Mð €EØ€Gð2Yð 2Yð 2Yð 2Yðh!ð !ð !ð
Oð Oð Oð
 ð'ð 'ñ „_ð'ð ð6ð 6ñ „_ð6ð ð9ð 9ñ „_ð9ð -2ð ð ð ð ð ð(
ð 
ð 
ð83ð 3ð 3ð3ð 3ð 3ð
ð 
ð 
ð0ð 0ð 0ð 0ð3ð 3ð 3ð
3ð 3ð 3ð
5ð 5ð 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¨      sj  ððð ð Ð Ð Ð Ø €€€Ø €€€à  Ð  Ð  Ð  Ð  Ð  Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø $Ð $Ð $Ð $Ð $Ð $Ø =Ð =Ð =Ð =Ð =Ð =Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3àˆ.€ð-ØÐÐÐð €JØ�Ð+Ð,Ñ,€G€Gøð	 ð ð ð Ø€J€J€Jðøøøðð ð Ð ð	ð 	ð 	ð 	ð 	�iñ 	ô 	ð 	ðE(ð E(ð E(ð E(ð E(ñ E(ô E(ð E(ð E(ð E(s   ·A ÁAÁA