
    _j.                        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
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%m&Z& e!rKd d	l'm(Z( 	 d d
l)m*Z+ n# e,$ r Y nw xY w	 d dl-m.Z/ d dl-m0Z1 n# e,$ r Y nw xY w	 d dl2m3Z4 d dl2m5Z6 n# e,$ r Y nw xY wd Z7dededdfdZ8dededdfdZ9 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? G d d e;          Z@ G d! d"e;          ZA G d# d$e;          ZB G d% d&e;          ZCdS )'    )BytesION)HTTPResponse)_util)RequestMetrics)APIConnectionError)AnyDictIterableListMappingMutableMappingOptionalTupleClassVarUnioncastoverloadAsyncIterable)TYPE_CHECKINGLiteralNoReturn	TypedDict	AwaitableNever)ParseResult)Session)Timeout)Client)ClientTimeout)StreamReaderc                  b    t          t          t          j                    dz                      S )Ni  )introundtime     W/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/stripe/_http_client.py_now_msr(   ?   s#    uTY[[4'(()))r&   argskwargsreturn
HTTPClientc                      	 ddl m} t          | i |S # t          $ r Y nw xY w	 ddl}t          | i |S # t          $ r Y nw xY w	 ddl}t          | i |S # t          $ r Y nw xY wt          | i |S )a  
    This method creates and returns a new HTTPClient based on what libraries are available. It uses the following precedence rules:

    1. Urlfetch (this is provided by Google App Engine, so if it's present you probably want it)
    2. Requests (popular library, the top priority for all environments outside Google App Engine, but not always present)
    3. Pycurl (another library, not always present, not as preferred as Requests but at least it verifies SSL certs)
    4. urllib with a warning (basically always present, a reasonable final default)

    For performance, it only imports what it's actually going to use. But, it re-calculates every time its called, so probably save its result instead of calling it multiple times.
    r   urlfetchN)	google.appengine.apir/   UrlFetchClientImportErrorrequestsRequestsClientpycurlPycurlClientUrllibClient)r)   r*   r/   r3   r5   s        r'   new_default_http_clientr8   C   s    /111111 t.v...    
/ t.v...    
- T,V,,,    
 ((((s-    
!!5 
AAA 
A#"A#c                      	 ddl }ddl}t          | i |S # t          $ r Y nw xY w	 ddl}t          | i |S # t          $ r Y nw xY wt          | i |S )z~
    Similar to `new_default_http_client` above, this returns a client that can handle async HTTP requests, if available.
    r   N)httpxanyioHTTPXClientr2   aiohttpAIOHTTPClientNoImportFoundAsyncClient)r)   r*   r:   r;   r=   s        r'   new_http_client_async_fallbackr@   f   s    
, D+F+++    
. d-f---    
 $T4V444s    
##7 
AAc                      e Zd ZU dZee         ed<    G d de          ZdZ	dZ
dZee         ed<   eed	<   	 	 	 	 d4dedeeeef                  ded          fdZdeeeeeeeef                  f                  dee         dedee         fdZ	 d5deeeeeeef         f                  fdZ	 d5dedeeeeeeef         f                  defdZdedefdZdeeef         deeef         fdZd Z	 	 d6d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"Z	 	 d6d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#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%Z	 d5d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&Z 	 d5d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'Z!d( Z"	 	 d6dddededeeef         dee         d!eee                  deeeef         fd)Z#	 	 d6dddededeeef         d!eee                  dee$e%         eef         f
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f         f         f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-            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.Z)	 d5dededeeef         dee%eeeef         f         fd/Z*	 d5dededeeef         dee$e%         eeeef         f         fd0Z+d1 Z,d2ede-d         fd3Z.dS )7r,   z@
    Base HTTP client that custom clients can inherit from.
    namec                   <    e Zd ZU ee         ed<   ee         ed<   dS )HTTPClient._ProxyhttphttpsN)__name__
__module____qualname__r   str__annotations__r%   r&   r'   _ProxyrD      s2         sm}r&   rL            ?<   _proxy_verify_ssl_certsTNverify_ssl_certsproxyasync_fallback_clientc                    || _         |r>t          |t                    r||d}t          |t                    st	          d          |r|                                nd | _        || _        t          j	                    | _
        d S )N)rE   rF   zqProxy(ies) must be specified as either a string URL or a dict() with string URL under the https and/or http keys.)rQ   
isinstancerJ   dict
ValueErrorcopyrP   _async_fallback_client	threadinglocal_thread_local)selfrR   rS   rT   _libs        r'   __init__zHTTPClient.__init__   s     "2 	%%% 8!&77eT** 	    ',5ejjlll&;#&_..r&   responseapi_connection_errornum_retriesmax_network_retriesc                     ||nd}||k    rdS ||J |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 )	Nr   Fzstripe-should-retryfalsetrueTi  i  should_retry)r^   ra   rb   rc   rd   _status_coderheaderss           r'   _should_retryzHTTPClient._should_retry   s     $7#B 	 ---5
 (333'44#+ ; $9X$E$E-.'99u-.&88t #4 #4ur&   c                 r    |d S |\  }}}	 t          |d                   S # t          t          f$ r Y d S w xY w)Nzretry-after)r"   KeyErrorrX   )r^   ra   rj   rl   s       r'   _retry_after_headerzHTTPClient._retry_after_header   sY     4!1h	x.///*% 	 	 	44	s   ! 66r+   c                 ,   t          t          j        d|dz
  z  z  t          j                  }|                     |          }t          t          j        |          }|                     |          pd}|t          j        k    rt          ||          }|S )z
        Apply exponential backoff with initial_network_retry_delay on the number of num_retries so far as inputs.
        Do not allow the number to exceed `max_network_retry_delay`.
              r   )minr,   INITIAL_DELAY	MAX_DELAY_add_jitter_timemaxrp   MAX_RETRY_AFTER)r^   rc   ra   sleep_secondsretry_afters        r'   _sleep_time_secondszHTTPClient._sleep_time_seconds   s     $kAo(>? 
 

 --m<< J4mDD ..x88=A*444];;Mr&   rz   c                 B    |ddt          j        dd          z   z  z  }|S )z
        Randomize the value in `[(sleep_seconds/ 2) to (sleep_seconds)]`.
        Also separated method here to isolate randomness for tests
        rN   rs   r   )randomuniform)r^   rz   s     r'   rw   zHTTPClient._add_jitter_time   s*    
 	FN1a$8$8 899r&   headersc                     t          | j        dd           }t          j        r@|r>d|                                i}t          |          }t          j        |          |d<   |S |S )Nlast_request_metricszX-Stripe-Client-Telemetry)getattrr]   stripeenable_telemetrypayloadrW   jsondumps)r^   r   r   	telemetryrets        r'   _add_telemetry_headerz HTTPClient._add_telemetry_header  sy      ' 6 
  
 " 	'; 	&(<(D(D(F(FI w--C/3z)/D/DC+,Jr&   c                     |\  }}}d|v rCt           j        r9|d         }t                      |z
  }t          |||          | j        _        d S d S d S )Nz
Request-Idusage)r   r   r(   r   r]   r   )r^   ra   request_startr   rj   rl   
request_idrequest_duration_mss           r'   _record_request_metricsz"HTTPClient._record_request_metrics  so    !1h8##(?#!,/J")))m";6D/u7 7 7D333 $###r&   )_usagemethodurl	post_datar   c          	      :    |                      ||||d||          S NFis_streamingrd   r   _request_with_retries_internalr^   r   r   r   r   rd   r   s          r'   request_with_retrieszHTTPClient.request_with_retries  s6     22 3 3 
 
 	
r&   c          	      :    |                      ||||d||          S NTr   r   r   s          r'   request_stream_with_retriesz&HTTPClient.request_stream_with_retries1  s6     22 3 3 
 
 	
r&   r   c                <   |                      |          }d}	 t                      }		 |r|                     ||||          }
n|                     ||||          }
d }n# t          $ 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 |J |Nr   Tz Encountered a retryable error %srs   zBInitiating retry %i for request %s %s after sleeping %.2f seconds.r   )r   r(   request_streamrequestr   rm   r   log_infouser_messager|   r$   sleepr   r^   r   r   r   r   r   rd   r   rc   r   ra   connection_errore
sleep_times                 r'   r   z)HTTPClient._request_with_retries_internalE  s    ,,W55*	+#IIM
  M#22Wi   HH  $||FC)LLH#'  %      #$   !!*K9L  + $ N:*78   q !55k8LL
1&Z@A   
:&&&&'00 -v 1    $O+777**U*	+s   5A 
A6(A11A6c                     t          d          )Nz.HTTPClient subclasses must implement `request`NotImplementedErrorr^   r   r   r   r   r   s         r'   r   zHTTPClient.request  s     "<
 
 	
r&   c                     t          d          )Nz5HTTPClient subclasses must implement `request_stream`r   r   s         r'   r   zHTTPClient.request_stream  s     "C
 
 	
r&   c                      t          d          )Nz,HTTPClient subclasses must implement `close`r   r^   s    r'   closezHTTPClient.close  s    !:
 
 	
r&   c          	      J   K   |                      ||||d||           d {V S r   $_request_with_retries_internal_asyncr   s          r'   request_with_retries_asyncz%HTTPClient.request_with_retries_async  sX       >> 3 ? 
 
 
 
 
 
 
 
 	
r&   c          	      J   K   |                      ||||d||           d {V S r   r   r   s          r'   !request_stream_with_retries_asyncz,HTTPClient.request_stream_with_retries_async  sX       >> 3 ? 
 
 
 
 
 
 
 
 	
r&   Fc                
   K   d S Nr%   r^   r   r   r   r   r   rd   r   s           r'   r   z/HTTPClient._request_with_retries_internal_async  s       .1Sr&   c                
   K   d S r   r%   r   s           r'   r   z/HTTPClient._request_with_retries_internal_async  s       ?Bcr&   c                f  K   |                      |          }d}	 t                      }		 |r|                     ||||           d {V }
n|                     ||||           d {V }
d }n# t          $ r}|}d }
Y d }~nd }~ww xY w|                     |
|||          rp|rt          j        d|j        z             |dz  }| 	                    ||
          }t          j        d||||fz             | 
                    |           d {V  n"|
|                     |
|	|           |
S |J |r   )r   r(   request_stream_asyncrequest_asyncr   rm   r   r   r   r|   sleep_asyncr   r   s                 r'   r   z/HTTPClient._request_with_retries_internal_async  s      ,,W55,	+#IIM  %)%>%>Wi& &            HH &*%7%7Wi& &            H $(  %      #$   !!*K9L  + $ N:*78   q !55k8LL
1&Z@A   &&z2222222222'00 -v 1    $O+777**Y,	+s   AA, ,
B6A??Bc                 x   K   | j         #| j                             ||||           d {V S t          d          )Nz4HTTPClient subclasses must implement `request_async`)rZ   r   r   r^   r   r   r   r   s        r'   r   zHTTPClient.request_async  sj       &24BBWi         "B
 
 	
r&   c                 x   K   | j         #| j                             ||||           d {V S t          d          )Nz;HTTPClient subclasses must implement `request_stream_async`)rZ   r   r   r   s        r'   r   zHTTPClient.request_stream_async)  sj       &24IIWi         "I
 
 	
r&   c                 p   K   | j         | j                                          d {V S t          d          )Nz2HTTPClient subclasses must implement `close_async`)rZ   close_asyncr   r   s    r'   r   zHTTPClient.close_async4  sK      &24@@BBBBBBBBB!@
 
 	
r&   secsc                 b    | j         | j                             |          S t          d          )Nz,HTTPClient subclasses must implement `sleep`)rZ   r   r   r^   r   s     r'   r   zHTTPClient.sleep_async;  s7    &2.::4@@@!:
 
 	
r&   TNNNr   )NN)/rG   rH   rI   __doc__r   rJ   rK   r   rL   rv   ru   ry   r   boolr   r`   r   r   r"   r   r   rm   rp   floatr|   rw   r   r   r   r   r   r   r   r   r   r   r   bytesr   r   r   r   r   r   r   r   r   r%   r&   r'   r,   r,   }   s(	          3-        IMOV "&.28</ // c6k*+/  (5	/ / / /4-5c8GCH4E+F!FGH- ''9:- 	-
 &c]- - - -` HL
 
 sCc1B'B!CD
 
 
 
 BF  5c738+<!<=> 
	   4e     sCx(	c	      -1
 '+
 
 

 
 c"	

 
 &c]
 c#
 
sCc**	+
 
 
 
2  
 '+
 
 

 
 c"	
 c#
 
sCc**	+
 
 
 
: '+9+ 9+ 9+9+ 9+ c"	9+
 9+ 9+ &c]9+ c#9+ 
sCc**	+9+ 9+ 9+ 9+@ 
 '+
 
 

 
 '#s(+,	

 
 c#
 
sCc**	+
 
 
 
$ 
 '+
 
 

 
 '#s(+,	

 
 c#
 
sCc**	+
 
 
 

 
 
 -1
 '+
 
 

 
 c"	
 &c]
 c#
 
sC}	
 
 
 
2  
 '+
 
 

 
 c"	
 c#
 
}U#S#-	.
 
 
 
(  '+
1 
1 
1
1 
1 c"	
1 en
1 &c]
1 c#
1 
sCc**	+
1 
1 
1 X
1  '+
B 
B 
B
B 
B c"	
B dm
B &c]
B c#
B 
}U#S'#s(*;;	<
B 
B 
B X
B* '+;+ ;+ ;+;+ ;+ c"	;+ ;+ &c];+ c#;+ 
sCc**	+;+ ;+ ;+ ;+| LP	
 	
	
 #	
.5c3h.?	
	uc738,,	-	
 	
 	
 	
 LP	
 	
	
 #	
.5c3h.?	
	}U#S'#s(*;;	<	
 	
 	
 	

 
 

 
)D/ 
 
 
 
 
 
r&   c                       e Zd ZdZ	 	 	 	 	 	 ddeeeeef         f         ded         ded	eee	e
j        f                  d
ee
         f
 fdZ	 dde	de	deee	e	f                  deeeee	e	f         f         fdZ	 dde	de	deee	e	f                  deeeee	e	f         f         f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            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            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ZdedefdZd Z xZS )r4   r3   P   NTtimeoutsessionRequestsSessionrR   rS   rT   c                     t          t          |                               |||           || _        || _        |dd l}|}|| _        d S NrR   rS   rT   r   )superr4   r`   _session_timeoutr3   )
r^   r   r   rR   rS   rT   r_   r*   r3   	__class__s
            r'   r`   zRequestsClient.__init__F  sc     	nd##,,-"7 	- 	
 	
 	

  <OOODr&   r   r   r   r+   c                 6    |                      ||||d          S NFr   _request_internalr   s        r'   r   zRequestsClient.request_  s,     %%C)% & 
 
 	
r&   c                 6    |                      ||||d          S NTr   r   r   s        r'   r   zRequestsClient.request_streamj  s,     %%C)$ & 
 
 	
r&   r   c                     d S r   r%   r^   r   r   r   r   r   s         r'   r   z RequestsClient._request_internalu  	     .1Sr&   Fc                     d S r   r%   r   s         r'   r   z RequestsClient._request_internal  s	     03sr&   c                 :   i }| j         rt          j        |d<   nd|d<   | j        r
| j        |d<   |rd|d<   t	          | j        dd           *| j        p| j                                        | j        _	        	 	  t          d| 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   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: )rQ   r   ca_bundle_pathrP   r   r]   r   r3   r   r   r   r   r   	TypeErrorrawcontentrk   	Exception_handle_request_errorr   )r^   r   r   r   r   r   r*   resultr   r   rk   s              r'   r   z RequestsClient._request_internal  s    ! 	%%4F8$F8; 	, $F9 	$#F84%y$77?8!6!6!8!8 &"	*%t'9'A 		
 $" M	 	 	 	    i 34!6    ) *
 !. ,KK 	* 	* 	* &&q))))))))	*
 V^33s6   90B* )C' *
C4CCC' '
D1DDr   c                    t          || j        j        j                  r+d}t	          |          j        dt          |          }d}nt          || j        j        j        | j        j        j        f          r+d}t	          |          j        dt          |          }d}nt          || j        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          ||          |)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.A  was raisedz with error message z with no error message

(Network error: )rh   )rV   r3   
exceptionsSSLErrortyperG   rJ   r   ConnectionErrorRequestExceptiontextwrapfillr   r^   r   msgerrri   s        r'   r   z$RequestsClient._handle_request_error  s    a1:;; -	!&  #1gg...A7C LL(0(8
 
 #	!& 
 #1gg...A7CLL4=3DEE 	!& 
 #1gg...A7C LL. C (,Aww'7'7'79C1vv 03q666;;// LmC   #EE <@@@aGr&   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   NTNNNr   )rG   rH   rI   rB   r   r   r   r   r   rJ   r,   rL   r`   r   r   r"   r   r   r   r   r   r   r   r   r   r   __classcell__r   s   @r'   r4   r4   C  s        D 68/3!%9=6: ueE5L112 +, 	
 c:#4456  (
3     < 	
 	
	
 	
 '#s(+,		
 
uc738,,	-	
 	
 	
 	
  	
 	
	
 	
 '#s(+,		
 
sCc**	+	
 	
 	
 	
 11 1 '#s(+,	1 dm1 
sCc**	+1 1 1 X1 33 3 '#s(+,	3 en3 
uc738,,	-3 3 3 X3=4=4 =4 '#s(+,	=4 =4 
uUCZ #wsCx'88	9=4 =4 =4 =4~3Hy 3HX 3H 3H 3H 3Hj/ / / / / / /r&   r4   c                       e Zd ZdZ	 	 	 	 	 ddedeej                 dedee         f fd	Z		 dd
e
de
dee
e
f         dee
eee
e
f         f         fdZ	 dd
e
de
dee
e
f         deeeee
e
f         f         fdZed
e
de
dee
e
f         ded         deeeef         f
d            Zed
e
de
dee
e
f         ded         dee
eef         f
d            Zd
e
de
dee
e
f         fdZdede
defdZd Z xZS )r1   r/   TN7   rR   rS   deadlinerT   c                     t          t          |                               |||           |rt          d          || _        || _        |ddlm} |}|| _        d S )Nr   zNo proxy support in urlfetch library. Set stripe.default_http_client to either RequestsClient, PycurlClient, or UrllibClient instance to use a proxy.r   r.   )r   r1   r`   rX   rQ   	_deadliner0   r/   )r^   rR   rS   r	  rT   r_   r/   r   s          r'   r`   zUrlFetchClient.__init__  s     	nd##,,-"7 	- 	
 	
 	
  	I   "2 "<555555Dr&   r   r   r   r+   c                 6    |                      ||||d          S r   r   r   s        r'   r   zUrlFetchClient.request(  ,     %%C)% & 
 
 	
r&   c                 6    |                      ||||d          S r   r   r   s        r'   r   zUrlFetchClient.request_stream/  ,     %%C)$ & 
 
 	
r&   r   c                     d S r   r%   r   s         r'   r   z UrlFetchClient._request_internal6  	     $'3r&   Fc                     d S r   r%   r   s         r'   r   z UrlFetchClient._request_internal@  	      #sr&   c                 H   	 | j                             |||| j        | j        |          }n2# | j         j        $ r }|                     ||           Y d }~nd }~ww xY w|r-t          t                              |j	                            }n|j	        }||j
        |j        fS )N)r   r   r   validate_certificater	  r   )r/   fetchrQ   r  Errorr   r   rJ   encoder   rk   r   )	r^   r   r   r   r   r   r   r   r   s	            r'   r   z UrlFetchClient._request_internalJ  s    	/](( &*%;! ) 
 
FF }" 	/ 	/ 	/&&q#........	/  	%cjj8899GGnG*FN::s   *- AAAr   c                 0   t          || j        j                  rd|d}n<t          || j        j                  rd}nt          || j        j                  rd}nd}t          j        |          dz   t          |          z   dz   }t          |          |)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   )	rV   r/   InvalidURLErrorDownloadErrorResponseTooLargeErrorr   r   rJ   r   )r^   r   r   r  s       r'   r   z$UrlFetchClient._handle_request_errori  s    a677 	 	
 -0CC2 C 4=677 	DCC4=>?? 
	< CG 
 mC  #99CFFBSH %%1,r&   c                     d S r   r%   r   s    r'   r   zUrlFetchClient.close      r&   )TNr  NNr   )rG   rH   rI   rB   r   r   r,   rL   r"   r`   rJ   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  s   @r'   r1   r1     s       D "&-16:! !! 
)*! 	!
  (
3! ! ! ! ! !H LP
 

 #
.5c3h.?
	sCc**	+
 
 
 
 LP
 

 #
.5c3h.?
	wWS#X..	/
 
 
 
 '' ' c"	' dm' 
wS 	!' ' ' X' ## # c"	# en# 
sC}	# # # X#;; ; c"	; ; ; ;>-y -s -x - - - -2      r&   r1   c                   <    e Zd ZU ed         ed<   ed         ed<   dS )rL   r   rE   rF   NrG   rH   rI   r   rK   r%   r&   r'   rL   rL     s4         
=
!!!!M""""""r&   rL   c                   r    e Zd ZU  G d ded          ZdZee         ed<   	 	 	 	 dd	ed
ee	j
                 dee	         f fdZd Z	 ddeeef         deeeeeef         f         fdZ	 ddeeef         deeeeeef         f         fdZedededeeef         ded         deeeef         f
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            Zdededeeef         deeeef         eeeef         f         fdZdedefdZded         fdZd Z xZS )r6   c                   <    e Zd ZU ed         ed<   ed         ed<   dS )PycurlClient._ParsedProxyr   rE   rF   Nr!  r%   r&   r'   _ParsedProxyr$    s4         }%%%%&&&&&&r&   r%  F)totalr5   _parsed_proxyTNrR   rS   rT   c                 h   t          t          |                               |||           |dd l}|}|| _        |                                | _        i | _        | j        rMddlm	} | j        }|
                                D ]-\  }}	 |t          t          |	                    | j        |<   ,d S d S )Nr   r   )urlparse)r   r6   r`   r5   Curl_curlr'  rP   urllib.parser)  itemsr   rJ   )r^   rR   rS   rT   r_   r5   r)  proxy_schemevaluer   s             r'   r`   zPycurlClient.__init__  s     	lD!!**-"7 	+ 	
 	
 	
 <MMMDYY[[
 ; 	H------[F!' H H .6Xd36F6F-G-G"6**	H 	HH Hr&   c                     d|vri S |                     dd          d         }t          j        |          }t          d t          |                                          D                       S )Nz
rs   c              3   H   K   | ]\  }}|                                 |fV  d S r   lower.0kvs      r'   	<genexpr>z-PycurlClient.parse_headers.<locals>.<genexpr>  s2      EEtq!QWWYYNEEEEEEr&   )splitemailmessage_from_stringrW   r-  )r^   r   raw_headersr   s       r'   parse_headerszPycurlClient.parse_headers  si    Ijj++A.+K88EEtG}}/B/B/D/DEEEEEEr&   r   r+   c                 6    |                      ||||d          S r   r   r   s        r'   r   zPycurlClient.request  r  r&   c                 6    |                      ||||d          S r   r   r   s        r'   r   zPycurlClient.request_stream  r  r&   r   r   r   c                     d S r   r%   r   s         r'   r   zPycurlClient._request_internal  r  r&   c                     d S r   r%   r   s         r'   r   zPycurlClient._request_internal  r   r&   c                 N   t                      }t                      }| j                                         |                     |          }|r|j        r*| j                            | j        j        |j                   |j        r*| j                            | j        j	        |j                   |j
        s|j        r4| j                            | j        j        |j
        d|j                   |dk    r&| j                            | j        j        d           n|dk    rK| j                            | j        j        d           | j                            | j        j        |           n7| 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 t5          |                                          D                        | j        r0| j                            | j        j        t<          j                   n%| j                            | j        j         d           	 | j        !                                 n1# | j        j"        $ r}	| #                    |	           Y d }	~	nd }	~	ww xY w|r|$                    d	           |}
n'|%                                &                    d
          }
| j        '                    | j        j(                  }| )                    |%                                &                    d
                    }|
||fS )N:getrs   post   r   c                 "    g | ]\  }}|d |S )r   r%   r5  s      r'   
<listcomp>z2PycurlClient._request_internal.<locals>.<listcomp>  s'    AAA41aAAAAAr&   Fr   utf-8)*r   r+  reset
_get_proxyhostnamesetoptr5   PROXYport	PROXYPORTusernamepasswordPROXYUSERPWDHTTPGETPOST
POSTFIELDSCUSTOMREQUESTupperURLWRITEFUNCTIONwriteHEADERFUNCTIONNOSIGNALCONNECTTIMEOUTTIMEOUT
HTTPHEADERrW   r-  rQ   CAINFOr   r   SSL_VERIFYHOSTperformerrorr   seekgetvaluedecodegetinfoRESPONSE_CODEr>  )r^   r   r   r   r   r   brl   rS   r   rcontentrcodes               r'   r   zPycurlClient._request_internal  s    II99 	
$$ 		~ E
!!$+"3U^DDDz E
!!$+"7DDD~  
!!K,$~~~u~~>  
 U??Jdk115555vJdk.222Jdk4i@@@@Jdk7HHH 	
$+/3///
$+3QW===
$+4hnEEE
$+.222
$+4b999
$+-r222
K"AA4==+>+>+@+@AAA	
 	
 	
 ! 	AJdk0&2GHHHHJdk8%@@@	*J    {  	* 	* 	*&&q))))))))	*  	4FF1IIIHHzz||**733H
""4;#<==$$X%6%6%8%8%?%?%H%HII''s   8M N !M;;N r   c                 <   |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          j        |          dz   |j         d         z   d	z   }t          ||
          |)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   rs   r   rh   )
r)   r5   E_COULDNT_CONNECTE_COULDNT_RESOLVE_HOSTE_OPERATION_TIMEOUTEDE_SSL_CACERTE_SSL_PEER_CERTIFICATEr   r   r   )r^   r   r  ri   s       r'   r   z"PycurlClient._handle_request_error&  s    6!9K)K.K-
 
 
&   LLVAYK$K.
 
 

&  !LLG  !LmC  #99AF1IEK <@@@aGr&   r   c                     | j         rY| j         }|r|                    d          d         nd }|r1|                    ||                    |dd                             S d S )NrD  r   )r'  r:  rE  )r^   r   rS   r/  s       r'   rL  zPycurlClient._get_proxyI  sj     	B&E*-7SYYs^^A&&4F Byy6!B$<)@)@AAAtr&   c                     d S r   r%   r   s    r'   r   zPycurlClient.closeQ  r  r&   r   r   )rG   rH   rI   r   r%  rB   r   rK   r   r,   rL   r`   r>  r   rJ   r   r"   r   r   r   r   r   r   r   r   r   r   r   rL  r   r  r  s   @r'   r6   r6     s        ' ' ' ' 'y ' ' ' ' DL)))) "&-16: H  H H 
)* H  (
3	 H  H  H  H  H  HDF F F BF
 
$+CH$5
	sCc**	+
 
 
 
 BF
 
$+CH$5
	wWS#X..	/
 
 
 
 '' ' c"	' dm' 
wS 	!' ' ' X' 11 1 c"	1 en1 
sCc**	+1 1 1 X1F(F( F( c"	F( 
uS'\"Cc)::	;F( F( F( F(P!Hy !HX !H !H !H !HF-!8          r&   r6   c                       e Zd ZdZ	 	 	 	 ddedeej                 dee         f fdZ	 dde	d	e	d
e
e	e	f         dee	ee
e	e	f         f         fdZ	 dde	d	e	d
e
e	e	f         deeee
e	e	f         f         fdZede	d	e	d
e
e	e	f         ded         dee	eef         f
d            Zede	d	e	d
e
e	e	f         ded         deeeef         f
d            Zde	d	e	d
e
e	e	f         fdZdedefdZd Z xZS )r7   zurllib.requestTNrR   rS   rT   c                    t          t          |                               |||           |dd lm} |}|| _        dd lm} || _        d | _	        | j
        re| j                            t          t          t          t          f         | j
                            }| j                            |          | _	        d S d S r   )r   r7   r`   urllib.requestr   urllibrequesturllib.errorre  urlliberror_openerrP   ProxyHandlerr   r	   rJ   build_opener)	r^   rR   rS   rT   r_   rz  r|  proxy_handlerr   s	           r'   r`   zUrllibClient.__init__X  s     	lD!!**-"7 	+ 	
 	
 	
 <222222 D!******& ; 	J !.;;T#s(^T[11 M  -::=IIDLLL	J 	Jr&   r   r   r   r+   c                 6    |                      ||||d          S r   r   r   s        r'   r   zUrllibClient.requesty  r  r&   c                 6    |                      ||||d          S r   r   r   s        r'   r   zUrllibClient.request_stream  r  r&   r   Fc                     d S r   r%   r   s         r'   r   zUrllibClient._request_internal  r  r&   c                     d S r   r%   r   s         r'   r   zUrllibClient._request_internal  s	     ),r&   c           	         t          |t                    r|                    d          }| j                            ||t          t          t          t          f         |                    }dvr
fd|_        	 | j        r| j        	                    |          n| j        
                    |          }|r|}n|                                }|j        }	t          |                                          }n# | j        j        $ rF}
|
j        }	|
                                }t          |
                                          }Y d }
~
n;d }
~
w| j        j        t$          f$ r}
|                     |
           Y d }
~
nd }
~
ww xY wt          d t)          t          |                                                    D                       }||	|fS )NrJ  )rE  rF  c                  ,                                      S r   )rY  )r   s   r'   <lambda>z0UrllibClient._request_internal.<locals>.<lambda>  s    V\\^^ r&   c              3   H   K   | ]\  }}|                                 |fV  d S r   r3  r5  s      r'   r9  z1UrllibClient._request_internal.<locals>.<genexpr>  s2      IITQ17799a.IIIIIIr&   )rV   rJ   r  rz  Requestr   r   
get_methodr}  openurlopenreadcoderW   infor|  	HTTPErrorURLErrorrX   r   iterr-  )r^   r   r   r   r   r   reqra   rl  rm  r   lhs    `          r'   r   zUrllibClient._request_internal  s    i%% 	2!((11I ((DS!97CC
 
 ((3333CN	*
 <5!!#&&&'//44   +##==??ME8==??++GG) 	% 	% 	%FEvvxxH16688nnGGGGGG ):6 	* 	* 	*&&q))))))))	*IIT$w--2E2E2G2G-H-HIIIII""s%   <A<C9 9F<E		F"E<<Fr   c                 z    d}t          j        |          dz   t          |          z   dz   }t          |          |)Nr  r   r   )r   r   rJ   r   )r^   r   r  s      r'   r   z"UrllibClient._handle_request_error  sD    K 	 mC  #99CFFBSH %%1,r&   c                     d S r   r%   r   s    r'   r   zUrllibClient.close  r  r&   r   r   )rG   rH   rI   rB   r   r   r,   rL   r`   rJ   r   r   r"   r   r   r   r   r   r   r   r   r   r   r   r  r  s   @r'   r7   r7   U  s       D "&-16:J JJ 
)*J  (
3	J J J J J JD LP
 

 #
.5c3h.?
	sCc**	+
 
 
 
 LP
 

 #
.5c3h.?
	|S'#s("33	4
 
 
 
 ## # c"	# en# 
sC}	# # # X# ,, , c"	, dm, 
|S#%	&, , , X,)#)# )# c"	)# )# )# )#V-y -X - - - -      r&   r7   c                       e Zd ZU dZed         ed<   	 	 	 ddeeedf                  f fd	Zd
 Z	de
de
dee
e
f         fdZ	 dde
de
dee
e
f         deeeee
e
f         f         fdZ	 dde
de
dee
e
f         deeeee
e
f         f         fdZdedefdZ	 dde
de
dee
e
f         deee         eee
e
f         f         fdZ	 dde
de
dee
e
f         deee         eee
e
f         f         fdZd Zd Z xZS )r<   r:   HTTPXClientType_clientr   FNr   HTTPXTimeoutc                 Z    t          t          |           j        di | |dd l}|}|| _        dd l}|| _        i }| j        r#t          j        t          j	                  |d<   nd|d<    | j        j
        di || _        d | _        |r | j        j        di || _        || _        d S )Nr   cafiler   Fr%   )r   r<   r`   r:   r;   rQ   sslcreate_default_contextr   r   AsyncClient_client_asyncr  r   r   )r^   r   allow_sync_methodsr_   r*   r:   r;   r   s          r'   r`   zHTTPXClient.__init__  s     	*k4  )33F333<LLLD

! 	%"9,     F8  %F83TZ3==f== 	7,4:,66v66DLr&   c                 6    | j                             |          S r   )r;   r   r   s     r'   r   zHTTPXClient.sleep_async  s    z%%%r&   r   r   r   c                 d    i }| j         r
| j         |d<   | j        r
| j        |d<   ||f||pi d|gS )Nr   r   )r   r   )rP   r   )r^   r   r   r   r   r*   s         r'   _get_request_args_kwargsz$HTTPXClient._get_request_args_kwargs  sZ     ; 	, $F9= 	. $F9SMbCCFC
 	
r&   r+   c                    | j         t          d          |                     ||||          \  }}	  | j         j        |i |}n,# t          $ r}|                     |           Y d }~nd }~ww xY w|j        }	|j        }
|j        }|	|
|fS )NzqStripe: HTTPXClient was initialized with allow_sync_methods=False, so it cannot be used for synchronous requests.)	r  RuntimeErrorr  r   r   r   r   rk   r   r^   r   r   r   r   r)   r*   ra   r   r   rk   response_headerss               r'   r   zHTTPXClient.request
  s     <A   44C)
 
f	*+t|+T<V<<HH 	* 	* 	*&&q))))))))	* "*#+%555s   A 
A/A**A/c                    K   |                      ||||          \  }}	  | j        j        |i | d {V }n,# t          $ r}|                     |           Y d }~nd }~ww xY w|j        }	|j        }
|j        }|	|
|fS r   )r  r  r   r   r   r   rk   r   r  s               r'   r   zHTTPXClient.request_async#  s       44C)
 
f	*7T/7HHHHHHHHHHH 	* 	* 	*&&q))))))))	* "*#+%555   8 
A!AA!r   c                     d}dt          |          j        d}d}t          j        |          d|dz   }t	          ||          |Nr  r   r   Tr   r   rh   r   rG   r   r   r   r  s        r'   r   z!HTTPXClient._handle_request_error7  `    C 	 $(77#3#3#35mC   #EE <@@@aGr&   c                 f   | j         t          d          |                     ||||          \  }}	 | j                              | j        j        |i |d          }n,# t          $ r}|                     |           Y d }~nd }~ww xY 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  r  r  sendr  build_requestr   r   
iter_bytesrk   r   r^   r   r   r   r   r)   r*   ra   r   r   rk   s              r'   r   zHTTPXClient.request_streamB  s     <A   44C)
 
f	*|((8*8$I&II )  HH  	* 	* 	*&&q))))))))	*%%''*"W,,s   ,A   
B	*BB	c                 J  K   |                      ||||          \  }}	 | j                             | j        j        |i |d           d {V }n,# t          $ r}|                     |           Y d }~nd }~ww xY w|                                }	|j        }
|j        }|	|
|fS )NTr  )	r  r  r  r  r   r   aiter_bytesrk   r   r  s              r'   r   z HTTPXClient.request_stream_asyncZ  s       44C)
 
f	*!/448*8$I&II 5        HH  	* 	* 	*&&q))))))))	*&&((*"W,,s   2A 
A;A66A;c                 J    | j         | j                                          d S d S r   )r  r   r   s    r'   r   zHTTPXClient.closem  s,    <#L      $#r&   c                 H   K   | j                                          d {V  d S r   )r  acloser   s    r'   r   zHTTPXClient.close_asyncq  s3       '')))))))))))r&   )r   FNr   )rG   rH   rI   rB   r   rK   r   r   r`   r   rJ   r   r  r   r   r"   r   r   r   r   r   r
   r   r   r   r   r   r  r  s   @r'   r<   r<     s        D'(((( ;= 	   %~ 567           B& & &

 #
.5c3h.?
 
 
 
( 6 66 6 c"	6 
uc738,,	-6 6 6 6< 6 66 6 c"	6 
uc738,,	-6 6 6 6(	Hy 	HX 	H 	H 	H 	H LP- -- #-.5c3h.?-	xWS#X%66	7- - - -2 LP- -- #-.5c3h.?-	}U#S'#s(*;;	<- - - -&! ! !* * * * * * *r&   r<   c                       e Zd ZdZ	 	 	 	 ddeeedf                  f fdZed             Z	d Z
d	eeeeeef         f         fd
Zdededeeef         fdZ	 ddededeeef         d	eeeeeef         f         fdZded	efdZd	eee         eeeef         f         fdZ	 ddededeeef         d	edeeeef         f         fdZd Zd Z xZS )r>   r=   r   Nr   AIOHTTPTimeoutc                      t          t          |           j        di | |dd l}|}|| _        || _        || _        || _        |d u | _        d | _        d S )Nr   r%   )	r   r>   r`   r=   r   _user_session_user_connector_internally_managed_session_cached_session)r^   r   r_   r   	connectorr*   r=   r   s          r'   r`   zAIOHTTPClient.__init__x  ss     	,mT""+55f555<NNND$(+2d?(#r&   c                 b   | j         | j        r| j        | _         ni }| j        r| j        |d<   nc| j        r>t	          j        t          j                  }| j        	                    |          |d<   n| j        	                    d          |d<    | j        j
        di || _         | j         S )Nr  r  )r  F)
verify_sslr%   )r  r  r  rQ   r  r  r   r   r=   TCPConnectorClientSession)r^   r*   ssl_contexts      r'   r   zAIOHTTPClient._session  s    '! L'+'9$$' *.*>F;''+ 
"%"<%4# # #K +/,*C*C' +D + +F;'' +/,*C*C#( +D + +F;' (Bt|'A'K'KF'K'K$##r&   c                 *    t          j        |          S r   )asyncior   r   s     r'   r   zAIOHTTPClient.sleep_async  s    }T"""r&   r+   c                      t          d          Nz4AIOHTTPClient does not support synchronous requests.r   r   s    r'   r   zAIOHTTPClient.request      !B
 
 	
r&   r   r   r   c                     ||f}i }| j         r;| j         d         | j         d         k    rt          d          | j         d         |d<   | j        r
| j        |d<   ||d<   ||d<   ||fS )NrE   rF   zDAIOHTTPClient does not support different proxies for HTTP and HTTPS.rS   r   r   r   )rP   rX   r   )r^   r   r   r   r   r)   r*   s          r'   r  z&AIOHTTPClient._get_request_args_kwargs  s     }; 	3{6"dk'&::: Z   #k'2F7O= 	. $F9#y"vV|r&   c                    K   |                      ||||           d {V \  }}}|                                 d {V ||fS )N)r   )r   r  )r^   r   r   r   r   r   rk   r  s           r'   r   zAIOHTTPClient.request_async  s       ++CI , 
 
 
 
 
 
 
 
		

 llnn$$$$$${4DDDr&   r   c                     d}dt          |          j        d}d}t          j        |          d|dz   }t	          ||          |r  r  r  s        r'   r   z#AIOHTTPClient._handle_request_error  r  r&   c                      t          d          r  r   r   s    r'   r   zAIOHTTPClient.request_stream  r  r&   AIOHTTPStreamReaderc                    K   |                      ||||          \  }}	  | j        j        |i | d {V }n,# t          $ r}|                     |           Y d }~nd }~ww xY w|j        }	|j        }
|j        }|	|
|fS r   )r  r   r   r   r   r   statusr   r  s               r'   r   z"AIOHTTPClient.request_stream_async  s       44C)
 
f	*2T]2DCFCCCCCCCCHH 	* 	* 	*&&q))))))))	* "o#+%555r  c                     d S r   r%   r   s    r'   r   zAIOHTTPClient.close  r  r&   c                 Z   K   | j         r!| j                                         d {V  d S d S r   )r  r   r   r   s    r'   r   zAIOHTTPClient.close_async  sG      + 	(-%%'''''''''''	( 	(r&   )r   NNNr   )rG   rH   rI   rB   r   r   r   r`   propertyr   r   r   r   r"   r   rJ   r   r  r   r   r   r   r
   r   r   r   r   r  r  s   @r'   r>   r>   u  s@       D =?$ $%'7 789$ $ $ $ $ $. $ $ X$0# # #
uc738+<<= 
 
 
 

 #.5c3h.?   . E EE E c"	E 
uc738,,	-E E E E"	Hy 	HX 	H 	H 	H 	H
huosGCH<M&M N 
 
 
 
 LP6 66 #6.5c3h.?6	$c738+<<	=6 6 6 6   ( ( ( ( ( ( (r&   r>   c                        e Zd Z fdZedefd            Z	 ddededeeef         de	e
eeeef         f         fdZ	 ddededeeef         fd	Zd
 Z xZS )r?   c                 H     t          t          |           j        di | d S )Nr%   )r   r?   r`   )r^   r*   r   s     r'   r`   z!NoImportFoundAsyncClient.__init__  s-    6&--6@@@@@@@r&   r+   c                       t          d          )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.)r2   r%   r&   r'   raise_async_client_import_errorz8NoImportFoundAsyncClient.raise_async_client_import_error  s    O
 
 	
r&   Nr   r   r   c                 2   K   |                                   d S r   r  r   s        r'   r   z&NoImportFoundAsyncClient.request_async
          	,,.....r&   c                 2   K   |                                   d S r   r  r   s        r'   r   z-NoImportFoundAsyncClient.request_stream_async  r  r&   c                 2   K   |                                   d S r   r  r   s    r'   r   z$NoImportFoundAsyncClient.close_async  s      ,,.....r&   r   )rG   rH   rI   r`   staticmethodr   r  rJ   r   r   r   r"   r   r   r   r  r  s   @r'   r?   r?     s       A A A A A 
U 
 
 
 \
 LP/ // #/.5c3h.?/	uc738,,	-/ / / / LP/ // #/.5c3h.?/ / / /
/ / / / / / /r&   r?   )Dior   r   r;  r$   r~   r[   r   r  r  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   r   r,  r   r3   r   r   r2   r:   r   r  r   r  r=   r   r  r    r  r(   r8   r@   objectr,   r4   r1   rL   r6   r7   r<   r>   r?   r%   r&   r'   <module>r     s                   



 $ $ $ $ $ $        2 2 2 2 2 2 , , , , , ,                                              ((((((7777777   1111113333333   ;;;;;;???????   * * * )3  )#  ),  )  )  )  )F5# 5 5 5 5 5 5.C
 C
 C
 C
 C
 C
 C
 C
L|/ |/ |/ |/ |/Z |/ |/ |/~A A A A AZ A A AH# # # # #Y # # #
G G G G G: G G GTz z z z z: z z zz`* `* `* `* `** `* `* `*FC( C( C( C( C(J C( C( C(L/ / / / /z / / / / /s6   :B B	B	B B"!B"&B3 3B;:B;