Viewing File: /opt/imunify360/venv/lib/python3.11/site-packages/geoip2/__pycache__/webservice.cpython-311.pyc



]jCzdZddlZddlZddlmZmZmZmZmZm	Z	m
Z
ddlZddlZddl
Z
ddlZ
ddlZddlZddlmZmZmZmZmZmZmZddlmZmZmZddlmZdejdejj Z!dejde
j"#Z$Gd	d
Z%Gdde%Z&Gd
de%Z'dS)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 web service are always made with SSL.

N)AnyDictcastListOptionalTypeUnion)AddressNotFoundErrorAuthenticationErrorGeoIP2Error	HTTPErrorInvalidRequestErrorOutOfQueriesErrorPermissionRequiredError)CityCountryInsights)	IPAddresszGeoIP2-Python-Client/ ceZdZUeed<eed<eed<eeed<eed<dededed	eeed
eddfd
Z	dede
defdZededede
fdZdededededef
dZdededededef
dZedededededeeeeeeff
dZedededeedefdZedededeedefdZdS)
BaseClient_account_id_host_license_key_locales_timeout
account_idlicense_keyhostlocalestimeoutreturnNc|dg}||_t|tr|nt||_||_d|d|_||_dS)zConstruct a Client.Nenzhttps://z/geoip/v2.1)r
isinstancebytesstrrr	_base_urir)selfrrrr r!s      q/builddir/build/BUILD/imunify360-venv-2.6.3/opt/imunify360/venv/lib/python3.11/site-packages/geoip2/webservice.py__init__zBaseClient.__init__Csd?fG
%Z77LJJS__	
(5D555


path
ip_addressc|dkrtj|}d|j|t	|gS)Nme/)	ipaddressr.joinr(r')r)r-r.s   r*_urizBaseClient._uriZs>"-j99Jxxs:?@@@r,bodyuric	tj|S#t$r6}td|dd|jzd||d}~wwxYw)NzReceived a 200 response for z, but could not decode the response as JSON: , )jsonloads
ValueErrorrr3args)r5r6exs   r*_handle_successzBaseClient._handle_success_s		:d###			s99RW--.

	s
A1AAstatuscontent_typecd|cxkrdkrnn|||||Sd|cxkrdkrnn||||S||||S)NiiiX)_exception_for_4xx_status_exception_for_5xx_status_exception_for_non_200_status)r)r@rAr5r6s     r*_exception_for_errorzBaseClient._exception_for_errorls&311&,cRRR&311&#tDDD11&#tDDDr,c|std|d|d|||S|ddkrtd|d|d||||S	tj|}d|vrBd	|vr>||d	|d||Std
|||S#t$rA}td|d|ddzd
|jz|||cYd}~Sd}~wwxYw)NzReceived a z error for z with no body.r:z for z with the following body: codeerrorzAResponse contains JSON but it does not specify code or error keysz but it did not include zthe expected JSON body: r8)	r
findr:r; _exception_for_web_service_errorgetr<r3r=)r)r@rAr5r6decoded_bodyr>s       r*rCz$BaseClient._exception_for_4xx_statusus	DfDDDDD	
V$$**PfPP3PP$PP	
	:d++L%%'\*A*A<< $$W--|/?/?/G/GQTS	
			NfNNNNN,-))BG$$%






	sB==
D6D=DDmessagerIc|dvrt|S|dvrt|S|dvrt|S|dkrt|St	||||S)N)IP_ADDRESS_NOT_FOUNDIP_ADDRESS_RESERVED)ACCOUNT_ID_REQUIREDACCOUNT_ID_UNKNOWNAUTHORIZATION_INVALIDLICENSE_KEY_REQUIREDUSER_ID_REQUIREDUSER_ID_UNKNOWN)INSUFFICIENT_FUNDSOUT_OF_QUERIESPERMISSION_REQUIRED)r
rrrr)rOrIr@r6s    r*rLz+BaseClient._exception_for_web_service_errorsBBB'000


'w///;;;$W---(((*7333"7D&#>>>r,c2td|d||||S)NzReceived a server error () for r
r@r6r5s   r*rDz$BaseClient._exception_for_5xx_statuss2;;;c;;	

	
r,c2td|d||||S)Nz(Received a very surprising HTTP status (r]r^r_s   r*rEz(BaseClient._exception_for_non_200_statuss2JvJJSJJ	

	
r,)__name__
__module____qualname__r'__annotations__rfloatintrr+rr4staticmethodrr?rrFrCr	rr
rrrrLr
rDrEr,r*rr<swJJJ3iOOO   	 
$s)$ 
 
    .AA)AAAAA

c




\
EE),E47E>AE	EEEE&&),&47&>A&	&&&&P???),?36?			
???\?6


%-c]
	


\



%-c]
	


\


r,rc\eZdZUdZejed<eeed<				dde	ded	ed
ee
ededeed
dffd
Zdde
d
efdZdde
d
efdZdde
d
efdZd
ejfdZdedeeeeeeefde
d
eeeeffdZdZd dZd!dZxZS)"AsyncClientaUAn async GeoIP2 client.

    It accepts the following required arguments:

    :param account_id: Your MaxMind account ID.
    :param license_key: Your MaxMind license key.

    Go to https://www.maxmind.com/en/my_license_key to see your MaxMind
    account 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". To use the GeoLite2 web service instead of GeoIP2
      Precision, set this to "geolite.info".
    :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.
    :param timeout: The timeout in seconds to use when waiting on the request.
      This sets both the connect timeout and the read timeout. The default is
      60.
    :param proxy: The URL of an HTTP proxy to use. It may optionally include
      a basic auth username and password, e.g.,
      ``http://username:password@host:port``.

    _existing_session_proxygeoip.maxmind.comN<rrrr r!proxyr"c`t|||||||_dSN)superr+rlr)rrrr r!ro	__class__s       r*r+zAsyncClient.__init__s=		
	
	
r,r0r.cKtt|dtjj|d{VS)Call 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

        cityNrr
_response_forgeoip2modelsr)r.s  r*rwzAsyncClient.citysH**66=3EzRRRRRRRR

	
r,cKtt|dtjj|d{VS)(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

        countryNrrryrzr{r|s  r*rzAsyncClient.country$sI$$Y
0EzRRRRRRRR

	
r,cKtt|dtjj|d{VS)Call the Insights endpoint with the specified IP.

        Insights is only supported by GeoIP2 Precision. The GeoLite2 web
        service does not support it.

        :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

        insightsNrrryrzr{r|s  r*rzAsyncClient.insights3sI$$Z1GTTTTTTTT

	
r,cKt|dsYtjtj|j|jdtdtj|j|_	|j	S)Nrkapplication/json)Accept
User-Agent)total)authheadersr!)
hasattraiohttp
ClientSession	BasicAuthrr_AIOHTTP_UA
ClientTimeoutrrkr)s r*_sessionzAsyncClient._sessionEsrt011	%,%:&t'79JKK#5[QQ-DMBBB&&&D"%%r,r-model_classcK|||}|d{V}|||jd{V4d{V}|j}|j}|d{V}	|dkr||||	|||	|}
||
|j	cdddd{VS#1d{VswxYwYdS)N)ror9r )
r4rrMrlr@rAtextrFr?r)r)r-rr.r6sessionresponser@rAr5rNs           r*ryzAsyncClient._response_forOsiij))

'''''' S<<<<<<<<	D	D	D	D	D	D	D_F#0L!((((((D}}//dCPPP//c::L;|T]CCC	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	D	D	D	DsA.C
C&)C&clKt|dr!|jd{VdSdS)fClose underlying session

        This will close the session and any associated connections.
        rkN)rrkclosers r*rzAsyncClient.close`sR
4,--	1(..00000000000	1	1r,c
K|Srqrhrs r*
__aenter__zAsyncClient.__aenter__hsr,exc_type	exc_value	tracebackc>K|d{VdSrqrr)rrrs    r*	__aexit__zAsyncClient.__aexit__ks,jjllr,rmNrnNr0)r"rjrNrNrNr"N)rarbrc__doc__rrrdrr'rfrrer+rrrwrrrrrr	rryrrr
__classcell__rts@r*rjrjs..`,,,,SM('+#	
$s)$
}
$

Y
$







	

W










h



$& 5&&&&DD4>4:tG}DED	D

wh&	'DDDD"111r,rjcVeZdZUdZejed<eee	e	fed<				dde
de	d	e	d
eee	dedee	d
dffd
Z
dded
efdZdded
efdZdded
efdZde	deeeeeeefded
eeeeffdZdZddZd dZxZS)!Clienta[A synchronous GeoIP2 client.

    It accepts the following required arguments:

    :param account_id: Your MaxMind account ID.
    :param license_key: Your MaxMind license key.

    Go to https://www.maxmind.com/en/my_license_key to see your MaxMind
    account 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". To use the GeoLite2 web service instead of GeoIP2
      Precision, set this to "geolite.info".
    :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.
    :param timeout: The timeout in seconds to use when waiting on the request.
      This sets both the connect timeout and the read timeout. The default is
      60.
    :param proxy: The URL of an HTTP proxy to use. It may optionally include
      a basic auth username and password, e.g.,
      ``http://username:password@host:port``.


    r_proxiesrmNrnrrrr r!ror"c t|||||tj|_|j|jf|j_d|jjd<t|jjd<|	d|_
dSd|i|_
dS)Nrrrhttps)rrr+requestsSessionrrrrr_REQUEST_UArrss       r*r+zClient.__init__s	[$III (**
".0AB
*<
h'.9
l+= DMMM$e,DMMMr,r0r.cttt|dtjj|S)rvrwrxr|s  r*rwzClient.citys+D$,,VV]5GTTUUUr,cttt|dtjj|S)r~rrr|s  r*rzClient.countrys2T''	6=3H*UU

	
r,cttt|dtjj|S)rrrr|s  r*rzClient.insightss2d((V]5KZXX

	
r,r-rc>|||}|j||j|j}|j}|jd}|j}|dkr||||||	||}	||	|j
S)N)proxiesr!zContent-Typer9r)r4rrMrrstatus_coderrrFr?r)
r)r-rr.r6rr@rAr5rNs
          r*ryzClient._response_forsiij))=$$S$-$WW%'7}S==++FL$LLL++D#66{<????r,c8|jdS)rN)rrrs r*rzClient.closes
	

r,c|Srqrhrs r*	__enter__zClient.__enter__sr,rrrc.|dSrqrrs    r*__exit__zClient.__exit__s

r,rr)r"rr)rarbrcrrrrdrrr'rfrrer+rrrwrrrrr	rryrrrrrs@r*rros//btCH~&&&&('+#----	-
$s)$-
-}-
------&
V
Vy
VD
V
V
V
V

)
w





9




"@@4>4:tG}DE@	@

wh&	'@@@@ r,r)(rr2r:typingrrrrrrr	raiohttp.httprrequests.utilsrz
geoip2.models
geoip2.errorsr
rrr
rrrrrrgeoip2.typesr__version__httpSERVER_SOFTWARErutilsdefault_user_agentrrrjrrhr,r*<module>rs6??????????????????



2111111111""""""PF.OO1MOO
WF.VV1R1R1T1TVV
Q
Q
Q
Q
Q
Q
Q
Q
h\\\\\*\\\~NNNNNZNNNNNr,
Back to Directory File Manager