
    d?i                     |    S r SSKrSSKrSSKrSSKrSSKJr  SrSrSr	Sr
S	rS
rSrSrSrS rS rS rS rS rS rg)z
Utilities used in handlers.
    N   )SDK_VERSIONzhttps://ipinfo.iozhttps://api.ipinfo.io/litez4https://cdn.ipinfo.io/static/images/countries-flags/i  i   iQ 1      c                     SR                  [        R                  S   [        S9SS.nU(       a  0 UEUEnU (       a  SR                  U 5      US'   U$ )z(Build headers for request to IPinfo API.z*IPinfoClient/Python{version}/{sdk_version}r   )versionsdk_versionzapplication/json)z
user-agentacceptz	Bearer {}authorization)formatsysversion_infor   )access_tokencustom_headersheaderss      X/var/www/html/livechat/backend/venv/lib/python3.13/site-packages/ipinfo/handler_utils.pyget_headersr   *   sf     CII$$Q'[ J 
 %	G /W//#.#5#5l#C N    c                 J   SnSU ;   a  U R                  S5      nOSU ;   a  U R                  S5      nUR                  U5      =n(       a  XpS'   Xb;   U S'   [        U-   S-   U S'   UR                  U5      =n(       a  [        R                  " U5      U S'   UR                  U5      =n	(       a  [        R                  " U	5      U S	'   UR                  U5      =n
(       a  [        R                  " U
5      U S
'   U R                  S5      =n(       a  [	        U5      u  U S'   U S'   gg)z*
Format details given a countries object.
 country_codecountrycountry_nameisEUz.svgcountry_flag_urlcountry_flagcountry_currency	continentloclatitude	longitudeN)getCOUNTRY_FLAGS_URLcopydeepcopyread_coords)details	countrieseu_countriescountries_flagscountries_currencies
continentsr   r   flagcurrencyr   locations               r   format_detailsr1   <   s     L {{>2	g	{{9- !}}\22|2"."2GFO"3l"BV"KG""<00t0"&--"5'++L99x9&*mmH&="#NN<00y0#}}Y7;;u%%x%4?4I1
W[1 &r   c                     Su  pU (       a  [        U R                  S5      5      OSn[        U5      S:X  a  US   (       a  US   (       a	  US   US   p!X4$ )z
Given a location of the form `<lat>,<lon>`, returns the latitude and
longitude as a tuple.

Returns None for each tuple item if the form is invalid.
)NN,r   r   r   r   )tuplesplitlen)r0   latloncoordss       r   r'   r'   ]   sP     HC+3U8>>#&'F
6{aF1I&)!9fQiS8Or   c                    [         R                  R                  [         R                  R                  [        5      U 5      n [        U SS9 nUR                  5       nS S S 5        [        R                  " W5      $ ! , (       d  f       N$= f)Nutf8)encoding)	ospathjoindirname__file__openreadjsonloads)	json_filef	json_datas      r   read_json_filerI   k   sY    RWW__X6	BI	i&	)QFFH	 
* ::i   
*	)s   A;;
B	c                     U (       a  UeU$ )z;
Either throws `e` if `raise_on_fail` or else returns `v`.
 )raise_on_failevs      r   return_or_failrO   s   s     r   c                     U  S[          3$ )z9
Transforms a user-input key into a versioned cache key.
:)CACHE_KEY_VSN)ks    r   	cache_keyrT   }   s     S-!!r   )__doc__r%   rD   r=   r   r	   r   API_URLLITE_API_URLr$   BATCH_MAX_SIZECACHE_MAXSIZE	CACHE_TTLrR   REQUEST_TIMEOUT_DEFAULTBATCH_REQ_TIMEOUT_DEFAULTr   r1   r'   rI   rO   rT   rK   r   r   <module>r]      s~      	 
    , K    	     $JB!"r   