a
    8öjá8  ã                   @   s$  d Z ddl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ZddlmZ ddlm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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dS ) a  The models for response from th GeoIP2 web service and databases.

The only difference between the City and Insights model classes is which
fields in each record may be populated. See
https://dev.maxmind.com/geoip/docs/web-services?lang=en for more details.
é    N)ÚABCMeta)ÚSequence)ÚIPv4AddressÚIPv6Address)ÚOptionalÚUnion)ÚModel)Ú	IPAddressc                   @   sÄ   e Zd ZU dZejjed< ejjed< ejj	ed< ejjed< ejj
ed< ejje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 dd
œ
dd„Zedœdd„ZdS )ÚCountryz7Model for the Country web service and Country database.Ú	continentÚcountryÚmaxmindÚregistered_countryÚrepresented_countryÚtraitsN©r   r   Ú
ip_addressr   Ú
prefix_lenr   r   r   )
Úlocalesr   r   r   r   r   r   r   r   Úreturnc                K   sÆ   || _ tjj|fi |pi ¤Ž| _tjj|fi |p2i ¤Ž| _tjj|fi |pLi ¤Ž| _tjj|fi |pfi ¤Ž| _	tjj
f i |p~i ¤Ž| _|	pŒi }	|d urž||	d< |d ur®||	d< tjjf i |	¤Ž| _d S )Nr   r   )Ú_localesÚgeoip2ÚrecordsÚ	Continentr   r
   r   r   ÚRepresentedCountryr   ÚMaxMindr   ÚTraitsr   )Úselfr   r   r   r   r   r   r   r   r   Ú_© r   úL/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/geoip2/models.pyÚ__init__2   s(    ÿþÿþzCountry.__init__©r   c                 C   s<   | j › d| jj› d| j›dd dd„ |  ¡  ¡ D ƒ¡› d�S )NÚ.ú(ú, c                 s   s    | ]\}}|› d |›�V  qdS ©ú=Nr   ©Ú.0ÚkÚvr   r   r    Ú	<genexpr>Y   ó    z#Country.__repr__.<locals>.<genexpr>ú))Ú
__module__Ú	__class__Ú__name__r   ÚjoinÚto_dictÚitems©r   r   r   r    Ú__repr__V   s    ÿÿzCountry.__repr__)r1   r/   Ú__qualname__Ú__doc__r   r   r   Ú__annotations__r
   r   r   r   r   r   ÚstrÚdictr	   Úintr!   r6   r   r   r   r    r
      s8   
õ
ó$r
   c                       sÊ   e Zd ZU dZejjed< ejjed< ejj	ed< ejj
e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 ddœ‡ fd	d
„Z‡  ZS )ÚCityz:Model for the City Plus web service and the City database.ÚcityÚlocationÚpostalÚsubdivisionsN)r>   r   r   r?   r   r   r@   r   r   r   rA   r   )r   r>   r   r   r?   r   r   r@   r   r   r   rA   r   r   c                   s†   t ƒ j||||||	|
||d�	 tjj|fi |p0i ¤Ž| _tjjf i |pHi ¤Ž| _tjjf i |p`i ¤Ž| _	tjj
|g|pxg ¢R Ž | _d S )Nr   )Úsuperr!   r   r   r=   r>   ÚLocationr?   ÚPostalr@   ÚSubdivisionsrA   )r   r   r>   r   r   r?   r   r   r@   r   r   r   rA   r   r   ©r0   r   r    r!   n   s    ÷zCity.__init__)r1   r/   r7   r8   r   r   r=   r9   rC   rD   rE   r   r   r:   r;   r	   r<   Úlistr!   Ú__classcell__r   r   rF   r    r=   ]   sB   
	ñ

ïr=   c                   @   s   e Zd ZdZdS )ÚInsightsz*Model for the GeoIP2 Insights web service.N©r1   r/   r7   r8   r   r   r   r    rI   ‘   s   rI   c                   @   s   e Zd ZdZdS )Ú
Enterprisez)Model for the GeoIP2 Enterprise database.NrJ   r   r   r   r    rK   •   s   rK   c                   @   s¤   e Zd ZU dZeed< eeej	ej
f  ed< ee ed< eee ee ddœdd„Zed	œd
d„Zeeeef d	œdd„ƒZeeeej	ej
f  d	œdd„ƒZdS )ÚSimpleModelz/Provides basic methods for non-location models.Ú_ip_addressÚ_networkÚ_prefix_lenN)r   Únetworkr   r   c                 C   s6   |r t j|dd�| _| jj| _nd | _|| _|| _d S )NF©Ústrict)Ú	ipaddressÚ
ip_networkrN   Ú	prefixlenrO   rM   )r   r   rP   r   r   r   r    r!       s    zSimpleModel.__init__r"   c                 C   sX   |   ¡ }| dd ¡ | j› d| jj› d�tt| jƒƒ d d dd„ | 	¡ D ƒ¡ d S )Nr   r#   r$   r%   c                 s   s    | ]\}}|› d |›�V  qdS r&   r   r(   r   r   r    r,   ¸   r-   z'SimpleModel.__repr__.<locals>.<genexpr>r.   )
r3   Úpopr/   r0   r1   Úreprr:   rM   r2   r4   )r   Údr   r   r    r6   ±   s    ÿþýüÿzSimpleModel.__repr__c                 C   s$   t | jttfƒst | j¡| _| jS )zThe IP address for the record.)Ú
isinstancerM   r   r   rS   r   r5   r   r   r    r   ¼   s    zSimpleModel.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ú/FrQ   )rN   r   rO   rS   rT   )r   rP   r   r   r   r   r    rP   Ã   s    zSimpleModel.network)r1   r/   r7   r8   r	   r9   r   r   rS   ÚIPv4NetworkÚIPv6Networkr<   r:   r!   r6   Úpropertyr   r   r   rP   r   r   r   r    rL   ™   s   
ûrL   )Ú	metaclassc                       s†   e Zd ZU dZeed< eed< eed< eed< eed< eed< ddddddd	d	d
œeeeeeeeee ee	 d	dœ
‡ fdd„Z
‡  ZS )ÚAnonymousIPz(Model class for the GeoIP2 Anonymous IP.Úis_anonymousÚis_anonymous_vpnÚis_hosting_providerÚis_public_proxyÚis_residential_proxyÚis_tor_exit_nodeFN)r`   ra   rb   rc   rd   re   rP   r   )
r   r`   ra   rb   rc   rd   re   rP   r   r   c                   s8   t ƒ  |||	¡ || _|| _|| _|| _|| _|| _d S ©N)rB   r!   r`   ra   rb   rc   rd   re   )r   r   r`   ra   rb   rc   rd   re   rP   r   r   rF   r   r    r!   ÷   s    zAnonymousIP.__init__)r1   r/   r7   r8   Úboolr9   r	   r   r:   r<   r!   rH   r   r   rF   r    r_   Ø   s6   
	õór_   c                       s”   e Zd ZU dZee ed< eej ed< ee	 e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	 ddœ‡ fd	d
„Z‡  ZS )ÚAnonymousPlusz)Model class for the GeoIP Anonymous Plus.Úanonymizer_confidenceÚnetwork_last_seenÚprovider_nameNF)ri   r`   ra   rb   rc   rd   re   rP   rj   r   rk   )r   ri   r`   ra   rb   rc   rd   re   rP   rj   r   rk   r   c                   sD   t ƒ j||||||||	|d�	 || _|
d ur:tj |
¡| _|| _d S )N)	r`   ra   rb   rc   rd   re   r   rP   r   )rB   r!   ri   ÚdatetimeÚdateÚfromisoformatrj   rk   )r   r   ri   r`   ra   rb   rc   rd   re   rP   rj   r   rk   r   rF   r   r    r!      s    ÷zAnonymousPlus.__init__)r1   r/   r7   r8   r   r<   r9   rl   rm   r:   r	   rg   r!   rH   r   r   rF   r    rh     s<   
	òðrh   c                       sf   e Zd ZU dZee ed< ee ed< dddddœeee ee ee ee ddœ‡ fdd„Z	‡  Z
S )	ÚASNz!Model class for the GeoLite2 ASN.Úautonomous_system_numberÚautonomous_system_organizationN)rp   rq   rP   r   )r   rp   rq   rP   r   r   c                   s    t ƒ  |||¡ || _|| _d S rf   )rB   r!   rp   rq   )r   r   rp   rq   rP   r   r   rF   r   r    r!   N  s    
zASN.__init__)r1   r/   r7   r8   r   r<   r9   r:   r	   r!   rH   r   r   rF   r    ro   B  s   

ù÷ro   c                       sR   e Zd ZU dZee ed< ddddœeee ee ee ddœ‡ fdd„Z	‡  Z
S )ÚConnectionTypez+Model class for the GeoIP2 Connection-Type.Úconnection_typeN)rs   rP   r   )r   rs   rP   r   r   c                   s   t ƒ  |||¡ || _d S rf   )rB   r!   rs   )r   r   rs   rP   r   r   rF   r   r    r!   l  s    	zConnectionType.__init__©r1   r/   r7   r8   r   r:   r9   r	   r<   r!   rH   r   r   rF   r    rr   ]  s   
úørr   c                       sR   e Zd ZU dZee ed< ddddœeee ee ee ddœ‡ fdd„Z	‡  Z
S )ÚDomainz"Model class for the GeoIP2 Domain.ÚdomainN)rv   rP   r   )r   rv   rP   r   r   c                   s   t ƒ  |||¡ || _d S rf   )rB   r!   rv   )r   r   rv   rP   r   r   rF   r   r    r!     s    	zDomain.__init__rt   r   r   rF   r    ru   y  s   
úøru   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< 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 ddœ
‡ fd	d
„Z	‡  Z
S )ÚISPzModel class for the GeoIP2 ISP.ÚispÚmobile_country_codeÚmobile_network_codeÚorganizationN)rp   rq   rx   ry   rz   r{   rP   r   )
r   rp   rq   rx   ry   rz   r{   rP   r   r   c                   s2   t ƒ j|||||	d� || _|| _|| _|| _d S )N)rp   rq   r   rP   r   )rB   r!   rx   ry   rz   r{   )r   r   rp   rq   rx   ry   rz   r{   rP   r   r   rF   r   r    r!   ¢  s    ûzISP.__init__rt   r   r   rF   r    rw   Œ  s2   
õórw   )r8   rl   rS   Úabcr   Úcollections.abcr   r   r   Útypingr   r   Zgeoip2.recordsr   Zgeoip2._internalr   Zgeoip2.typesr	   r
   r=   rI   rK   rL   r_   rh   ro   rr   ru   rw   r   r   r   r    Ú<module>   s(   H4?64