o
    Bi                     @   s`  U d dl 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 d dlZd dlmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZm Z  d dl!m"Z"m#Z#m$Z$m%Z%m&Z& zd dl'm(Z) d dl*m+Z, W n	 e-y   Y nw zd dl.Z.W n e-y   dZ.Y nw zd dl/Z/d dl0Z0d d	l/m1Z2 d d
l/m3Z4 W n e-y   dZ/dZ0Y nw zd dl5Z5d dl5m6Z7 d dl5m8Z9 W n e-y   dZ5Y nw zd dl:Z:d dl:m;Z< W n e-y   dZ:Y nAw z"e=e>d< e:j?Z@eAe>d< eAe>d< eAe>d< dd e@BdD \ZCZDZEW n
 eFy#   Y nw eCeDeEfdk r7ejGHde@f  dZ:zd dlImJZJ W n e-yK   dZJY nw d dlKmLZLmMZM dd ZNdededdfdd ZOdededdfd!d"ZPG d#d deQZRG d$d% d%eRZSG d&d' d'eRZTG d(d) d)eRZUG d*d+ d+eRZVG d,d- d-eRZWG d.d/ d/eRZXG d0d1 d1eRZYdS )2    )BytesION)HTTPResponse)_util)RequestMetrics)APIConnectionError)AnyDictIterableListMappingMutableMappingOptionalTupleClassVarUnioncastoverloadAsyncIterable)LiteralNoReturn	TypedDict	AwaitableNever)Timeout)Client)ClientTimeout)StreamReader)Sessionversionmajorminorpatchc                 C   s   g | ]}t |qS  )int).0ir"   r"   S/var/www/html/Trade-python/venv/lib/python3.10/site-packages/stripe/_http_client.py
<listcomp>Y   s    r'   .)r      r)   a  Warning: the Stripe library requires that your Python "requests" library be newer than version 0.8.8, but your "requests" library is version %s. 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)urlparseParseResultc                   C   s   t tt d S )Ni  )r#   roundtimer"   r"   r"   r&   _now_mst   s   r/   argskwargsreturn
HTTPClientc                  O   s0   t rt}ntr
t}ntrt}nt}|| i |S N)r*   UrlFetchClientrequestsRequestsClientpycurlPycurlClientUrllib2Clientr0   r1   implr"   r"   r&   new_default_http_clientx   s   r=   c                  O   s&   t rt}ntr
t}nt}|| i |S r4   )httpxHTTPXClientaiohttpAIOHTTPClientNoImportFoundAsyncClientr;   r"   r"   r&   new_http_client_async_fallback   s   rC   c                   @   s  e Zd ZU ee ed< G dd deZdZdZ	dZ
ee ed< eed< 			
	
dGdedeeeef  ded  fddZdeeeeeeeef  f  dee dedee fddZ	
dHdeeeeeeef f  fddZ	
dHdedeeeeeeef f  fddZdefddZdeeef deeef fdd Zd!d" Z	
	
dId
d#d$ed%edeeef d&edee d'eee  deeeeeef f fd(d)Z	
	
dId
d#d$ed%edeeef d'eee  deeeeeef f f
d*d+Zd
d#d$ed%edeeef d&ed,edee d'eee  deeeeeef f fd-d.Z	
dHd
d#d$ed%edeeeef  d&ed'eee  deeeeeef f fd/d0Z	
dHd
d#d$ed%edeeeef  d&ed'eee  deeeeeef f fd1d2Z d3d4 Z!	
	
dId
d#d$ed%edeeef dee d'eee  deeeef fd5d6Z"	
	
dId
d#d$ed%edeeef d'eee  dee#e$ eef f
d7d8Z%e&d
d#d$ed%edeeef d,e'd9 dee d'eee  deeeeeef f fd:d;Z(e&d
d#d$ed%edeeef d,e'd	 dee d'eee  dee#e$ eeeef f fd<d;Z(d
d#d$ed%edeeef d,edee d'eee  deeeeeef f fd=d;Z(	
dHd$ed%edeeef dee$eeeef f fd>d?Z)	
dHd$ed%edeeef dee#e$ eeeef f fd@dAZ*dBdC Z+dDede,d
 fdEdFZ-d
S )Jr3   namec                   @   &   e Zd ZU ee ed< ee ed< dS )zHTTPClient._ProxyhttphttpsN)__name__
__module____qualname__r   str__annotations__r"   r"   r"   r&   _Proxy      
 rM            ?<   _proxy_verify_ssl_certsTNverify_ssl_certsproxyasync_fallback_clientc                 C   sV   || _ |rt|tr||d}t|tstd|r| nd | _|| _t	 | _
d S )N)rF   rG   zqProxy(ies) must be specified as either a string URL or a dict() with string URL under the https and/or http keys.)rS   
isinstancerK   dict
ValueErrorcopyrR   _async_fallback_client	threadinglocal_thread_local)selfrT   rU   rV   r"   r"   r&   __init__   s   


	zHTTPClient.__init__responseapi_connection_errornum_retriesmax_network_retriesc                 C   s   |d ur|nd}||krdS |d u r|d usJ |j S |\}}}|d ur8d|v r8|d dkr0dS |d dkr8dS |dkr>dS |dkrDdS dS )	Nr   Fzstripe-should-retryfalsetrueTi  i  should_retry)r_   ra   rb   rc   rd   _status_coderheadersr"   r"   r&   _should_retry   s$   
zHTTPClient._should_retryc              	   C   s>   |d u rd S |\}}}zt |d W S  ttfy   Y d S w )Nzretry-after)r#   KeyErrorrY   )r_   ra   ri   rk   r"   r"   r&   _retry_after_header   s   
zHTTPClient._retry_after_headerc                 C   sV   t tjd|d   tj}| |}ttj|}| |pd}|tjkr)t||}|S )NrO      r   )minr3   INITIAL_DELAY	MAX_DELAY_add_jitter_timemaxrn   MAX_RETRY_AFTER)r_   rc   ra   sleep_secondsretry_afterr"   r"   r&   _sleep_time_seconds   s   


zHTTPClient._sleep_time_secondsrv   c                 C   s   |ddt dd  9 }|S )NrP   ro   r   )randomuniform)r_   rv   r"   r"   r&   rs   
  s   zHTTPClient._add_jitter_timeheadersr2   c                 C   sB   t | jdd }tjr|rd| i}t|}t||d< |S |S )Nlast_request_metricszX-Stripe-Client-Telemetry)getattrr^   stripeenable_telemetrypayloadrX   jsondumps)r_   r{   r|   	telemetryretr"   r"   r&   _add_telemetry_header  s   
z HTTPClient._add_telemetry_headerc                 C   sH   |\}}}d|v r t jr"|d }t | }t|||d| j_d S d S d S )Nz
Request-Idusage)r~   r   r/   r   r^   r|   )r_   ra   request_startr   ri   rk   
request_idrequest_duration_msr"   r"   r&   _record_request_metrics  s   

z"HTTPClient._record_request_metrics)_usagemethodurl	post_datar   c             	   C      | j ||||d||dS NFis_streamingrd   r   _request_with_retries_internalr_   r   r   r{   r   rd   r   r"   r"   r&   request_with_retries(     
zHTTPClient.request_with_retriesc             	   C   r   NTr   r   r   r"   r"   r&   request_stream_with_retries<  r   z&HTTPClient.request_stream_with_retriesr   c             
   C   s   |  |}d}	 t }	z|r| ||||}
n| ||||}
d }W n ty8 } z
|}d }
W Y d }~nd }~ww | |
|||rf|rKtd|j  |d7 }| 	||
}td||||f  t
| n|
d urt| j|
|	|d |
S |d uszJ |qNr   Tz Encountered a retryable error %sro   zBInitiating retry %i for request %s %s after sleeping %.2f seconds.r   )r   r/   request_streamrequestr   rl   r   log_infouser_messagerx   r.   sleepr   r_   r   r   r{   r   r   rd   r   rc   r   ra   connection_errore
sleep_timer"   r"   r&   r   P  sR   

z)HTTPClient._request_with_retries_internalc                C      t d)Nz.HTTPClient subclasses must implement `request`NotImplementedErrorr_   r   r   r{   r   r   r"   r"   r&   r        	zHTTPClient.requestc                C   r   )Nz5HTTPClient subclasses must implement `request_stream`r   r   r"   r"   r&   r     r   zHTTPClient.request_streamc                 C   r   )Nz,HTTPClient subclasses must implement `close`r   r_   r"   r"   r&   close     zHTTPClient.closec             	          | j ||||d||dI d H S r   $_request_with_retries_internal_asyncr   r"   r"   r&   request_with_retries_async     
z%HTTPClient.request_with_retries_asyncc             	      r   r   r   r   r"   r"   r&   !request_stream_with_retries_async  r   z,HTTPClient.request_stream_with_retries_asyncFc                      d S r4   r"   r_   r   r   r{   r   r   rd   r   r"   r"   r&   r        z/HTTPClient._request_with_retries_internal_asyncc                   r   r4   r"   r   r"   r"   r&   r     r   c             
      s  |  |}d}	 t }	z|r| ||||I d H }
n| ||||I d H }
d }W n ty? } z
|}d }
W Y d }~nd }~ww | |
|||rp|rRtd|j  |d7 }| 	||
}td||||f  | 
|I d H  n|
d ur~| j|
|	|d |
S |d usJ |q	r   )r   r/   request_stream_asyncrequest_asyncr   rl   r   r   r   rx   sleep_asyncr   r   r"   r"   r&   r     sX   


c                    ,   | j d ur| j ||||I d H S td)Nz4HTTPClient subclasses must implement `request_async`)r[   r   r   r_   r   r   r{   r   r"   r"   r&   r   )     

zHTTPClient.request_asyncc                    r   )Nz;HTTPClient subclasses must implement `request_stream_async`)r[   r   r   r   r"   r"   r&   r   4  r   zHTTPClient.request_stream_asyncc                    s$   | j d ur| j  I d H S td)Nz2HTTPClient subclasses must implement `close_async`)r[   close_asyncr   r   r"   r"   r&   r   ?  s   
zHTTPClient.close_asyncsecsc                 C   s   | j d ur| j |S td)Nz,HTTPClient subclasses must implement `sleep`)r[   r   r   r_   r   r"   r"   r&   r   F  s
   
zHTTPClient.sleep_asyncTNNr4   )NN).rH   rI   rJ   r   rK   rL   r   rM   rr   rq   ru   r   boolr   r`   r   r   r#   r   r   rl   rn   rx   floatrs   r   r   r
   r   r   r   r   r   r   r   r   bytesr   r   r   r   r   r   r   r   r   r"   r"   r"   r&   r3      s  
 

0






	


	


	

@






	


	



	



	


	

>



c                       s  e Zd ZdZ					d deded ded	eeee	j
f  d
ee	 f
 fddZ	d!dededeeeef  deeeeeef f fddZ	d!dededeeeef  deeeeeef f fddZedededeeeef  ded deeeeeef f f
ddZedededeeeef  ded deeeeeef f f
ddZdededeeeef  dedeeeef eeeef f f
ddZdedefddZdd Z  ZS )"r7   r6   P   NTtimeoutsessionRequestsSessionrT   rU   rV   c                    s8   t t| j|||d || _|| _td usJ t| _d S NrT   rU   rV   )superr7   r`   _session_timeoutr6   )r_   r   r   rT   rU   rV   r1   	__class__r"   r&   r`   Q  s   
	
zRequestsClient.__init__r   r   r{   r2   c                 C      | j ||||ddS NFr   _request_internalr   r"   r"   r&   r   e     
zRequestsClient.requestc                 C   r   NTr   r   r   r"   r"   r&   r   p  r   zRequestsClient.request_streamr   c                 C      d S r4   r"   r_   r   r   r{   r   r   r"   r"   r&   r   {     z RequestsClient._request_internalFc                 C   r   r4   r"   r   r"   r"   r&   r     r   c              
   C   s  i }| j rtj|d< nd|d< | jr| j|d< |rd|d< t| jdd d u r0| jp-| j | j_	z8zt
d| jj	j||f||| jd|}W n tyZ } ztd	|f d }~ww |ra|j}	n|j}	|j}
W n ty } z| | W Y d }~nd }~ww |	|
|jfS )
NverifyFproxiesTstreamr   r   )r{   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: %s)rS   r~   ca_bundle_pathrR   r}   r^   r   r6   r   r   r   r   r   	TypeErrorrawcontentrj   	Exception_handle_request_errorr{   )r_   r   r   r{   r   r   r1   resultr   r   rj   r"   r"   r&   r     sV   




r   c                 C   s   t || jjjrd}dt|jt|f }d}nSt || jjj| jjjfr5d}dt|jt|f }d}n6t || jjj	rMd}dt|jt|f }d}nd}dt|jf }t|re|dt|f 7 }n|d	7 }d}t
|d
|f  }t||d|)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.%s: %sFziUnexpected 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.A %s was raisedz with error message %sz with no error message

(Network error: %s)rg   )rW   r6   
exceptionsSSLErrortyperH   rK   r   ConnectionErrorRequestExceptiontextwrapfillr   r_   r   msgerrrh   r"   r"   r&   r     s:   z$RequestsClient._handle_request_errorc                 C   s&   t | jdd d ur| jj  d S d S )Nr   )r}   r^   r   r   r   r"   r"   r&   r     s   zRequestsClient.close)r   NTNNr4   )rH   rI   rJ   rD   r#   r   r   r   rK   r3   rM   r`   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r"   r"   r   r&   r7   N  s    

		
?5r7   c                       sb  e Zd ZdZ				ddedeej dedee f fd	d
Z		dde
de
dee
e
f dee
eee
e
f f fddZ	dde
de
dee
e
f deeeee
e
f f fddZede
de
dee
e
f ded deeeef f
ddZede
de
dee
e
f ded dee
eef f
ddZde
de
dee
e
f fddZdede
defddZdd Z  ZS ) r5   r*   TN7   rT   rU   deadlinerV   c                    sD   t t| j|||d |rtd|| _|| _td usJ t| _d S )Nr   zNo proxy support in urlfetch library. Set stripe.default_http_client to either RequestsClient, PycurlClient, or Urllib2Client instance to use a proxy.)r   r5   r`   rY   rS   	_deadliner*   )r_   rT   rU   r   rV   r   r"   r&   r`     s   

zUrlFetchClient.__init__r   r   r{   r2   c                 C   r   r   r   r   r"   r"   r&   r   )     
zUrlFetchClient.requestc                 C   r   r   r   r   r"   r"   r&   r   0  r   zUrlFetchClient.request_streamr   c                 C   r   r4   r"   r   r"   r"   r&   r   7  r   z UrlFetchClient._request_internalFc                 C   r   r4   r"   r   r"   r"   r&   r   A  r   c           	   
   C   s   z| j j|||| j| j|d}W n | j jy* } z| || W Y d }~nd }~ww |r8tjt	
|j}n|j}||j|jfS )N)r   r   r{   validate_certificater   r   )r*   fetchrS   r   Errorr   r   ior   rK   encoder   rj   r{   )	r_   r   r   r{   r   r   r   r   r   r"   r"   r&   r   K  s"   
r   c                 C   sj   t || jjrd|f }nt || jjrd}nt || jjr!d}nd}t|d t| d }t||)NzThe Stripe library attempted to fetch an invalid URL (%r). 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.

(Network error: ))	rW   r*   InvalidURLErrorDownloadErrorResponseTooLargeErrorr   r   rK   r   )r_   r   r   r   r"   r"   r&   r   j  s   
z$UrlFetchClient._handle_request_errorc                 C   r   r4   r"   r   r"   r"   r&   r        zUrlFetchClient.close)TNr   Nr4   )rH   rI   rJ   rD   r   r   r3   rM   r#   r`   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   r"   r   r&   r5     s    




	
	

r5   c                       s  e Zd ZU G dd deddZdZee ed< 			d$d	ed
ee	j
 dee	 f fddZdd Z	d%deeef deeeeeef f fddZ	d%deeef deeeeeef f fddZedededeeef ded deeeef f
ddZedededeeef ded deeeeeef f f
ddZdededeeef deeeef eeeef f fddZdedefddZdee fd d!Zd"d# Z  ZS )&r9   c                   @   rE   )zPycurlClient._ParsedProxyrF   rG   N)rH   rI   rJ   r   r,   rL   r"   r"   r"   r&   _ParsedProxy  rN   r  F)totalr8   _parsed_proxyTNrT   rU   rV   c                    sr   t t| j|||d td usJ t| _t | _i | _| jr5| j}| D ]\}}t	t
t|| j|< q&d S d S r   )r   r9   r`   r8   Curl_curlr  rR   itemsr+   r   rK   )r_   rT   rU   rV   proxy_schemevaluer   r"   r&   r`     s   

zPycurlClient.__init__c                 C   s@   d|vri S | ddd }t|}tdd t| D S )Nz
ro   c                 s        | ]\}}|  |fV  qd S r4   lowerr$   kvr"   r"   r&   	<genexpr>      z-PycurlClient.parse_headers.<locals>.<genexpr>)splitemailmessage_from_stringrX   r  )r_   r   raw_headersr{   r"   r"   r&   parse_headers  s
   
zPycurlClient.parse_headersr{   r2   c                 C   r   r   r   r   r"   r"   r&   r     r   zPycurlClient.requestc                 C   r   r   r   r   r"   r"   r&   r     r   zPycurlClient.request_streamr   r   r   c                 C   r   r4   r"   r   r"   r"   r&   r     r   zPycurlClient._request_internalc                 C   r   r4   r"   r   r"   r"   r&   r     r   c              
   C   sD  t j }t j }| j  | |}|rE|jr#| j| jj	|j |j
r0| j| jj|j
 |js6|jrE| j| jjd|j|jf  |dkrS| j| jjd n"|dkrj| j| jjd | j| jj| n| j| jj|  | j| jj| | j| jj|j | j| jj|j | j| jjd | j| jjd | j| jjd | j| jjdd tt| D  | jr| j| jj t!j" n	| j| jj#d	 z| j$  W n | jj%y }	 z| &|	 W Y d }	~	nd }	~	ww |r|'d
 |}
n|( )d}
| j*| jj+}| ,|( )d}|
||fS )Nz%s:%sgetro   post   r   c                 S   s   g | ]
\}}d ||f qS )r   r"   r  r"   r"   r&   r'     s    z2PycurlClient._request_internal.<locals>.<listcomp>Fr   utf-8)-r   r   r   r  reset
_get_proxyhostnamesetoptr8   PROXYport	PROXYPORTusernamepasswordPROXYUSERPWDHTTPGETPOST
POSTFIELDSCUSTOMREQUESTupperURLWRITEFUNCTIONwriteHEADERFUNCTIONNOSIGNALCONNECTTIMEOUTTIMEOUT
HTTPHEADERiterrX   r  rS   CAINFOr~   r   SSL_VERIFYHOSTperformerrorr   seekgetvaluedecodegetinfoRESPONSE_CODEr  )r_   r   r   r{   r   r   brk   rU   r   rcontentrcoder"   r"   r&   r     s\   





r   c                 C   s   |j d | jj| jj| jjfv rd}d}n|j d | jj| jjfv r'd}d}nd}d}t|d |j d  d	 }t	||d
|)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   ro   r   rg   )
r0   r8   E_COULDNT_CONNECTE_COULDNT_RESOLVE_HOSTE_OPERATION_TIMEOUTEDE_SSL_CACERTE_SSL_PEER_CERTIFICATEr   r   r   )r_   r   r   rh   r"   r"   r&   r     s(   z"PycurlClient._handle_request_errorc                 C   sD   | j r | j }|r|dd nd }|r ||||dd S d S )N:r   )r  r  r  )r_   r   rU   r	  r"   r"   r&   r  >  s   zPycurlClient._get_proxyc                 C   r   r4   r"   r   r"   r"   r&   r   F  r  zPycurlClient.closer   r4   ) rH   rI   rJ   r   r  rD   r   rL   r   r3   rM   r`   r  r   rK   r   r#   r   r   r   r   r   r   r   r   r   r   r   r,   r  r   r   r"   r"   r   r&   r9     s~   
 




	
	

H#r9   c                       sX  e Zd ZdZ			ddedeej dee f fddZ	dd	e	d
e	de
e	e	f dee	ee
e	e	f f fddZ	dd	e	d
e	de
e	e	f deeee
e	e	f f fddZed	e	d
e	de
e	e	f ded dee	eef f
ddZed	e	d
e	de
e	e	f ded deeeef f
ddZd	e	d
e	de
e	e	f fddZdedefddZdd Z  ZS )r:   zurllib.requestTNrT   rU   rV   c                    sP   t t| j|||d d | _| jr&tttt	t	f | j}t
|| _d S d S r   )r   r:   r`   _openerrR   urllibrequestProxyHandlerr   r   rK   build_opener)r_   rT   rU   rV   proxy_handlerr   r"   r&   r`   M  s   
zUrllib2Client.__init__r   r   r{   r2   c                 C   r   r   r   r   r"   r"   r&   r   b  r   zUrllib2Client.requestc                 C   r   r   r   r   r"   r"   r&   r   i  r   zUrllib2Client.request_streamr   Fc                 C   r   r4   r"   r   r"   r"   r&   r   p  r   zUrllib2Client._request_internalc                 C   r   r4   r"   r   r"   r"   r&   r   z  r   c              
      s&  t |tr
|d}t||ttttf |} dvr# fdd|_z"| jr-| j	|nt
|}|r7|}n| }|j}	t| }W n9 tjye }
 z|
j}	|
 }t|
 }W Y d }
~
nd }
~
w tjtfy~ }
 z| |
 W Y d }
~
nd }
~
ww tdd tt| D }||	|fS )Nr  )r  r  c                      s      S r4   )r*  r"   r   r"   r&   <lambda>  s    z1Urllib2Client._request_internal.<locals>.<lambda>c                 s   r  r4   r  r  r"   r"   r&   r    r  z2Urllib2Client._request_internal.<locals>.<genexpr>)rW   rK   r   rH  Requestr   r   
get_methodrG  openurlopenreadcoderX   infourlliberror	HTTPErrorURLErrorrY   r   r3  r  )r_   r   r   r{   r   r   reqra   r>  r?  r   lhr"   rL  r&   r     s8   


r   c                 C   s(   d}t |d t| d }t||)Nr   r   r   )r   r   rK   r   )r_   r   r   r"   r"   r&   r     s   
z#Urllib2Client._handle_request_errorc                 C   r   r4   r"   r   r"   r"   r&   r     r  zUrllib2Client.closer   r4   )rH   rI   rJ   rD   r   r   r3   rM   r`   rK   r   r   r#   r   r   r   r   r   r   r   r   r   r   r   r   r"   r"   r   r&   r:   J  s    




	
	

+r:   c                       sv  e Zd ZU dZed ed< 		d"deeedf  f fdd	Zd
d Z	de
de
dee
e
f fddZ	d#de
de
dee
e
f deeeee
e
f f fddZ	d#de
de
dee
e
f deeeee
e
f f fddZdedefddZ	d#de
de
dee
e
f deee eee
e
f f fddZ	d#de
de
dee
e
f deee eee
e
f f fddZdd Zd d! Z  ZS )$r?   r>   HTTPXClientType_clientr   Fr   HTTPXTimeoutc                    s   t t| jdi | td u rtdtd u rtdt| _t| _i }| jr,tj|d< nd|d< tj	di || _
d | _|rGtjdi || _|| _d S )NzPUnexpected: tried to initialize HTTPXClient but the httpx module is not present.zPUnexpected: tried to initialize HTTPXClient but the anyio module is not present.r   Fr"   )r   r?   r`   r>   ImportErroranyiorS   r~   r   AsyncClient_client_asyncr[  r   r   )r_   r   allow_sync_methodsr1   r   r"   r&   r`     s(   
zHTTPXClient.__init__c                 C   s   | j |S r4   )r^  r   r   r"   r"   r&   r     s   zHTTPXClient.sleep_asyncr   r   r{   c                 C   s>   i }| j r
| j |d< | jr| j|d< ||f||pi d|gS )Nr   r   )r{   r   )rR   r   )r_   r   r   r{   r   r1   r"   r"   r&   _get_request_args_kwargs  s   

z$HTTPXClient._get_request_args_kwargsNr2   c              
   C   s   | j d u r	td| ||||\}}z| j j|i |}W n ty5 } z| | W Y d }~nd }~ww |j}	|j}
|j}|	|
|fS )NzqStripe: HTTPXClient was initialized with allow_sync_methods=False, so it cannot be used for synchronous requests.)	r[  RuntimeErrorrb  r   r   r   r   rj   r{   r_   r   r   r{   r   r0   r1   ra   r   r   rj   response_headersr"   r"   r&   r     s"   

zHTTPXClient.requestc              
      ~   |  ||||\}}z| jj|i |I d H }W n ty0 } z| | W Y d }~nd }~ww |j}	|j}
|j}|	|
|fS r4   )rb  r`  r   r   r   r   rj   r{   rd  r"   r"   r&   r     s   
zHTTPXClient.request_asyncr   c                 C   :   d}dt |jf }d}t|d|f  }t||d|Nr   r   Tr   rg   r   rH   r   r   r   r   r"   r"   r&   r         z!HTTPXClient._handle_request_errorc              
   C   s   | j d u r	td| ||||\}}z| j j| jj|i |dd}W n ty; } z| | W Y d }~nd }~ww | }	|j	}
|j
}|	|
|fS )NztStripe: HTTPXClient was not initialized with allow_sync_methods=True, so it cannot be used for synchronous requests.Tr   r   )r[  rc  rb  sendr`  build_requestr   r   
iter_bytesrj   r{   r_   r   r   r{   r   r0   r1   ra   r   r   rj   r"   r"   r&   r   +  s(   


zHTTPXClient.request_streamc              
      s   |  ||||\}}z| jj| jj|i |ddI d H }W n ty6 } z| | W Y d }~nd }~ww | }	|j}
|j}|	|
|fS )NTrk  )	rb  r`  rl  rm  r   r   aiter_bytesrj   r{   ro  r"   r"   r&   r   C  s"   
z HTTPXClient.request_stream_asyncc                 C   s   | j d ur| j   d S d S r4   )r[  r   r   r"   r"   r&   r   V  s   
zHTTPXClient.closec                       | j  I d H  d S r4   )r`  acloser   r"   r"   r&   r   Z     zHTTPXClient.close_async)r   Fr4   )rH   rI   rJ   rD   r   rL   r   r   r`   r   rK   r   rb  r   r   r#   r   r   r   r   r   r	   r   r   r   r   r   r   r"   r"   r   r&   r?     sv   
 !









r?   c                       s>  e Zd ZdZ	d"deeedf  f fddZedd Z	d	d
 Z
deeeeeef f fddZdededeeef fddZ	d#dededeeef deeeeeef f fddZdedefddZdeee eeeef f fddZ	d#dededeeef dedeeeef f fddZdd Zd d! Z  ZS )$rA   r@   r   r   AIOHTTPTimeoutc                    s6   t t| jdi | td u rtd|| _d | _d S )NzTUnexpected: tried to initialize AIOHTTPClient but the aiohttp module is not present.r"   )r   rA   r`   r@   r]  r   _cached_session)r_   r   r1   r   r"   r&   r`   a  s   
zAIOHTTPClient.__init__c                 C   sh   t d usJ | jd u r1i }| jr tjtjd}t j|d|d< nt jdd|d< t jdi || _| jS )N)cafile)ssl	connectorF)
verify_sslr"   )	r@   ru  rS   rw  create_default_contextr~   r   TCPConnectorClientSession)r_   r1   ssl_contextr"   r"   r&   r   n  s   
zAIOHTTPClient._sessionc                 C   s
   t |S r4   )asyncior   r   r"   r"   r&   r     s   
zAIOHTTPClient.sleep_asyncr2   c                 C   r   Nz4AIOHTTPClient does not support synchronous requests.r   r   r"   r"   r&   r     r   zAIOHTTPClient.requestr   r   r{   c                 C   sd   ||f}i }| j r| j d | j d krtd| j d |d< | jr&| j|d< ||d< ||d< ||fS )NrF   rG   zDAIOHTTPClient does not support different proxies for HTTP and HTTPS.rU   r   r{   r   )rR   rY   r   )r_   r   r   r{   r   r0   r1   r"   r"   r&   rb    s   
z&AIOHTTPClient._get_request_args_kwargsNc                    s4   | j ||||dI d H \}}}| I d H ||fS )N)r   )r   rR  )r_   r   r   r{   r   r   rj   re  r"   r"   r&   r     s   
zAIOHTTPClient.request_asyncr   c                 C   rg  rh  ri  r   r"   r"   r&   r     rj  z#AIOHTTPClient._handle_request_errorc                 C   r   r  r   r   r"   r"   r&   r     r   zAIOHTTPClient.request_streamAIOHTTPStreamReaderc              
      rf  r4   )rb  r   r   r   r   r   statusr{   rd  r"   r"   r&   r     s   
z"AIOHTTPClient.request_stream_asyncc                 C   r   r4   r"   r   r"   r"   r&   r     r  zAIOHTTPClient.closec                    rq  r4   )r   r   r   r"   r"   r&   r     rs  zAIOHTTPClient.close_async)r   r4   )rH   rI   rJ   rD   r   r   r   r`   propertyr   r   r   r   r#   r   rK   r   rb  r   r   r   r   r	   r   r   r   r   r   r"   r"   r   r&   rA   ^  sR    
 



$

rA   c                       s   e Zd Z fddZedefddZ	ddeded	eeef de	e
eeeef f fd
dZ	ddeded	eeef fddZdd Z  ZS )rB   c                    s   t t| jdi | d S )Nr"   )r   rB   r`   )r_   r1   r   r"   r&   r`     s   z!NoImportFoundAsyncClient.__init__r2   c                   C   r   )NzImport httpx not found. To make async http requests,You must either install httpx or define your ownasync http client by subclassing stripe.HTTPClientand setting stripe.default_http_client to an instance of it.)r]  r"   r"   r"   r&   raise_async_client_import_error  s   z8NoImportFoundAsyncClient.raise_async_client_import_errorNr   r   r{   c                       |    d S r4   r  r   r"   r"   r&   r        z&NoImportFoundAsyncClient.request_asyncc                    r  r4   r  r   r"   r"   r&   r     r  z-NoImportFoundAsyncClient.request_stream_asyncc                    r  r4   r  r   r"   r"   r&   r     s   z$NoImportFoundAsyncClient.close_asyncr4   )rH   rI   rJ   r`   staticmethodr   r  rK   r   r   r   r#   r   r   r   r   r"   r"   r   r&   rB     s.    



rB   )Zr   r   sysr   r  r.   ry   r\   r   r~  rw  http.clientr   r~   r   stripe._request_metricsr   stripe._errorr   typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   typing_extensionsr   r   r   r   r   urllib.requestr   rH  urllib.errorr7  rU  r]  r8   r>   r^  r   r\  r   rZ  r@   r   rt  r   r  r6   r   r   rK   rL   __version__r   r#   r  r   r    r!   r   stderrr-  google.appengine.apir*   urllib.parser+   r,   r/   r=   rC   objectr3   r7   r5   r9   r:   r?   rA   rB   r"   r"   r"   r&   <module>   s    <
   A ; Dq $t