a
    8öj5W  ã                   @   s(  d Z ddlZddlmZ ddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZ ddlmZ G d	d
„ d
eed�ZG dd„ deed�ZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG d d!„ d!eƒZdS )"z/Record classes used within the response models.é    N)ÚABCMeta)ÚSequence)ÚIPv4AddressÚIPv6Address)ÚOptionalÚUnion)ÚModel)Ú	IPAddressc                   @   s   e Zd ZdZedœdd„ZdS )ÚRecordz<All records are subclasses of the abstract class ``Record``.©Úreturnc                 C   s8   d  dd„ |  ¡  ¡ D ƒ¡}| j› d| jj› d|› d�S )Nz, c                 s   s    | ]\}}|› d |›�V  qdS )ú=N© )Ú.0ÚkÚvr   r   úM/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/geoip2/records.pyÚ	<genexpr>   ó    z"Record.__repr__.<locals>.<genexpr>Ú.ú(ú))ÚjoinÚto_dictÚitemsÚ
__module__Ú	__class__Ú__name__)ÚselfÚargsr   r   r   Ú__repr__   s    zRecord.__repr__N)r   r   Ú__qualname__Ú__doc__Ústrr    r   r   r   r   r
      s   r
   )Ú	metaclassc                   @   sj   e Zd ZU dZeeef ed< ee ed< eee  eeeef  ddœdd„Z	e
ee dœd	d
„ƒZdS )ÚPlaceRecordzCAll records with :py:attr:`names` subclass :py:class:`PlaceRecord`.ÚnamesÚ_localesN)Úlocalesr&   r   c                 C   s*   |d u rdg}|| _ |d u r i }|| _d S )NÚen)r'   r&   )r   r(   r&   r   r   r   Ú__init__    s    zPlaceRecord.__init__r   c                    s   t ‡ fdd„ˆ jD ƒdƒS )z=The name based on the locales list passed to the constructor.c                 3   s$   | ]}|ˆ j v rˆ j  |¡V  qd S ©N)r&   Úget©r   Úx©r   r   r   r   0   r   z#PlaceRecord.name.<locals>.<genexpr>N)Únextr'   r/   r   r/   r   Úname,   s    zPlaceRecord.name)r   r   r!   r"   Údictr#   Ú__annotations__r   r   r*   Úpropertyr1   r   r   r   r   r%      s   

ür%   c                       sn   e Zd ZU dZee ed< ee ed< ddddœeee  ee ee ee	eef  ddœ‡ fdd„Z
‡  ZS )	ÚCityzÝContains data for the city record associated with an IP address.

    This class contains the city-level data associated with an IP address.

    This record is returned by ``city``, ``enterprise``, and ``insights``.
    Ú
confidenceÚ
geoname_idN)r6   r7   r&   )r(   r6   r7   r&   r   c                   s   || _ || _tƒ  ||¡ d S r+   )r6   r7   Úsuperr*   )r   r(   r6   r7   r&   Ú_©r   r   r   r*   C   s    	zCity.__init__)r   r   r!   r"   r   Úintr3   r   r#   r2   r*   Ú__classcell__r   r   r:   r   r5   3   s   
ú
ør5   c                       sn   e Zd ZU dZee ed< ee ed< ddddœeee  ee ee ee	eef  ddœ‡ fdd„Z
‡  ZS )	Ú	ContinentzŸContains data for the continent record associated with an IP address.

    This class contains the continent-level data associated with an IP
    address.
    Úcoder7   N)r>   r7   r&   )r(   r>   r7   r&   r   c                   s   || _ || _tƒ  ||¡ d S r+   )r>   r7   r8   r*   )r   r(   r>   r7   r&   r9   r:   r   r   r*   _   s    	zContinent.__init__)r   r   r!   r"   r   r#   r3   r;   r   r2   r*   r<   r   r   r:   r   r=   Q   s   
ú
ør=   c                
       sŽ   e Zd ZU dZee ed< ee ed< eed< ee ed< ddddddœee	e  ee ee eee ee
eef  dd	œ‡ fd
d„Z‡  ZS )ÚCountryz—Contains data for the country record associated with an IP address.

    This class contains the country-level data associated with an IP address.
    r6   r7   Úis_in_european_unionÚiso_codeNF©r6   r7   r@   rA   r&   )r(   r6   r7   r@   rA   r&   r   c                   s*   || _ || _|| _|| _tƒ  ||¡ d S r+   )r6   r7   r@   rA   r8   r*   )r   r(   r6   r7   r@   rA   r&   r9   r:   r   r   r*   ‚   s
    zCountry.__init__)r   r   r!   r"   r   r;   r3   Úboolr#   r   r2   r*   r<   r   r   r:   r   r?   m   s&   

ø
ör?   c                
       sv   e Zd ZU dZee ed< dddddddœeee  ee ee e	ee ee
eef  ee ddœ‡ fdd„Z‡  ZS )	ÚRepresentedCountrya  Contains data for the represented country associated with an IP address.

    This class contains the country-level data associated with an IP address
    for the IP's represented country. The represented country is the country
    represented by something like a military base.
    ÚtypeNF)r6   r7   r@   rA   r&   rE   )r(   r6   r7   r@   rA   r&   rE   r   c          	         s"   || _ tƒ j||||||d� d S )NrB   )rE   r8   r*   )	r   r(   r6   r7   r@   rA   r&   rE   r9   r:   r   r   r*   ¢   s    úzRepresentedCountry.__init__)r   r   r!   r"   r   r#   r3   r   r;   rC   r2   r*   r<   r   r   r:   r   rD   ”   s$   

ö
ôrD   c                
   @   s°   e Zd ZU dZee ed< ee ed< ee ed< ee ed< ee ed< ee ed< ee ed< d	d	d	d	d	d	d	d
œee ee ee ee ee ee ee d	dœdd„Z	d	S )ÚLocationzßContains data for the location record associated with an IP address.

    This class contains the location data associated with an IP address.

    This record is returned by ``city``, ``enterprise``, and ``insights``.
    Úaverage_incomeÚaccuracy_radiusÚlatitudeÚ	longitudeÚ
metro_codeÚpopulation_densityÚ	time_zoneN©rG   rH   rI   rJ   rK   rL   rM   )rG   rH   rI   rJ   rK   rL   rM   r   c          	      K   s.   || _ || _|| _|| _|| _|| _|| _d S r+   rN   )	r   rG   rH   rI   rJ   rK   rL   rM   r9   r   r   r   r*   æ   s    zLocation.__init__)
r   r   r!   r"   r   r;   r3   Úfloatr#   r*   r   r   r   r   rF   º   s2   
	÷õrF   c                   @   s8   e Zd ZU dZee ed< ddœee ddœdd„ZdS )ÚMaxMindz.Contains data related to your MaxMind account.Úqueries_remainingN©rQ   )rQ   r   c                K   s
   || _ d S r+   rR   )r   rQ   r9   r   r   r   r*     s    zMaxMind.__init__)r   r   r!   r"   r   r;   r3   r*   r   r   r   r   rP   û   s   
rP   c                   @   sL   e Zd ZU dZee ed< ee ed< dddœee ee ddœdd„ZdS )	ÚPostalzÞContains data for the postal record associated with an IP address.

    This class contains the postal data associated with an IP address.

    This attribute is returned by ``city``, ``enterprise``, and ``insights``.
    r>   r6   N©r>   r6   )r>   r6   r   c                K   s   || _ || _d S r+   rT   )r   r>   r6   r9   r   r   r   r*     s    zPostal.__init__)	r   r   r!   r"   r   r#   r3   r;   r*   r   r   r   r   rS     s   
	üúrS   c                	       s‚   e Zd ZU dZee ed< ee ed< ee ed< dddddœeee  ee ee ee ee	eef  ddœ‡ fdd	„Z
‡  ZS )
ÚSubdivisionzâContains data for the subdivisions associated with an IP address.

    This class contains the subdivision data associated with an IP address.

    This attribute is returned by ``city``, ``enterprise``, and ``insights``.
    r6   r7   rA   N)r6   r7   rA   r&   )r(   r6   r7   rA   r&   r   c                   s$   || _ || _|| _tƒ  ||¡ d S r+   )r6   r7   rA   r8   r*   )r   r(   r6   r7   rA   r&   r9   r:   r   r   r*   9  s    
zSubdivision.__init__)r   r   r!   r"   r   r;   r3   r#   r   r2   r*   r<   r   r   r:   r   rU   %  s    
	ù
÷rU   c                       sd   e Zd ZdZed  eee  d dœ‡ fdd„Zeee  ddœ‡ fdd„Z	e
ed	œd
d„ƒZ‡  ZS )ÚSubdivisionsa¤  A tuple-like collection of subdivisions associated with an IP address.

    This class contains the subdivisions of the country associated with the
    IP address from largest to smallest.

    For instance, the response for Oxford in the United Kingdom would have
    England as the first element and Oxfordshire as the second element.

    This attribute is returned by ``city``, ``enterprise``, and ``insights``.
    )Úclsr(   r   c                    s$   t ‡ fdd„|D ƒƒ}tƒ  | |¡S )Nc                 3   s   | ]}t ˆ fi |¤ŽV  qd S r+   )rU   r-   ©r(   r   r   r   Z  r   z'Subdivisions.__new__.<locals>.<genexpr>)Útupler8   Ú__new__)rW   r(   ÚsubdivisionsZsubobjsr:   rX   r   rZ   U  s    zSubdivisions.__new__N)r(   r   c                    s   || _ tƒ  ¡  d S r+   )r'   r8   r*   )r   r(   r[   r:   r   r   r*   ]  s    zSubdivisions.__init__r   c                 C   s,   z
| d W S  t y&   t| jƒ Y S 0 dS )z¾The most specific (smallest) subdivision available.

        If there are no :py:class:`Subdivision` objects for the response,
        this returns an empty :py:class:`Subdivision`.
        éÿÿÿÿN)Ú
IndexErrorrU   r'   r/   r   r   r   Úmost_specifice  s    
zSubdivisions.most_specific)r   r   r!   r"   rE   r   r   r#   rZ   r*   r4   rU   r^   r<   r   r   r:   r   rV   I  s   
ü

ürV   c                   @   s   e Zd ZU dZee ed< ee ed< ee ed< ee ed< ee ed< e	ed< e	ed< e	ed	< e	ed
< e	ed< e	ed< e	ed< e	ed< e	ed< e	ed< ee ed< ee ed< ee ed< ee ed< ee
 ed< ee ed< ee ed< eeejejf  ed< ee ed< dddddddddddddddddddddddddœee ee ee ee e	e	e	e	e	e	e	e	e	ee ee ee ee ee ee
 ee ee ee ee e	ddœdd„Zeeeeef  d œd!d"„ƒZeeeejejf  d œd#d$„ƒZdS )%ÚTraitsz�Contains data for the traits record associated with an IP address.

    This class contains the traits data associated with an IP address.
    Úautonomous_system_numberÚautonomous_system_organizationÚconnection_typeÚdomainÚ_ip_addressÚis_anonymousÚis_anonymous_proxyÚis_anonymous_vpnÚ
is_anycastÚis_hosting_providerÚis_legitimate_proxyÚis_public_proxyÚis_residential_proxyÚis_satellite_providerÚis_tor_exit_nodeÚispÚmobile_country_codeÚmobile_network_codeÚorganizationÚstatic_ip_scoreÚ
user_countÚ	user_typeÚ_networkÚ_prefix_lenNF)r`   ra   rb   rc   re   rf   rg   ri   rj   rk   rl   rm   rn   ro   Ú
ip_addressÚnetworkrr   Ú
prefix_lenrs   rt   ru   rp   rq   rh   )r`   ra   rb   rc   re   rf   rg   ri   rj   rk   rl   rm   rn   ro   rx   ry   rr   rz   rs   rt   ru   rp   rq   rh   r   c                K   s®   || _ || _|| _|| _|| _|| _|| _|| _|| _|	| _	|
| _
|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|d u r”d | _ntj|dd�| _|| _d S )NF©Ústrict)r`   ra   rb   rc   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   ru   rt   rd   rv   Ú	ipaddressÚ
ip_networkrw   )r   r`   ra   rb   rc   re   rf   rg   ri   rj   rk   rl   rm   rn   ro   rx   ry   rr   rz   rs   rt   ru   rp   rq   rh   r9   r   r   r   r*     s4    zTraits.__init__r   c                 C   s4   | j }|du rdS t|ttfƒs0t |¡}|| _ |S )aE  The IP address that the data in the model is for.

        If you performed a "me" lookup against the web service, this will be
        the externally routable IP address for the system the code is running
        on. If the system is behind a NAT, this may differ from the IP address
        locally assigned to it.
        N)rd   Ú
isinstancer   r   r}   rx   )r   rx   r   r   r   rx   U  s    	
zTraits.ip_addressc                 C   sT   | j }|dur|S | j}| j}|du s.|du r2dS tj|› d|› �dd�}|| _ |S )z¬The network associated with the record.

        In particular, this is the largest network where all of the fields besides
        ip_address have the same value.
        Nú/Fr{   )rv   rx   rw   r}   r~   )r   ry   rx   rz   r   r   r   ry   g  s    zTraits.network)r   r   r!   r"   r   r;   r3   r#   r	   rC   rO   r   r}   ÚIPv4NetworkÚIPv6Networkr*   r4   r   r   rx   ry   r   r   r   r   r_   r  s    


æä<r_   )r"   r}   Úabcr   Úcollections.abcr   r   r   Útypingr   r   Zgeoip2._internalr   Zgeoip2.typesr	   r
   r%   r5   r=   r?   rD   rF   rP   rS   rU   rY   rV   r_   r   r   r   r   Ú<module>   s&   '&A$)