Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib
/
python3.5
/
site-packages
/
geoip2
/
__pycache__
/
File Content:
webservice.cpython-35.opt-1.pyc
�IX�! � @ s� d Z d d l Z d d l m Z d d l 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 m Z Gd d � d e � Z d S) a� ============================ WebServices Client API ============================ This class provides a client API for all the GeoIP2 Precision web service end points. The end points are Country, City, and Insights. Each end point returns a different set of data about an IP address, with Country returning the least data and Insights the most. Each web service end point is represented by a different model class, and these model classes in turn contain multiple record classes. The record classes have attributes which contain data about the IP address. If the web service does not return a particular piece of data for an IP address, the associated attribute is not populated. The web service may not return any information for an entire record, in which case all of the attributes for that record class will be empty. SSL --- Requests to the GeoIP2 Precision web service are always made with SSL. � N)�default_user_agent� )�compat_ip_address)�AddressNotFoundError�AuthenticationError�GeoIP2Error� HTTPError�InvalidRequestError�OutOfQueriesError�PermissionRequiredErrorc @ s� e Z d Z d Z d d d d d � Z d d d � Z d d d � Z d d d � Z d d � Z d d � Z d d � Z d d � Z d d � Z d d � Z d d � Z d d � Z d S)�Clienta� Creates a new client object. It accepts the following required arguments: :param user_id: Your MaxMind User ID. :param license_key: Your MaxMind license key. Go to https://www.maxmind.com/en/my_license_key to see your MaxMind User ID and license key. The following keyword arguments are also accepted: :param host: The hostname to make a request against. This defaults to "geoip.maxmind.com". In most cases, you should not need to set this explicitly. :param locales: This is list of locale codes. This argument will be passed on to record classes to use when their name properties are called. The default value is ['en']. The order of the locales is significant. When a record class has multiple names (country, city, etc.), its name property will return the name in the first locale that has one. Note that the only locale which is always present in the GeoIP2 data is "en". If you do not include this locale, the name property may end up returning None even when the record has an English name. Currently, the valid locale codes are: * de -- German * en -- English names may still include accented characters if that is the accepted spelling in English. In other words, English does not mean ASCII. * es -- Spanish * fr -- French * ja -- Japanese * pt-BR -- Brazilian Portuguese * ru -- Russian * zh-CN -- Simplified Chinese. zgeoip.maxmind.comNc C sP | d k r d g } | | _ t | � | _ | | _ d | | _ | | _ d S)zConstruct a Client.NZenzhttps://%s/geoip/v2.1)�_locales�str�_user_id�_license_key� _base_uri�_timeout)�selfZuser_idZlicense_key�host�locales�timeout� r �/webservice.py�__init__U s zClient.__init__�mec C s | j d t j j | � S)a* Call GeoIP2 Precision City endpoint with the specified IP. :param ip_address: IPv4 or IPv6 address as a string. If no address is provided, the address that the web service is called from will be used. :returns: :py:class:`geoip2.models.City` object �city)� _response_for�geoip2�modelsZCity)r � ip_addressr r r r g s zClient.cityc C s | j d t j j | � S)a( Call the GeoIP2 Country endpoint with the specified IP. :param ip_address: IPv4 or IPv6 address as a string. If no address is provided, the address that the web service is called from will be used. :returns: :py:class:`geoip2.models.Country` object �country)r r r ZCountry)r r r r r r s s zClient.countryc C s | j d t j j | � S)a5 Call the GeoIP2 Precision: Insights endpoint with the specified IP. :param ip_address: IPv4 or IPv6 address as a string. If no address is provided, the address that the web service is called from will be used. :returns: :py:class:`geoip2.models.Insights` object �insights)r r r ZInsights)r r r r r r! s zClient.insightsc C s� | d k r t t | � � } d j | j | | g � } t j | d | j | j f d d d d | j � i d | j �} | j d k r� | j | | � } | | d | j �S| j | | � d S)Nr �/Zauth�headersZAcceptzapplication/jsonz User-Agentr �� r )r r �joinr �requests�getr r �_user_agentr �status_code�_handle_successr � _handle_error)r �pathZmodel_classr �uri�response�bodyr r r r � s zClient._response_forc C s d t j t � f S)NzGeoIP2 Python Client v%s (%s))r �__version__r )r r r r r( � s zClient._user_agentc C sc y | j � SWnN t k r^ } z. t d t � d j | j � d | � � WYd d } ~ Xn Xd S)NzOReceived a 200 response for %(uri)s but could not decode the response as JSON: z, r$ )�json� ValueErrorr �localsr% �args)r r. r- �exr r r r* � s zClient._handle_successc C s~ | j } d | k o d k n r; | j | | | � n? d | k oR d k n rj | j | | � n | j | | � d S)Ni� i� iX )r) �_handle_4xx_status�_handle_5xx_status�_handle_non_200_status)r r. r- �statusr r r r+ � s zClient._handle_errorc C s | j s% t d t � | | � � n>