lf`dZddlZddlmZddlmZmZmZmZm Z ddl m Z Gdde eZ Gd d e eZ Gd d e ZGd de ZGdde ZGddeZGdde ZGdde ZGdde ZGdde ZGddeZGdde ZdS)z Records ======= N)ABCMeta)DictListOptionalTypeUnion)SimpleEqualityceZdZdZdefdZdS)Recordzz"Record.__repr__..s&DD1DDDDDD.())join__dict__items __module__ __class____name__)selfargss r__repr__zRecord.__repr__sVyyDDdm.A.A.C.CDDDDD/EEDN$;EEdEEEErN)rr __qualname____doc__strr rrrr r s<FFF#FFFFFFrr ) metaclassceZdZUdZeeefed<eeed< d deeedeeeefddfdZ e deefdZ dS) PlaceRecordzCAll records with :py:attr:`names` subclass :py:class:`PlaceRecord`.names_localesNlocalesr c4|dg}||_|i}||_dS)Nen)r(r')rr)r's r__init__zPlaceRecord.__init__ s, ?fG =E rcFtfdjDdS)z;Dict with locale codes as keys and localized name as value.c3^K|]'}|jv j|V(dSN)r'get)rrrs rrz#PlaceRecord.name..0s7QQ1djTZ^^A&&QQrN)nextr(rs`rnamezPlaceRecord.name,s-QQQQ QQQSWXXXrNN) rrr!r"rr#__annotations__rrr,propertyr3rrrr&r&sMM S>3i(,*.  $s)$ S#X'      YhsmYYYXYYYrr&c eZdZUdZeeed<eeed< d deeedeedeedee eefddf fd Z xZ S) Citya=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``. Attributes: .. attribute:: confidence A value from 0-100 indicating MaxMind's confidence that the city is correct. This attribute is only available from the Insights end point and the GeoIP2 Enterprise database. :type: int .. attribute:: geoname_id The GeoName ID for the city. :type: int .. attribute:: name The name of the city based on the locales list passed to the constructor. :type: unicode .. attribute:: names A dictionary where the keys are locale codes and the values are names. :type: dict confidence geoname_idNr)r'r c h||_||_t||dSr/)r9r:superr,)rr)r9r:r'_rs rr,z City.__init__]s3%$ %(((((rNNNN) rrr!r"rintr5rr#rr, __classcell__rs@rr8r83s$$L  (,$($(*. ) )$s)$ )SM )SM ) S#X' )  ) ) ) ) ) ) ) ) ) )rr8c eZdZUdZeeed<eeed< d deeedeedeedee eefddf fd Z xZ S) ContinentaContains data for the continent record associated with an IP address. This class contains the continent-level data associated with an IP address. Attributes: .. attribute:: code A two character continent code like "NA" (North America) or "OC" (Oceania). :type: unicode .. attribute:: geoname_id The GeoName ID for the continent. :type: int .. attribute:: name Returns the name of the continent based on the locales list passed to the constructor. :type: unicode .. attribute:: names A dictionary where the keys are locale codes and the values are names. :type: dict coder:Nr)r'r c h||_||_t||dSr/)rDr:r<r,)rr)rDr:r'r=rs rr,zContinent.__init__s3 $ %(((((rr>) rrr!r"rr#r5r?rrr,r@rAs@rrCrCjs##J 3- (,"$(*. ) )$s)$ )sm )SM ) S#X' )  ) ) ) ) ) ) ) ) ) )rrCceZdZUdZeeed<eeed<eed<eeed< d dee edeedeededeed ee eefd dffd Z xZ S) Countrya5Contains data for the country record associated with an IP address. This class contains the country-level data associated with an IP address. Attributes: .. attribute:: confidence A value from 0-100 indicating MaxMind's confidence that the country is correct. This attribute is only available from the Insights end point and the GeoIP2 Enterprise database. :type: int .. attribute:: geoname_id The GeoName ID for the country. :type: int .. attribute:: is_in_european_union This is true if the country is a member state of the European Union. :type: bool .. attribute:: iso_code The two-character `ISO 3166-1 `_ alpha code for the country. :type: unicode .. attribute:: name The name of the country based on the locales list passed to the constructor. :type: unicode .. attribute:: names A dictionary where the keys are locale codes and the values are names. :type: dict r9r:is_in_european_unioniso_codeNFr)r'r c ||_||_||_||_t ||dSr/)r9r:rHrIr<r,) rr)r9r:rHrIr'r=rs rr,zCountry.__init__sB%$$8!   %(((((r)NNNFNN) rrr!r"rr?r5boolr#rrr,r@rAs@rrGrGs11f  sm(,$($(%*"&*.))$s)$)SM)SM ) # ) 3- )S#X') ))))))))))rrGceZdZUdZeeed< d deeedeedeede d eed ee eefdeed dffd Z xZ S)RepresentedCountryaContains 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. Attributes: .. attribute:: confidence A value from 0-100 indicating MaxMind's confidence that the country is correct. This attribute is only available from the Insights end point and the GeoIP2 Enterprise database. :type: int .. attribute:: geoname_id The GeoName ID for the country. :type: int .. attribute:: is_in_european_union This is true if the country is a member state of the European Union. :type: bool .. attribute:: iso_code The two-character `ISO 3166-1 `_ alpha code for the country. :type: unicode .. attribute:: name The name of the country based on the locales list passed to the constructor. :type: unicode .. attribute:: names A dictionary where the keys are locale codes and the values are names. :type: dict .. attribute:: type A string indicating the type of entity that is representing the country. Currently we only return ``military`` but this could expand to include other types in the future. :type: unicode typeNFr)r9r:rHrIr'r c b||_t||||||dSr/)rNr<r,) rr)r9r:rHrIr'rNr=rs rr,zRepresentedCountry.__init__*s@   Z-A8U     r)NNNFNNN) rrr!r"rr#r5rr?rKrr,r@rAs@rrMrMs;;z 3-(,$($(%*"&*."  $s)$ SM SM  #  3-  S#X' sm            rrMc:eZdZUdZeeed<eeed<eeed<eeed<eeed<eeed<eeed< d deedeedeedeedeedeedeed d fd Z d S) LocationaContains 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``. Attributes: .. attribute:: average_income The average income in US dollars associated with the requested IP address. This attribute is only available from the Insights end point. :type: int .. attribute:: accuracy_radius The approximate accuracy radius in kilometers around the latitude and longitude for the IP address. This is the radius where we have a 67% confidence that the device using the IP address resides within the circle centered at the latitude and longitude with the provided radius. :type: int .. attribute:: latitude The approximate latitude of the location associated with the IP address. This value is not precise and should not be used to identify a particular address or household. :type: float .. attribute:: longitude The approximate longitude of the location associated with the IP address. This value is not precise and should not be used to identify a particular address or household. :type: float .. attribute:: metro_code The metro code of the location if the location is in the US. MaxMind returns the same metro codes as the `Google AdWords API `_. :type: int .. attribute:: population_density The estimated population per square kilometer associated with the IP address. This attribute is only available from the Insights end point. :type: int .. attribute:: time_zone The time zone associated with location, as specified by the `IANA Time Zone Database `_, e.g., "America/New_York". :type: unicode average_incomeaccuracy_radiuslatitude longitude metro_codepopulation_density time_zoneNr c h||_||_||_||_||_||_||_dSr/)rRrSrTrUrVrWrX) rrRrSrTrUrVrWrXr=s rr,zLocation.__init__s<-.  "$"4"r)NNNNNNN) rrr!r"rr?r5floatr#r,rrrrQrQ<s/@@DSM!!!c]"""uo   %%%})-)-$(%)$(,0#'##  #"##5/ # E? # SM #%SM#C=# ######rrQcHeZdZUdZeeed<ddeeddfdZdS)MaxMindzContains data related to your MaxMind account. Attributes: .. attribute:: queries_remaining The number of remaining queries you have for the end point you are calling. :type: int queries_remainingNr c ||_dSr/)r])rr]r=s rr,zMaxMind.__init__s!2rr/)rrr!r"rr?r5r,rrrr\r\s]   }$$$33(3-3333333rr\cpeZdZUdZeeed<eeed< ddeedeeddfdZdS)PostalaContains 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``. Attributes: .. attribute:: code The postal code of the location. Postal codes are not available for all countries. In some countries, this will only contain part of the postal code. :type: unicode .. attribute:: confidence A value from 0-100 indicating MaxMind's confidence that the postal code is correct. This attribute is only available from the Insights end point and the GeoIP2 Enterprise database. :type: int rDr9Nr c "||_||_dSr/)rDr9)rrDr9r=s rr,zPostal.__init__s $rr4) rrr!r"rr#r5r?r,rrrr`r`s6 3- GK%%SM%6>sm% %%%%%%rr`ceZdZUdZeeed<eeed<eeed< d deeedeedeedeedee eefddf fd Z xZ S) SubdivisionaBContains 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``. Attributes: .. attribute:: confidence This is a value from 0-100 indicating MaxMind's confidence that the subdivision is correct. This attribute is only available from the Insights end point and the GeoIP2 Enterprise database. :type: int .. attribute:: geoname_id This is a GeoName ID for the subdivision. :type: int .. attribute:: iso_code This is a string up to three characters long contain the subdivision portion of the `ISO 3166-2 code `_. :type: unicode .. attribute:: name The name of the subdivision based on the locales list passed to the constructor. :type: unicode .. attribute:: names A dictionary where the keys are locale codes and the values are names :type: dict r9r:rINr)r'r c v||_||_||_t||dSr/)r9r:rIr<r,)rr)r9r:rIr'r=rs rr,zSubdivision.__init__ s:%$   %(((((r)NNNNN) rrr!r"rr?r5r#rrr,r@rAs@rrcrcs--^  sm(,$($("&*. ) )$s)$ )SM )SM ) 3- ) S#X' )  ) ) ) ) ) ) ) ) ) )rrcceZdZdZdeddeeeddffd Zdeeeddffd Z e de fdZ xZ S) SubdivisionsaA 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 ctfd|D}t||}|S)Nc32K|]}tfi|VdSr/)rc)rrr)s rrz'Subdivisions.__new__..'s3HHa G11q11HHHHHHr)tupler<__new__)rgr) subdivisionssubobjsobjrs ` rrkzSubdivisions.__new__$sDHHHH<HHHHHggooc7++ rNcV||_tdSr/)r(r<r,)rr)rlrs rr,zSubdivisions.__init__+s(   rc\ |dS#t$rt|jcYSwxYw)zThe most specific (smallest) subdivision available. If there are no :py:class:`Subdivision` objects for the response, this returns an empty :py:class:`Subdivision`. :type: :py:class:`Subdivision` ) IndexErrorrcr(r2s r most_specificzSubdivisions.most_specific1sA .8O . . .t}-- - - - .s  ++)rrr!r"rrrr#rkr,r6rcrsr@rAs@rrfrfs   . !,4T#Y,? S *   .{ . . .X . . . . .rrfc-eZdZUdZeeed<eeed<eeed<eeed<eed<eed<eed<eed <eed <eed <eed <eed <eed<eeed<eeed<eeed<ee ed<eeed<eeed<eeed<eeed< ddeedeedeedeedededed ed ed ed ed ededeedeedeedeedeedee deedeeddf,dZ e dee e je jffdZdS)TraitsaContains data for the traits record associated with an IP address. This class contains the traits data associated with an IP address. This class has the following attributes: .. attribute:: autonomous_system_number The `autonomous system number `_ associated with the IP address. This attribute is only available from the City and Insights web service end points and the GeoIP2 Enterprise database. :type: int .. attribute:: autonomous_system_organization The organization associated with the registered `autonomous system number `_ for the IP address. This attribute is only available from the City and Insights web service end points and the GeoIP2 Enterprise database. :type: unicode .. attribute:: connection_type The connection type may take the following values: - Dialup - Cable/DSL - Corporate - Cellular Additional values may be added in the future. This attribute is only available in the GeoIP2 Enterprise database. :type: unicode .. attribute:: domain The second level domain associated with the IP address. This will be something like "example.com" or "example.co.uk", not "foo.example.com". This attribute is only available from the City and Insights web service end points and the GeoIP2 Enterprise database. :type: unicode .. attribute:: ip_address 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. :type: unicode .. attribute:: is_anonymous This is true if the IP address belongs to any sort of anonymous network. This attribute is only available from GeoIP2 Precision Insights. :type: bool .. attribute:: is_anonymous_proxy This is true if the IP is an anonymous proxy. See http://dev.maxmind.com/faq/geoip#anonproxy for further details. :type: bool .. deprecated:: 2.2.0 Use our our `GeoIP2 Anonymous IP database `_ instead. .. 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. This attribute is only available from GeoIP2 Precision Insights. :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). This attribute is only available from GeoIP2 Precision Insights. :type: bool .. attribute:: is_legitimate_proxy This attribute is true if MaxMind believes this IP address to be a legitimate proxy, such as an internal VPN used by a corporation. This attribute is only available in the GeoIP2 Enterprise database. :type: bool .. attribute:: is_public_proxy This is true if the IP address belongs to a public proxy. This attribute is only available from GeoIP2 Precision Insights. :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. This attribute is only available from GeoIP2 Precision Insights. :type: bool .. attribute:: is_satellite_provider This is true if the IP address is from a satellite provider that provides service to multiple countries. :type: bool .. deprecated:: 2.2.0 Due to the increased coverage by mobile carriers, very few satellite providers now serve multiple countries. As a result, the output does not provide sufficiently relevant data for us to maintain it. .. attribute:: is_tor_exit_node This is true if the IP address is a Tor exit node. This attribute is only available from GeoIP2 Precision Insights. :type: bool .. attribute:: isp The name of the ISP associated with the IP address. This attribute is only available from the City and Insights web service end points and the GeoIP2 Enterprise database. :type: unicode .. 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 .. attribute:: organization The name of the organization associated with the IP address. This attribute is only available from the City and Insights web service end points and the GeoIP2 Enterprise database. :type: unicode .. attribute:: static_ip_score An indicator of how static or dynamic an IP address is. The value ranges from 0 to 99.99 with higher values meaning a greater static association. For example, many IP addresses with a user_type of cellular have a lifetime under one. Static Cable/DSL IPs typically have a lifetime above thirty. This indicator can be useful for deciding whether an IP address represents the same user over time. This attribute is only available from GeoIP2 Precision Insights. :type: float .. attribute:: user_count The estimated number of users sharing the IP/network during the past 24 hours. For IPv4, the count is for the individual IP. For IPv6, the count is for the /64 network. This attribute is only available from GeoIP2 Precision Insights. :type: int .. attribute:: user_type The user type associated with the IP address. This can be one of the following values: * business * cafe * cellular * college * content_delivery_network * dialup * government * hosting * library * military * residential * router * school * search_engine_spider * traveler This attribute is only available from the Insights end point and the GeoIP2 Enterprise database. :type: unicode autonomous_system_numberautonomous_system_organizationconnection_typedomain is_anonymousis_anonymous_proxyis_anonymous_vpnis_hosting_provideris_legitimate_proxyis_public_proxyis_residential_proxyis_satellite_provideris_tor_exit_nodeisp ip_address organizationstatic_ip_score user_count user_type_network _prefix_lenNFnetwork prefix_lenr c ,||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ ||_ ||_||_||_||_||_||_||_dSr/)rvrwrxryrzr{r|r}r~rrrrrrrrrrrr)rrvrwrxryrzr{r|r}r~rrrrrrrrrrrrr=s rr,zTraits.__init__4s2)A%.L+. ("4 0#6 #6 .$8!%:" 0(."$$ %rc|j}t|tjtjfr|S||j}|j}||dS|d|}tj|d}||_|S)zThe network for the recordN/F)r isinstance ipaddress IPv4Network IPv6Networkrr ip_network)rrrrs rrzTraits.networkes- g 5y7LM N N N ?J)J!Z%7t#22j22G&w66 r)NNNNFFFFFFFFFNNNNNNNN)rrr!r"rr?r5r#rKrZr,r6rrrrrrrrruru@s[[z'sm+++$,SM111c]""" SM # 3-e_$$$ }sm#378<)- $"#(!&$)$) %%*&+!&!$(!%&*$(+/$(#'--&-&"*3--&)1 -&"# -&  -&  -&!-&-&"-&"-&-&#-& $-&-&c]-& SM!-&"##-&$sm%-&&SM'-&("%)-&*SM+-&,C=--&0 1-&-&-&-&b% (=y?T(T"UVXrru)r"rabcrtypingrrrrr geoip2.mixinsr r r&r8rCrGrMrQr\r`rcrjrfrurrrrs44444444444444((((((FFFFF^wFFFFYYYYY&GYYYY24)4)4)4)4);4)4)4)n3)3)3)3)3) 3)3)3)lG)G)G)G)G)kG)G)G)TO O O O O O O O d\#\#\#\#\#v\#\#\#~33333f333(#%#%#%#%#%V#%#%#%L@)@)@)@)@)+@)@)@)F%.%.%.%.%.5%.%.%.PtttttVtttttr