
    d?i                         S r SSKJrJr  SSKrSSKJr  SSKJr  SSK	J
r
  SSKJr  SS	KJrJrJrJrJr  SS
KJr  SSKJr  SSKJrJrJrJrJr   " S S5      rg)zQ
Main API client asynchronous handler for fetching data from the IPinfo service.
    )IPv4AddressIPv6AddressN   )APIError)DefaultCache)Details)RequestQuotaExceededError)CACHE_MAXSIZE	CACHE_TTLLITE_API_URLREQUEST_TIMEOUT_DEFAULT	cache_key)handler_utils)is_bogon)
continents	countriescountries_currencieseu_countriescountries_flagsc                   >    \ rS rSrSrS
S jrS rS rSS jrS r	S	r
g)AsyncHandlerLite   z
Allows client to request data for specified IP address asynchronously using the Lite API.
Instantiates and maintains access to cache.
Nc                    Xl         UR                  S5      =(       d    [        U l        UR                  S5      =(       d    [        U l        UR                  S5      =(       d    [        U l        UR                  S5      =(       d    [
        U l        UR                  S5      =(       d    [        U l        UR                  S0 5      U l        SU R                  ;  a  [        U R                  S'   SU l	        S	U;   a  US	   U l
        O@UR                  S
0 5      nSU;  a	  [        US'   SU;  a	  [        US'   [        S0 UD6U l
        UR                  SS5      U l        g)zQ
Initialize the Handler object with country name list and the
cache initialized.
r   r   r   r   	continentrequest_optionstimeoutNcachecache_optionsmaxsizettlheaders )access_tokengetr   r   r   r   r   r   r   httpsessr   r
   r   r   r!   )selfr#   kwargsr   s       ]/var/www/html/livechat/backend/venv/lib/python3.13/site-packages/ipinfo/handler_lite_async.py__init__AsyncHandlerLite.__init__%   s/   
 )  K0=I #JJ~6F,  &zz*;<O JJ-.F2F 	!
 !**[1?Z  &zz*;R@D000.ED  +  fDJ"JJ;M-+8i(M)'0e$%66DJ zz)T2    c                 @   #    U R                  5       I Sh  vN   g N7f)z
Initializes internal aiohttp connection pool.

This isn't _required_, as the pool is initialized lazily when needed.
But in case you require non-lazy initialization, you may await this.

This is idempotent.
N)_ensure_aiohttp_readyr&   s    r(   initAsyncHandlerLite.initS   s      ((***s   c                    #    U R                   (       a*  U R                   R                  5       I Sh  vN   SU l         gg N7f)z
Deinitialize the async handler.

This is required in case you need to let go of the memory/state
associated with the async handler in a long-running process.

This is idempotent.
N)r%   closer.   s    r(   deinitAsyncHandlerLite.deinit^   s3      ==--%%''' DM 's   /A?Ac                   #    U R                  5         [        U[        5      (       d  [        U[        5      (       a  UR                  nU(       a   [        U5      (       a  USS.n[        U5      $  U R                  [        U5         n[        U5      $ ! [         a     Of = fU(       a  [         SU 3O[         S3n[        R                  " U R                  U R                  5      n0 nUb  X'S'   U R                  R                   " U4SU0UD6 ISh  vN  nUR"                  S:X  a
  [%        5       eUR"                  S	:  ad  UR"                  n	UR                  R!                  S
5      n
U
S:X  a  UR'                  5       I Sh  vN  nOSUR)                  5       0n[+        X5      eUR'                  5       I Sh  vN  nSSS5      ISh  vN    O! , ISh  vN  (       d  f       O= f[        R,                  " WU R.                  U R0                  U R2                  U R4                  U R6                  5        X0R                  [        U5      '   [        U5      $ 7f)z9Get details for specified IP address as a Details object.T)ipbogon/z/meNr   r!   i  i  zContent-Typezapplication/jsonerror)r-   
isinstancer   r   explodedr   r   r   r   KeyErrorr   r   get_headersr#   r!   r%   r$   statusr	   jsontextr   format_detailsr   r   r   r   r   )r&   
ip_addressr   detailscached_ipaddrurlr!   req_optsresp
error_codecontent_typeerror_responses               r(   
getDetailsAsyncHandlerLite.getDetailsk   s    ""$
 j+..*Z2U2U#,,J (:..'$7G7##	 JJy'<=M=)) 		 1;a
|,<.PS@T++D,=,=t||L")Y==$$SF'FXFF${{c!/11{{c!![[
#||//?#55+/99;%6%6N&-tyy{%;Nz:: IIK''G GFFFFF 	$$NN  %%OO	
 -4

9Z()ws   A.I1"B I
B!I B!!A5IDIA+GF	6G=G >GIGIG,GG,(A6Ic                     U R                   (       a  g[        R                  " U R                  S   S9n[        R                  " US9U l         g)z.Ensures aiohttp internal state is initialized.Nr   )total)r   )r%   aiohttpClientTimeoutr   ClientSession)r&   r   s     r(   r-   &AsyncHandlerLite._ensure_aiohttp_ready   s9    ==''d.B.B9.MN--g>r+   )
r#   r   r   r   r   r   r   r!   r%   r   )N)NN)__name__
__module____qualname____firstlineno____doc__r)   r/   r3   rK   r-   __static_attributes__r"   r+   r(   r   r      s"    
,3\	+!4 l?r+   r   )rW   	ipaddressr   r   rO   r9   r   cache.defaultr   rC   r   
exceptionsr	   r   r
   r   r   r   r    r7   r   datar   r   r   r   r   r   r"   r+   r(   <module>r^      sF    /   '  1    H? H?r+   