
    \jh                     p   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
 defdZ e j                  d      Zd dlZ ed      Zg d	ZeeeefZg d
Zdede j0                  defdZdedede j0                  defdZd Zd Z G d d      Z G d de      Zd Z d Z!d Z"ddZ#d Z$d Z%dedefdZ&y)     N)Any)_base_headers)urlparse
urlunparsereturnc                  B    t        t        j                         dz        S )Ni  )inttime     </root/env/lib/python3.12/site-packages/ldclient/impl/util.pycurrent_time_millisr      s    tyy{T!""r   zldclient.utill   )	keyipcountryemail	firstNamelastNameavatarname	anonymous)  i  i  applicationloggerc                 x    t        | j                  dd      d|      t        | j                  dd      d|      dS )Nid version)r   r   )validate_application_valueget)r   r   s     r   validate_application_infor!      s;    (r)BD&Q-kooi.LiY_` r   valuer   c                     t        | t              syt        |       dkD  r|j                  d|z         yt	        j
                  d|       r|j                  d|z         y| S )Nr   @   zHValue of application[%s] was longer than 64 characters and was discardedz[^a-zA-Z0-9._-]zGValue of application[%s] contained invalid characters and was discarded)
isinstancestrlenwarningresearch)r"   r   r   s      r   r   r   $   sZ    eS!
5zBadhhi	yy#U+`cgghLr   c                 B    t        |       }|j                  ddi       |S )NzContent-Typezapplication/json)r   update)configbase_headerss     r   _headersr/   2   s&     (L);<=r   c                  4   dt         j                  v rdd l} t        | d      sy | j                  j                  d      ry | j                  j                  d      (t        | j                  j                  d            dkD  ry t        j                  d       y y )Nuwsgir   optzenable-threadsthreads   zThe LaunchDarkly client requires the 'enable-threads' or 'threads' option be passed to uWSGI. To learn more, read https://docs.launchdarkly.com/sdk/server-side/python#configuring-uwsgi)	sysmodulesr1   hasattrr2   r    r	   logerror)r1   s    r   check_uwsgir:   7   sz    #++ue$99==)*99==#/C		i8P4QTU4U		 q 	r r   c                       e Zd ZddZd Zy)EventNc                 <    || _         || _        || _        || _        y N)dataeventr   retry)selfr?   r@   event_idrA   s        r   __init__zEvent.__init__H   s    	

r   c                     | j                   S r>   )r?   )rB   argskwargss      r   __str__zEvent.__str__N   s    yyr   )r   messageNN)__name__
__module____qualname__rD   rH   r   r   r   r<   r<   G   s    r   r<   c                   .     e Zd Z fdZed        Z xZS )UnsuccessfulResponseExceptionc                 @    t         t        |   d|z         || _        y )NzHTTP error %d)superrN   rD   _status)rB   status	__class__s     r   rD   z&UnsuccessfulResponseException.__init__S   s    +T;Of<TUr   c                     | j                   S r>   )rQ   )rB   s    r   rR   z$UnsuccessfulResponseException.statusW   s    ||r   )rJ   rK   rL   rD   propertyrR   __classcell__)rS   s   @r   rN   rN   R   s      r   rN   c                 L    | j                   dk\  rt        | j                         y )Nr   )rR   rN   )resps    r   throw_if_unsuccessful_responserY   \   s"    {{c+DKK88 r   c                 (    | dk\  r| dk  r| t         v S y)Nr   i  T)_retryable_statusesrR   s    r   is_http_error_recoverabler]   a   s    }#,,,r   c                 .    d| | dk(  s| dk(  rdfz  S dfz  S )NzHTTP error %d%si  i  z (invalid SDK key)r   r   r\   s    r   http_error_descriptionr_   g   s.    3RX\_R_(<iiifhiiir   c                 H    dt        |       d|dt        |       r|S dS )Nz	Received z for z - zgiving up permanently)r_   r]   )rR   contextretryable_messages      r   http_error_messagerc   k   s9    v&6v>[
 
 E\[
 
r   c                     |r|t        |      }|r't        |      st        j                  d| d|       yt        j	                  d| d|d|       y)NzError z (giving up permanently): Fz (z): T)r_   r]   r8   r9   r(   )error_contextstatus_code
error_descrecoverable_messages       r   %check_if_error_is_recoverable_and_logri   s   sJ    
*+K8
4[A		M:VWKK}6I:VWr   c                     | y d }|D ]G  }| j                  |      }|t        |t              r(|| j                         }t        |      ||<   I || S |S r>   )r    r%   r&   copy)attrdictattrsnewdictattrvals        r   stringify_attrsrq   }   si    G %ll4 ?:c3#7"--/HGDM% 83G3r   urlc                     t        |       }|j                  | S |j                  j                  |j                  d      }|j	                  |      }t        |      S )z
    Replace any embedded password in the provided URL with 'xxxx'. This is
    useful for ensuring sensitive information included in a URL isn't logged.
    xxxx)netloc)r   passwordru   replace_replacer   )rr   partsupdateds      r   redact_passwordr{      sQ    
 SME~~
ll""5>>6:GNN'N*Eer   )z
will retry)'loggingr)   r5   r
   typingr   ldclient.impl.httpr   urllib.parser   r   r	   r   	getLoggerr8   queuefloat__LONG_SCALE____BUILTINS__r&   bool__BASE_TYPES__r[   dictLoggerr!   r   r/   r:   r<   	ExceptionrN   rY   r]   r_   rc   ri   rq   r{   r   r   r   <module>r      s    	 
   , -#S # g(  ()H uc4( & 4  D c  gnn QT 
r  I 9
j

4  r   