
     hd                        d dl mZmZmZ d dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlmZmZmZ d dlmZ 	 d dlmZ n# e$ r Y nw xY w	 d dlZn# e$ r dZY nw xY w	 d dlZ	 ej        Zd e                    d          D             \  ZZZeeefdk     r ej                            d	ed
           dZn# e$ r Y nw xY w# e$ r dZY nw xY w	 d dl m!Z! n# e$ r dZ!Y nw xY wd dl"m#Z# d Z$d Z% G d de&          Z' G d de'          Z( G d de'          Z) G d de'          Z* G d de'          Z+dS )    )absolute_importdivisionprint_functionN)errorutilsix)RequestMetrics)urllibc                 ,    g | ]}t          |          S  )int).0is     N/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/stripe/http_client.py
<listcomp>r   '   s    BBB!s1vvBBB    .)r      r   zWarning: the Stripe library requires that your Python "requests" library be newer than version 0.8.8, but your "requests" library is version a#  . Stripe will fall back to an alternate HTTP library so everything should work. We recommend upgrading your "requests" library. If you have any questions, please contact support@stripe.com. (HINT: running "pip install -U requests" should upgrade your requests library to the latest version.))urlfetch)urlparsec                  b    t          t          t          j                    dz                      S )Ni  )r   roundtimer   r   r   _now_msr   B   s#    uTY[[4'(()))r   c                      t           rt          }nIt          rt          }n:t          rt
          }n+t          }t          j        dk     rt          j
        d            || i |S )N)      	   zWarning: the Stripe library is falling back to urllib2 because neither requests nor pycurl are installed. urllib2's SSL implementation doesn't verify server certificates. For improved security, we suggest installing requests.)r   UrlFetchClientrequestsRequestsClientpycurlPycurlClientUrllib2Clientsysversion_infowarningswarn)argskwargsimpls      r   new_default_http_clientr,   F   sr     	 	 i''M   4    r   c                   ~    e Zd ZdZdZdZddZddZ	 ddZd	 Z	dd
Z
ddZd Zd ZddZddZd Zd Zd Zd ZdS )
HTTPClientr         ?<   TNc                     || _         |r>t          |t                    r||d}t          |t                    st	          d          |r|                                nd | _        t          j                    | _	        d S )N)httphttpszqProxy(ies) must be specified as either a string URL or a dict() with string URL under the https and/or http keys.)
_verify_ssl_certs
isinstancestrdict
ValueErrorcopy_proxy	threadinglocal_thread_local)selfverify_ssl_certsproxys      r   __init__zHTTPClient.__init__`   s    !1 	%%% 8!&77eT** 	    ',5ejjlll&_..r   c                 6    |                      ||||d          S NFis_streaming_request_with_retries_internalr>   methodurlheaders	post_datas        r   request_with_retrieszHTTPClient.request_with_retriess   s*    22C)% 3 
 
 	
r   c                 6    |                      ||||d          S NTrD   rF   rH   s        r   request_stream_with_retriesz&HTTPClient.request_stream_with_retriesx   s,     22C)$ 3 
 
 	
r   c                 8   |                      |           d}	 t                      }	 |r|                     ||||          }n|                     ||||          }d }	n # t          j        $ r}
|
}	d }Y d }
~
nd }
~
ww xY w|                     ||	|          ri|	rt          j        d|	j	        z             |dz  }| 
                    ||          }t          j        d||||fz             t          j        |           n||                     ||           |S |	)Nr   Tz Encountered a retryable error %s   zBInitiating retry %i for request %s %s after sleeping %.2f seconds.)_add_telemetry_headerr   request_streamrequestr   APIConnectionError_should_retryr   log_infouser_message_sleep_time_secondsr   sleep_record_request_metrics)r>   rI   rJ   rK   rL   rE   num_retriesrequest_startresponseconnection_errore
sleep_times               r   rG   z)HTTPClient._request_with_retries_internal   s    	""7+++%	+#IIM
  M#22Wi   HH  $||FC)LLH#'  +      #$   !!(,<kJJ +# M:*78   q !55k8LL
1&Z@A   
:&&&&'00=III#O**K%	+s   5A A;-A66A;c                      t          d          )Nz.HTTPClient subclasses must implement `request`NotImplementedErrorrH   s        r   rU   zHTTPClient.request   s    !<
 
 	
r   c                      t          d          )Nz5HTTPClient subclasses must implement `request_stream`rd   rH   s        r   rT   zHTTPClient.request_stream   s    !C
 
 	
r   c                     ||                                  k    rdS ||j        S |\  }}}| d|v r|d         dk    rdS |d         dk    rdS |dk    rdS |dk    rdS dS )NFzstripe-should-retryfalsetrueTi  i  )_max_network_retriesshould_retry)r>   r_   api_connection_errorr]   _status_coderheaderss          r   rW   zHTTPClient._should_retry   s    $3355555
 (44#+ ; $9X$E$E-.'99u-.&88t #4 #4ur   c                     ddl m} |S )Nr   )max_network_retries)striperq   )r>   rq   s     r   rj   zHTTPClient._max_network_retries   s    ...... #"r   c                 r    |d S |\  }}}	 t          |d                   S # t          t          f$ r Y d S w xY w)Nzretry-after)r   KeyErrorr8   )r>   r_   rm   ro   s       r   _retry_after_headerzHTTPClient._retry_after_header   sW    4!1h	x.///*% 	 	 	44	s   ! 66c                 ,   t          t          j        d|dz
  z  z  t          j                  }|                     |          }t          t          j        |          }|                     |          pd}|t          j        k    rt          ||          }|S )Nr   rR   r   )minr.   INITIAL_DELAY	MAX_DELAY_add_jitter_timemaxru   MAX_RETRY_AFTER)r>   r]   r_   sleep_secondsretry_afters        r   rZ   zHTTPClient._sleep_time_seconds   s     $kAo(>? 
 

 --m<< J4mDD ..x88=A*444];;Mr   c                 B    |ddt          j        dd          z   z  z  }|S )Nr/   rR   r   )randomuniform)r>   r}   s     r   rz   zHTTPClient._add_jitter_time  s*     	FN1a$8$8 899r   c                     t          | j        dd           }t          j        r1|r1d|                                i}t          j        |          |d<   d S d S d S )Nlast_request_metricszX-Stripe-Client-Telemetry)getattrr=   rr   enable_telemetrypayloadjsondumps)r>   rK   r   	telemetrys       r   rS   z HTTPClient._add_telemetry_header  s    & 6 
  
 " 	I'; 	I&(<(D(D(F(FI 48:i3H3HG/000		I 	I 	I 	Ir   c                     |\  }}}d|v rAt           j        r7|d         }t                      |z
  }t          ||          | j        _        d S d S d S )Nz
Request-Id)rr   r   r   r	   r=   r   )r>   r_   r^   rm   ro   
request_idrequest_duration_mss          r   r\   z"HTTPClient._record_request_metrics  sh    !1h8##(?#!,/J")))m";6D/7 7D333 $###r   c                      t          d          )Nz,HTTPClient subclasses must implement `close`rd   r>   s    r   closezHTTPClient.close  s    !:
 
 	
r   TNN)__name__
__module____qualname__ry   rx   r|   rA   rM   rP   rG   rU   rT   rW   rj   ru   rZ   rz   rS   r\   r   r   r   r   r.   r.   [   s"       IMO/ / / /&
 
 
 
 /3
 
 
 
,+ ,+ ,+\
 
 
 


 
 
 

# # #J# # #      *  I I I  
 
 
 
 
r   r.   c                   F     e Zd ZdZd
 fd	ZddZddZd Zd Zd	 Z	 xZ
S )r!   r    P   Nc                 d     t          t          |           j        di | || _        || _        d S )Nr   )superr!   rA   _session_timeout)r>   timeoutsessionr*   	__class__s       r   rA   zRequestsClient.__init__#  s8    ,nd##,66v666r   c                 6    |                      ||||d          S rC   _request_internalrH   s        r   rU   zRequestsClient.request(  *    %%C)% & 
 
 	
r   c                 6    |                      ||||d          S rO   r   rH   s        r   rT   zRequestsClient.request_stream-  *    %%C)$ & 
 
 	
r   c                    i }| j         rt          j        |d<   nd|d<   | j        r
| j        |d<   |rd|d<   t	          | j        dd           $| j        pt          j                    | j        _	        	 	  | j        j	        j
        ||f||| j        d|}n$# t          $ r}t          d|          d }~ww xY w|r|j        }	n|j        }	|j        }
n,# t           $ r}|                     |           Y d }~nd }~ww xY w|	|
|j        fS )	NverifyFproxiesTstreamr   )rK   datar   a  Warning: It looks like your installed version of the "requests" library is not compatible with Stripe's usage thereof. (HINT: The most likely cause is that your "requests" library is out of date. You can fix that by running "pip install -U requests".) The underlying error was: )r4   rr   ca_bundle_pathr:   r   r=   r   r    Sessionr   rU   r   	TypeErrorrawcontentrn   	Exception_handle_request_errorrK   )r>   rI   rJ   rK   rL   rE   r*   resultra   r   rn   s              r   r   z RequestsClient._request_internal2  s   ! 	%%4F8$F8; 	, $F9 	$#F84%y$77?)-)L(:J:L:LD& 	*;+3; $" M       i 34!6    ) *
 !. ,KK 	* 	* 	* &&q))))))))	* V^33s6   3"B C 
B7 B22B77C 
C<C77C<c                    t          |t          j        j                  r+d}t	          |          j        dt          |          }d}nt          |t          j        j        t          j        j        f          r+d}t	          |          j        dt          |          }d}nt          |t          j        j	                  r+d}t	          |          j        dt          |          }d}nFd}dt	          |          j        d}t          |          r|d	t          |          z  }n|d
z  }d}t          j        |          d|dz   }t          j        ||          )NCould not verify Stripe's SSL certificate.  Please make sure that your network is not intercepting certificates.  If this problem persists, let us know at support@stripe.com.: FziUnexpected error communicating with Stripe.  If this problem persists, let us know at support@stripe.com.TzUnexpected error communicating with Stripe. It looks like there's probably a configuration issue locally.  If this problem persists, let us know at support@stripe.com.zA z was raisedz with error message z with no error message

(Network error: )rk   )r5   r    
exceptionsSSLErrortyper   r6   TimeoutConnectionErrorRequestExceptiontextwrapfillr   rV   )r>   ra   msgerrrk   s        r   r   z$RequestsClient._handle_request_errore  s    a,566 *	!&  #1gg...A7C LL ((*=*MN
 
  	!
& 
 #1gg...A7CLL8.?@@ 	!& 
 #1gg...A7C LL. C (,Aww'7'7'79C1vv 03q666;;// LmC   #EE&sFFFFr   c                 r    t          | j        dd            | j        j                                         d S d S )Nr   )r   r=   r   r   r   s    r   r   zRequestsClient.close  s>    4%y$77C&,,..... DCr   )r   Nr   r   r   r   namerA   rU   rT   r   r   r   __classcell__r   s   @r   r!   r!      s        D           

 
 
 


 
 
 

14 14 14f1G 1G 1Gf/ / / / / / /r   r!   c                   F     e Zd ZdZd fd	ZddZddZd Zd	 Zd
 Z	 xZ
S )r   r   TN7   c                     t          t          |                               ||           |rt          d          || _        || _        d S )Nr?   r@   zNo proxy support in urlfetch library. Set stripe.default_http_client to either RequestsClient, PycurlClient, or Urllib2Client instance to use a proxy.)r   r   rA   r8   r4   	_deadline)r>   r?   r@   deadliner   s       r   rA   zUrlFetchClient.__init__  sh    nd##,,-U 	- 	
 	
 	
  	J   "2 "r   c                 6    |                      ||||d          S rC   r   rH   s        r   rU   zUrlFetchClient.request  r   r   c                 6    |                      ||||d          S rO   r   rH   s        r   rT   zUrlFetchClient.request_stream  r   r   c                 \   	 t          j        |||| j        | j        |          }n2# t           j        $ r }|                     ||           Y d }~nd }~ww xY w|r=t          j                            t          
                    |j                            }n|j        }||j        |j        fS )N)rJ   rI   rK   validate_certificater   r   )r   fetchr4   r   Errorr   r   ioBytesIOr6   encoder   rn   rK   )	r>   rI   rJ   rK   rL   rE   r   ra   r   s	            r   r   z UrlFetchClient._request_internal  s    	/^ &*%;!
 
 
FF ~ 	/ 	/ 	/&&q#........	/  	%goocjj&@&@AAGGnG*FN::s   $' AAAc                 8   t          |t          j                  rd|d}n<t          |t          j                  rd}nt          |t          j                  rd}nd}t          j        |          dz   t          |          z   dz   }t          j	        |          )Nz6The Stripe library attempted to fetch an invalid URL (zg). This is likely due to a bug in the Stripe Python bindings. Please let us know at support@stripe.com.z0There was a problem retrieving data from Stripe.zThere was a problem receiving all of your data from Stripe.  This is likely due to a bug in Stripe. Please let us know at support@stripe.com.hUnexpected error communicating with Stripe. If this problem persists, let us know at support@stripe.com.r   r   )
r5   r   InvalidURLErrorDownloadErrorResponseTooLargeErrorr   r   r6   r   rV   )r>   ra   rJ   r   s       r   r   z$UrlFetchClient._handle_request_error  s    a122 	 	
 -0CC2 C 8122 	DCC89:: 
	< CG 
 mC  #99CFFBSH&s+++r   c                     d S r   r   r   s    r   r   zUrlFetchClient.close      r   )TNr   r   r   r   s   @r   r   r     s        D" " " " " "&
 
 
 


 
 
 

; ; ;., , ,2      r   r   c                   R     e Zd ZdZd fd	Zd ZddZddZd Zd	 Z	d
 Z
d Z xZS )r#   r"   TNc                    t          t          |                               ||           t          j                    | _        | j        r3| j        }t          j        |          D ]\  }}t          |          ||<   d S d S Nr   )
r   r#   rA   r"   Curl_curlr:   r   	iteritemsr   )r>   r?   r@   schemevaluer   s        r   rA   zPycurlClient.__init__  s    lD!!**-U 	+ 	
 	
 	

 []]
 ; 	0KE!$u!5!5 0 0 (f		0 	00 0r   c                     d|vri S |                     dd          d         }t          j        |          }t          d t	          j        t          |                    D                       S )Nz
rR   c              3   H   K   | ]\  }}|                                 |fV  d S r   lowerr   kvs      r   	<genexpr>z-PycurlClient.parse_headers.<locals>.<genexpr>	  s2      LLtq!QWWYYNLLLLLLr   )splitemailmessage_from_stringr7   r   r   )r>   r   raw_headersrK   s       r   parse_headerszPycurlClient.parse_headers  sg    Ijj++A.+K88LLs}T']]/K/KLLLLLLr   c                 6    |                      ||||d          S rC   r   rH   s        r   rU   zPycurlClient.request  r   r   c                 6    |                      ||||d          S rO   r   rH   s        r   rT   zPycurlClient.request_stream  r   r   c           	         t           j                                        }t           j                                        }| j                                         |                     |          }|r|j        r*| j                            t          j	        |j                   |j
        r*| j                            t          j        |j
                   |j        s|j        r4| j                            t          j        |j        d|j                   |dk    r&| j                            t          j        d           n|dk    rK| j                            t          j        d           | j                            t          j        |           n7| j                            t          j        |                                           | j                            t          j        t          j        |                     | j                            t          j        |j                   | j                            t          j        |j                   | j                            t          j        d           | j                            t          j        d           | j                            t          j        d           | j                            t          j        d t;          j        t?          |                    D                        | j         r0| j                            t          j!        tD          j#                   n%| j                            t          j$        d           	 | j        %                                 n1# t          j&        $ r}	| '                    |	           Y d }	~	nd }	~	ww xY w|r|(                    d	           |}
n'|)                                *                    d
          }
| j        +                    t          j,                  }| -                    |)                                *                    d
                    }|
||fS )N:getrR   post   r   c                 "    g | ]\  }}|d |S )r   r   r   s      r   r   z2PycurlClient._request_internal.<locals>.<listcomp>?  s'    HHH41aAAHHHr   Fr   utf-8).r   r   r   r   reset
_get_proxyhostnamesetoptr"   PROXYport	PROXYPORTusernamepasswordPROXYUSERPWDHTTPGETPOST
POSTFIELDSCUSTOMREQUESTupperURLutf8WRITEFUNCTIONwriteHEADERFUNCTIONNOSIGNALCONNECTTIMEOUTTIMEOUT
HTTPHEADERr   r   r7   r4   CAINFOrr   r   SSL_VERIFYHOSTperformr   r   seekgetvaluedecodegetinfoRESPONSE_CODEr   )r>   rI   rJ   rK   rL   rE   bro   r@   ra   rcontentrcodes               r   r   zPycurlClient._request_internal  s   GOO7??$$ 	
$$ 		~ @
!!&,???z @
!!&"2EJ???~  
!!'$~~~u~~>  
 U??Jfna0000vJfk1---Jf/;;;;Jf2FLLNNCCC 	
&*dinn555
&.888
&/@@@
&/1---
&/444
&."---
HH3=g+G+GHHH	
 	
 	
 ! 	<JfmV-BCCCCJf3U;;;	*J    | 	* 	* 	*&&q))))))))	*  	4FF1IIIHHzz||**733H
""6#788$$X%6%6%8%8%?%?%H%HII''s   *N N2N--N2c                 D   |j         d         t          j        t          j        t          j        fv rd}d}n.|j         d         t          j        t          j        fv rd}d}nd}d}t          j        |          dz   |j         d         z   d	z   }t          j
        ||
          )Nr   zCould not connect to Stripe.  Please check your internet connection and try again.  If this problem persists, you should check Stripe's service status at https://twitter.com/stripestatus, or let us know at support@stripe.com.Tr   Fr   r   rR   r   r   )r)   r"   E_COULDNT_CONNECTE_COULDNT_RESOLVE_HOSTE_OPERATION_TIMEOUTEDE_SSL_CACERTE_SSL_PEER_CERTIFICATEr   r   r   rV   )r>   ra   r   rk   s       r   r   z"PycurlClient._handle_request_errorV  s    6!9$)(
 
 
&   LLVAY6.0MNNN&  !LLG  !LmC  #99AF1IEK&sFFFFr   c                     | j         rY| j         }|r|                    d          d         nd }|r1|                    ||                    |dd                             S d S )Nr   r   )r:   r   r   )r>   rJ   r@   r   s       r   r   zPycurlClient._get_proxyv  sh    ; 	BKE*-7SYYs^^A&&4F Byy6!B$<)@)@AAAtr   c                     d S r   r   r   s    r   r   zPycurlClient.close~  r   r   r   r   )r   r   r   r   rA   r   rU   rT   r   r   r   r   r   r   s   @r   r#   r#     s        D0 0 0 0 0 0 M M M
 
 
 


 
 
 

?( ?( ?(BG G G@        r   r#   c                   F     e Zd ZdZd
 fd	ZddZddZd Zd Zd	 Z	 xZ
S )r$   zurllib.requestTNc                    t          t          |                               ||           d | _        | j        rJt
          j                            | j                  }t
          j                            |          | _        d S d S r   )	r   r$   rA   _openerr:   r
   rU   ProxyHandlerbuild_opener)r>   r?   r@   r   s      r   rA   zUrllib2Client.__init__  s~    mT""++-U 	, 	
 	
 	
 ; 	>N//<<E!>66u==DLLL	> 	>r   c                 6    |                      ||||d          S rC   r   rH   s        r   rU   zUrllib2Client.request  r   r   c                 6    |                      ||||d          S rO   r   rH   s        r   rT   zUrllib2Client.request_stream  r   r   c                    t           j        r/t          |t           j                  r|                    d          }t
          j                            |||          }dvr
fd|_        	 | j	        r| j	        
                    |          nt
          j                            |          }|r|}n|                                }|j        }	t          |                                          }n# t
          j        j        $ rF}
|
j        }	|
                                }t          |
                                          }Y d }
~
n@d }
~
wt
          j        j        t&          f$ r}
|                     |
           Y d }
~
nd }
~
ww xY wt          d t          j        t          |                    D                       }||	|fS )Nr   )r   r   c                  ,                                      S r   )r  )rI   s   r   <lambda>z1Urllib2Client._request_internal.<locals>.<lambda>  s    V\\^^ r   c              3   H   K   | ]\  }}|                                 |fV  d S r   r   r   s      r   r   z2Urllib2Client._request_internal.<locals>.<genexpr>  s2      JJTQ17799a.JJJJJJr   )r   PY3r5   string_typesr   r
   rU   Request
get_methodr(  openurlopenreadcoder7   infor   	HTTPErrorURLErrorr8   r   r   )r>   rI   rJ   rK   rL   rE   reqr_   r  r  ra   lhs    `          r   r   zUrllib2Client._request_internal  s   7 	2z)S-=>> 	2!((11In$$S)W==((3333CN	*
 <1!!#&&&^++C00   +##==??ME8==??++GG|% 	% 	% 	%FEvvxxH16688nnGGGGGG%z2 	* 	* 	*&&q))))))))	*JJS]4==-I-IJJJJJ""s%   -BC/ /F<EF"E<<Fc                     d}t          j        |          dz   t          |          z   dz   }t          j        |          )Nr   r   r   )r   r   r6   r   rV   )r>   ra   r   s      r   r   z#Urllib2Client._handle_request_error  sE    K 	 mC  #99CFFBSH&s+++r   c                     d S r   r   r   s    r   r   zUrllib2Client.close  r   r   r   r   r   r   s   @r   r$   r$     s        D> > > > > >
 
 
 


 
 
 

 #  #  #D, , ,      r   r$   ),
__future__r   r   r   r%   r   r'   r   r   r   r;   r   rr   r   r   r   stripe.request_metricsr	   stripe.six.movesr
   ImportErrorr"   r    __version__versionr   majorminorpatchstderrr  r   google.appengine.apir   stripe.six.moves.urllib.parser   r   r,   objectr.   r!   r   r#   r$   r   r   r   <module>rM     s_   @ @ @ @ @ @ @ @ @ @ 



            # # # # # # # # # # 1 1 1 1 1 1	''''''' 	 	 	D	MMMM   FFFOOO&BBw}}S/A/ABBBue
 5% 9,,J 6=WW?	 	 	 H        HHH0-------   HHH 3 2 2 2 2 2* * *! ! !*B
 B
 B
 B
 B
 B
 B
 B
Jz/ z/ z/ z/ z/Z z/ z/ z/zQ Q Q Q QZ Q Q QhN N N N N: N N NbB B B B BJ B B B B BsZ    A AAA A"!A"&C
 +*B? ?CC
CCC C)(C)