U
    [eD                     @   s   d Z ddlZddlmZ ddlmZmZmZmZm	Z	m
Z
 ddl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dS )a-  
Models
======

These classes provide models for the data returned by the 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)AnycastDictListOptionalUnion)SimpleEqualityc                   @   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eeef eee  dd	d
dZedddZdS )Countrya2  Model for the Country web service and Country database.

    This class provides the following attributes:

    .. attribute:: continent

      Continent object for the requested IP address.

      :type: :py:class:`geoip2.records.Continent`

    .. attribute:: country

      Country object for the requested IP address. This record represents the
      country where MaxMind believes the IP is located.

      :type: :py:class:`geoip2.records.Country`

    .. attribute:: maxmind

      Information related to your MaxMind account.

      :type: :py:class:`geoip2.records.MaxMind`

    .. attribute:: registered_country

      The registered country object for the requested IP address. This record
      represents the country where the ISP has registered a given IP block in
      and may differ from the user's country.

      :type: :py:class:`geoip2.records.Country`

    .. attribute:: represented_country

      Object for the country represented by the users of the IP address
      when that country is different than the country in ``country``. For
      instance, the country represented by an overseas military base.

      :type: :py:class:`geoip2.records.RepresentedCountry`

    .. attribute:: traits

      Object with the traits of the requested IP address.

      :type: :py:class:`geoip2.records.Traits`

    	continentcountrymaxmindregistered_countryrepresented_countrytraitsNraw_responselocalesreturnc                 C   s   |d krdg}|| _ tjj|f|di | _tjj|f|di | _tjj|f|di | _tjj	|f|di | _
tjjf |di | _tjjf |di | _|| _d S )Nenr   r   r   r   r   r   )_localesgeoip2records	Continentgetr   r
   r   r   RepresentedCountryr   MaxMindr   Traitsr   rawselfr   r    r!   O/var/www/html/services/stratfitenv/lib/python3.8/site-packages/geoip2/models.py__init__M   s4    



zCountry.__init__r   c                 C   s&   | j  d| jj d| j d| j dS )N.(z, ))
__module__	__class____name__r   r   r    r!   r!   r"   __repr__e   s    $zCountry.__repr__)N)r*   r(   __qualname____doc__r   r   r   __annotations__r
   r   r   r   r   strr   r   r   r#   r,   r!   r!   r!   r"   r
      s   
/ 
 
r
   c                       sn   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
eeef eee  dd fdd	Z  ZS )CityaW  Model for the City Plus web service and the City database.

    .. attribute:: city

      City object for the requested IP address.

      :type: :py:class:`geoip2.records.City`

    .. attribute:: continent

      Continent object for the requested IP address.

      :type: :py:class:`geoip2.records.Continent`

    .. attribute:: country

      Country object for the requested IP address. This record represents the
      country where MaxMind believes the IP is located.

      :type: :py:class:`geoip2.records.Country`

    .. attribute:: location

      Location object for the requested IP address.

      :type: :py:class:`geoip2.records.Location`

    .. attribute:: maxmind

      Information related to your MaxMind account.

      :type: :py:class:`geoip2.records.MaxMind`

    .. attribute:: postal

      Postal object for the requested IP address.

      :type: :py:class:`geoip2.records.Postal`

    .. attribute:: registered_country

      The registered country object for the requested IP address. This record
      represents the country where the ISP has registered a given IP block in
      and may differ from the user's country.

      :type: :py:class:`geoip2.records.Country`

    .. attribute:: represented_country

      Object for the country represented by the users of the IP address
      when that country is different than the country in ``country``. For
      instance, the country represented by an overseas military base.

      :type: :py:class:`geoip2.records.RepresentedCountry`

    .. attribute:: subdivisions

      Object (tuple) representing the subdivisions of the country to which
      the location of the requested IP address belongs.

      :type: :py:class:`geoip2.records.Subdivisions`

    .. attribute:: traits

      Object with the traits of the requested IP address.

      :type: :py:class:`geoip2.records.Traits`

    citylocationpostalsubdivisionsNr   c                    sx   t  || tjj|f|di | _tjjf |di | _tjj	f |di | _
tjj|f|dg  | _d S )Nr2   r3   r4   r5   )superr#   r   r   r1   r   r2   Locationr3   Postalr4   Subdivisionsr5   r   r)   r!   r"   r#      s    
zCity.__init__)N)r*   r(   r-   r.   r   r   r1   r/   r7   r8   r9   r   r0   r   r   r   r#   __classcell__r!   r!   r:   r"   r1   k   s   
F 
 
r1   c                   @   s   e Zd ZdZdS )Insightsa  Model for the GeoIP2 Insights web service.

    .. attribute:: city

      City object for the requested IP address.

      :type: :py:class:`geoip2.records.City`

    .. attribute:: continent

      Continent object for the requested IP address.

      :type: :py:class:`geoip2.records.Continent`

    .. attribute:: country

      Country object for the requested IP address. This record represents the
      country where MaxMind believes the IP is located.

      :type: :py:class:`geoip2.records.Country`

    .. attribute:: location

      Location object for the requested IP address.

    .. attribute:: maxmind

      Information related to your MaxMind account.

      :type: :py:class:`geoip2.records.MaxMind`

    .. attribute:: registered_country

      The registered country object for the requested IP address. This record
      represents the country where the ISP has registered a given IP block in
      and may differ from the user's country.

      :type: :py:class:`geoip2.records.Country`

    .. attribute:: represented_country

      Object for the country represented by the users of the IP address
      when that country is different than the country in ``country``. For
      instance, the country represented by an overseas military base.

      :type: :py:class:`geoip2.records.RepresentedCountry`

    .. attribute:: subdivisions

      Object (tuple) representing the subdivisions of the country to which
      the location of the requested IP address belongs.

      :type: :py:class:`geoip2.records.Subdivisions`

    .. attribute:: traits

      Object with the traits of the requested IP address.

      :type: :py:class:`geoip2.records.Traits`

    Nr*   r(   r-   r.   r!   r!   r!   r"   r<      s   r<   c                   @   s   e Zd ZdZdS )
Enterprisea  Model for the GeoIP2 Enterprise database.

    .. attribute:: city

      City object for the requested IP address.

      :type: :py:class:`geoip2.records.City`

    .. attribute:: continent

      Continent object for the requested IP address.

      :type: :py:class:`geoip2.records.Continent`

    .. attribute:: country

      Country object for the requested IP address. This record represents the
      country where MaxMind believes the IP is located.

      :type: :py:class:`geoip2.records.Country`

    .. attribute:: location

      Location object for the requested IP address.

    .. attribute:: maxmind

      Information related to your MaxMind account.

      :type: :py:class:`geoip2.records.MaxMind`

    .. attribute:: registered_country

      The registered country object for the requested IP address. This record
      represents the country where the ISP has registered a given IP block in
      and may differ from the user's country.

      :type: :py:class:`geoip2.records.Country`

    .. attribute:: represented_country

      Object for the country represented by the users of the IP address
      when that country is different than the country in ``country``. For
      instance, the country represented by an overseas military base.

      :type: :py:class:`geoip2.records.RepresentedCountry`

    .. attribute:: subdivisions

      Object (tuple) representing the subdivisions of the country to which
      the location of the requested IP address belongs.

      :type: :py:class:`geoip2.records.Subdivisions`

    .. attribute:: traits

      Object with the traits of the requested IP address.

      :type: :py:class:`geoip2.records.Traits`

    Nr=   r!   r!   r!   r"   r>     s   r>   c                   @   s   e Zd ZU dZeeeeeef f e	d< ee	d< e
eejejf  e	d< ee	d< eeeeeef f dddd	Ze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 modelsr   
ip_address_network_prefix_lenNr   r   c                 C   s4   || _ d | _tt|d| _tt|d| _d S )N
prefix_lenr@   )r   rA   r   intr   rB   r0   r@   r    r   r!   r!   r"   r#   K  s    zSimpleModel.__init__r$   c                 C   s   | j  d| jj d| j dS )Nr%   r&   r'   )r(   r)   r*   r   r+   r!   r!   r"   r,   Q  s    zSimpleModel.__repr__c                 C   sR   | j }|dk	r|S | j}| j}|dks.|dkr2dS t| d| d}|| _ |S )zThe network for the recordN/F)rA   r@   rB   	ipaddress
ip_network)r    networkr@   rD   r!   r!   r"   rJ   T  s    zSimpleModel.network)r*   r(   r-   r.   r   r0   r   boolrE   r/   r   rH   IPv4NetworkIPv6Networkr#   r,   propertyrJ   r!   r!   r!   r"   r?   C  s   
"r?   )	metaclassc                       sb   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< eeef dd	 fd
dZ  Z	S )AnonymousIPa  Model class for the GeoIP2 Anonymous IP.

    This class provides the following attribute:

    .. attribute:: is_anonymous

      This is true if the IP address belongs to any sort of anonymous network.

      :type: bool

    .. attribute:: is_anonymous_vpn

      This is true if the IP address is registered to an anonymous VPN
      provider.

      If a VPN provider does not register subnets under names associated with
      them, we will likely only flag their IP ranges using the
      ``is_hosting_provider`` attribute.

      :type: bool

    .. attribute:: is_hosting_provider

      This is true if the IP address belongs to a hosting or VPN provider
      (see description of ``is_anonymous_vpn`` attribute).

      :type: bool

    .. attribute:: is_public_proxy

      This is true if the IP address belongs to a public proxy.

      :type: bool

    .. attribute:: is_residential_proxy

      This is true if the IP address is on a suspected anonymizing network
      and belongs to a residential ISP.

      :type: bool

    .. attribute:: is_tor_exit_node

      This is true if the IP address is a Tor exit node.

      :type: bool

    .. attribute:: ip_address

      The IP address used in the lookup.

      :type: str

    .. attribute:: network

      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.

      :type: ipaddress.IPv4Network or ipaddress.IPv6Network
    is_anonymousis_anonymous_vpnis_hosting_provideris_public_proxyis_residential_proxyis_tor_exit_nodeNrC   c                    sd   t  | |dd| _|dd| _|dd| _|dd| _|dd| _|dd| _d S )NrQ   FrR   rS   rT   rU   rV   )	r6   r#   r   rQ   rR   rS   rT   rU   rV   rF   r:   r!   r"   r#     s    zAnonymousIP.__init__)
r*   r(   r-   r.   rK   r/   r   r0   r#   r;   r!   r!   r:   r"   rP   e  s   
>rP   c                       sR   e Zd ZU dZee ed< ee ed< eee	eef f dd fddZ
  ZS )ASNa  Model class for the GeoLite2 ASN.

    This class provides the following attribute:

    .. attribute:: autonomous_system_number

      The autonomous system number associated with the IP address.

      :type: int

    .. attribute:: autonomous_system_organization

      The organization associated with the registered autonomous system number
      for the IP address.

      :type: str

    .. attribute:: ip_address

      The IP address used in the lookup.

      :type: str

    .. attribute:: network

      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.

      :type: ipaddress.IPv4Network or ipaddress.IPv6Network
    autonomous_system_numberautonomous_system_organizationNrC   c                    s<   t  | ttt |d| _ttt |d| _d S )NrX   rY   )	r6   r#   r   r   rE   r   rX   r0   rY   rF   r:   r!   r"   r#     s      zASN.__init__)r*   r(   r-   r.   r   rE   r/   r0   r   r   r#   r;   r!   r!   r:   r"   rW     s   
 rW   c                       sF   e Zd ZU dZee ed< eeeee	f f dd fddZ
  ZS )ConnectionTypea  Model class for the GeoIP2 Connection-Type.

    This class provides the following attribute:

    .. attribute:: connection_type

      The connection type may take the following values:

      - Dialup
      - Cable/DSL
      - Corporate
      - Cellular

      Additional values may be added in the future.

      :type: str

    .. attribute:: ip_address

      The IP address used in the lookup.

      :type: str

    .. attribute:: network

      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.

      :type: ipaddress.IPv4Network or ipaddress.IPv6Network
    connection_typeNrC   c                    s&   t  | ttt |d| _d S )Nr[   )r6   r#   r   r   r0   r   r[   rF   r:   r!   r"   r#     s    zConnectionType.__init__r*   r(   r-   r.   r   r0   r/   r   r   rE   r#   r;   r!   r!   r:   r"   rZ     s   
 rZ   c                       sF   e Zd ZU dZee ed< eeeee	f f dd fddZ
  ZS )Domaina  Model class for the GeoIP2 Domain.

    This class provides the following attribute:

    .. attribute:: domain

      The domain associated with the IP address.

      :type: str

    .. attribute:: ip_address

      The IP address used in the lookup.

      :type: str

    .. attribute:: network

      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.

      :type: ipaddress.IPv4Network or ipaddress.IPv6Network

    domainNrC   c                    s&   t  | ttt |d| _d S )Nr^   )r6   r#   r   r   r0   r   r^   rF   r:   r!   r"   r#   )  s    zDomain.__init__r\   r!   r!   r:   r"   r]     s   
r]   c                       sj   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ee	f f dd fdd	Z
  ZS )
ISPaP  Model class for the GeoIP2 ISP.

    This class provides the following attribute:

    .. attribute:: autonomous_system_number

      The autonomous system number associated with the IP address.

      :type: int

    .. attribute:: autonomous_system_organization

      The organization associated with the registered autonomous system number
      for the IP address.

      :type: str

    .. attribute:: isp

      The name of the ISP associated with the IP address.

      :type: str

    .. attribute: mobile_country_code

      The `mobile country code (MCC)
      <https://en.wikipedia.org/wiki/Mobile_country_code>`_ associated with the
      IP address and ISP.

      :type: str

    .. attribute: mobile_network_code

      The `mobile network code (MNC)
      <https://en.wikipedia.org/wiki/Mobile_country_code>`_ associated with the
      IP address and ISP.

      :type: str

    .. attribute:: organization

      The name of the organization associated with the IP address.

      :type: str

    .. attribute:: ip_address

      The IP address used in the lookup.

      :type: str

    .. attribute:: network

      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.

      :type: ipaddress.IPv4Network or ipaddress.IPv6Network
    ispmobile_country_codemobile_network_codeorganizationNrC   c                    sh   t  | ttt |d| _ttt |d| _ttt |d| _ttt |d| _	d S )Nr`   ra   rb   rc   )
r6   r#   r   r   r0   r   r`   ra   rb   rc   rF   r:   r!   r"   r#   q  s
    zISP.__init__r\   r!   r!   r:   r"   r_   .  s   
<r_   )r.   rH   abcr   typingr   r   r   r   r   r   Zgeoip2.recordsr   Zgeoip2.mixinsr	   r
   r1   r<   r>   r?   rP   rW   rZ   r]   r_   r!   r!   r!   r"   <module>   s    UX@@"P/("