
    Ai9                     l   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!r'd d	l'm(Z( 	 d d
l)m*Z+ 	 d dl-m.Z/ d dl-m0Z1 	 d dl2m3Z4 d dl2m5Z6 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;      ZCy# e,$ r Y w xY w# e,$ r Y w xY w# e,$ r Y w xY w)'    )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                  T    t        t        t        j                         dz              S )Ni  )introundtime     F/var/www/html/immo/lib/python3.12/site-packages/stripe/_http_client.py_now_msr(   ?   s    uTYY[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 t.v..  
/ t.v..  
- T,V,,  
 (((s*    	2 	>>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   ss    
, D+F++  
. d-f--  
 $T4V44s    	!!4 	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.y)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<   y)HTTPClient._ProxyhttphttpsN)__name__
__module____qualname__r   str__annotations__r%   r&   r'   _ProxyrD      s    sm}r&   rL            ?<   _proxy_verify_ssl_certsTNverify_ssl_certsproxyasync_fallback_clientc                     || _         |r0t        |t              r||d}t        |t              st	        d      |r|j                         nd | _        || _        t        j                         | _
        y )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__   si     "2%%!&7eT*   ',ejjl&;#&__.r&   responseapi_connection_errornum_retriesmax_network_retriesc                     ||nd}||k\  ry||J |j                   S |\  }}}|d|v r|d   dk(  ry|d   dk(  ry|dk(  ry|dk\  ryy)	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 	 --
 (333'444#+ ; $9X$E-.'9-.&8 # #r&   c                 \    |y |\  }}}	 t        |d         S # t        t        f$ r Y y w xY w)Nzretry-after)r"   KeyErrorrX   )r^   ra   rj   rl   s       r'   _retry_after_headerzHTTPClient._retry_after_header   sD     !1h	x.//*% 		s    ++r+   c                 &   t        t        j                  d|dz
  z  z  t        j                        }| j	                  |      }t        t        j                  |      }| j                  |      xs 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44mD ..x8=A*444];Mr&   rz   c                 D    |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)    
 	FNN1a$8 899r&   headersc                     t        | j                  dd       }t        j                  r9|r7d|j	                         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  sj      ' 6 
 ""';&(<(D(D(FI w-C/3zz)/DC+,Jr&   c                     |\  }}}d|v rAt         j                  r0|d   }t               |z
  }t        |||      | j                  _        y y y )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  sX    !1h8#(?(?!,/J"))m";6D/u7D3 )@#r&   )_usagemethodurl	post_datar   c          	      2    | j                  ||||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  s1     22 3 3 
 	
r&   c          	      2    | j                  ||||d||      S NTr   r   r   s          r'   request_stream_with_retriesz&HTTPClient.request_stream_with_retries1  s1     22 3 3 
 	
r&   r   c                   | j                  |      }d}	 t               }		 |r| j                  ||||      }
n| j                  ||||      }
d }| j                  |
|||      rm|r"t        j                  d|j                  z         |dz  }| j                  ||
      }t        j                  d||||fz         t        j                  |       n|
| j                  |
|	|       |
S |J |# t        $ r}|}d }
Y d }~d }~ww xY wNr   z 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  sH    ,,W5#IM
 #22Wi H  $||FC)LH#' 
 !!*K9L $NN:*778 q !55k8L
1&Z@A 

:&'00 -v 1  $O+777**U  &  #$  s   -C- -	D6C??D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          	      N   K   | j                  ||||d||       d {   S 7 wr   $_request_with_retries_internal_asyncr   s          r'   request_with_retries_asyncz%HTTPClient.request_with_retries_async  s?      >> 3 ? 
 
 	
 
   %#%c          	      N   K   | j                  ||||d||       d {   S 7 wr   r   r   s          r'   !request_stream_with_retries_asyncz,HTTPClient.request_stream_with_retries_async  s?      >> 3 ? 
 
 	
 
r   Fc                   K   y wNr%   r^   r   r   r   r   r   rd   r   s           r'   r   z/HTTPClient._request_with_retries_internal_async  s      .1   c                   K   y wr   r%   r   s           r'   r   z/HTTPClient._request_with_retries_internal_async  s      ?Br   c                J  K   | j                  |      }d}	 t               }		 |r| j                  ||||       d {   }
n| j                  ||||       d {   }
d }| j                  |
|||      rq|r"t        j                  d|j                  z         |dz  }| j                  ||
      }t        j                  d||||fz         | j                  |       d {    n|
| j                  |
|	|       |
S |J |7 7 # t        $ r}|}d }
Y d }~d }~ww xY w7 Bw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  su     ,,W5#IM %)%>%>Wi&  H &*%7%7Wi&  H $( 
 !!*K9L $NN:*778 q !55k8L
1&Z@A &&z222'00 -v 1  $O+777**Y 
   &  #$  * 3s]   D#D DD DD A?D#D!$D#D D 	DDD#DD#c                    K   | j                   &| j                   j                  ||||       d {   S t        d      7 w)Nz4HTTPClient subclasses must implement `request_async`)rZ   r   r   r^   r   r   r   r   s        r'   r   zHTTPClient.request_async  sR      &&244BBWi   "B
 	
   .AA Ac                    K   | j                   &| j                   j                  ||||       d {   S t        d      7 w)Nz;HTTPClient subclasses must implement `request_stream_async`)rZ   r   r   r   s        r'   r   zHTTPClient.request_stream_async)  sR      &&244IIWi   "I
 	
r   c                    K   | j                   "| j                   j                          d {   S t        d      7 w)Nz2HTTPClient subclasses must implement `close_async`)rZ   close_asyncr   r   s    r'   r   zHTTPClient.close_async4  s@     &&244@@BBB!@
 	
 Cs   *><>secsc                 f    | j                   | j                   j                  |      S t        d      )Nz,HTTPClient subclasses must implement `sleep`)rZ   r   r   r^   r   s     r'   r   zHTTPClient.sleep_async;  s5    &&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+ c"	9+
 9+ 9+ &c]9+ c#9+ 
sCc**	+9+@ 
 '+

 
 '#s(+,	

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

 
 c#
 
sCc**	+

 -1
 '+

 
 c"	
 &c]
 c#
 
sC}	
2  
 '+

 
 c"	
 c#
 
}U#S#-	.
(  '+
1
1 
1 c"	
1 en
1 &c]
1 c#
1 
sCc**	+
1 
1  '+
B
B 
B c"	
B dm
B &c]
B c#
B 
}U#S'#s(*;;	<
B 
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   TtimeoutsessionRequestsSessionrR   rS   rT   c                 l    t         t        |   |||       || _        || _        |dd l}|}|| _        y 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  sF     	nd,-"7 	- 	

  <Dr&   r   r   r   r+   c                 .    | j                  ||||d      S NFr   _request_internalr   s        r'   r   zRequestsClient.request_  s'     %%C)% & 
 	
r&   c                 .    | j                  ||||d      S NTr   r   r   s        r'   r   zRequestsClient.request_streamj  s'     %%C)$ & 
 	
r&   r   c                      y r   r%   r^   r   r   r   r   r   s         r'   r   z RequestsClient._request_internalu       .1r&   Fc                      y r   r%   r   s         r'   r   z RequestsClient._request_internal  s     03r&   c                    i }| j                   rt        j                  |d<   nd|d<   | j                  r| j                  |d<   |rd|d<   t	        | j
                  dd       7| j                  xs | j                  j                         | j
                  _	        	 	  t        d| j
                  j                        j                  ||f||| j                  d|}|r|j                  }	n|j                  }	|j                   }
	
j&                  fS # t        $ r}t        d	|      d }~ww xY w# t"        $ r}| j%                  |       Y d }~Md }~ww xY w)
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  se    !!%44F8$F8;; $F9#F84%%y$7?8!6!6!8 &"	*%t'9'9'A'A'		
 $" MM	 	(  **
 !.. ,,K V^^331   346 &  	* &&q))	*s7   A D 'D/ 	D,D''D,,D/ /	E8EEr   c                    t        || j                  j                  j                        r)d}t	        |      j
                  dt        |      }d}nt        || 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}n?d}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  sT    a11::;&  #1g..A7C L((00((88
& 
 #1g..A7CL4==33DDE& 
 #1g..A7C L.  (,Aw'7'79C1v3q6;;// LmmC #EE <@aGr&   c                 |    t        | j                  dd       %| j                  j                  j                          y y )Nr   )r   r]   r   r   r   s    r'   r   zRequestsClient.close  s5    4%%y$7C&&,,. Dr&   )P   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456  (
3< 	
	
 	
 '#s(+,		
 
uc738,,	-	
  	
	
 	
 '#s(+,		
 
sCc**	+	
 11 1 '#s(+,	1 dm1 
sCc**	+1 1 33 3 '#s(+,	3 en3 
uc738,,	-3 3=4=4 =4 '#s(+,	=4 =4 
uUCZ #wsCx'88	9=4~3Hy 3HX 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/   TrR   rS   deadlinerT   c                     t         t        |   |||       |rt        d      || _        || _        |ddlm} |}|| _        y )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__  sa     	nd,-"7 	- 	
 I  "2 "<5Dr&   r   r   r   r+   c                 .    | j                  ||||d      S r   r   r   s        r'   r   zUrlFetchClient.request(  '     %%C)% & 
 	
r&   c                 .    | j                  ||||d      S r   r   r   s        r'   r   zUrlFetchClient.request_stream/  '     %%C)$ & 
 	
r&   r   c                      y r   r%   r   s         r'   r   z UrlFetchClient._request_internal6       $'r&   Fc                      y r   r%   r   s         r'   r   z UrlFetchClient._request_internal@        #r&   c                 ~   	 | j                   j                  |||| j                  | j                  |      }|r)t        t        j                  j                              }nj                  }||j                  |j                  fS # | j                   j                  $ r}| j                  ||       Y d }~d }~ww xY w)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    	/]](( &*%;%;! ) 
F cjj89GnnG**FNN:: }}"" 	/&&q#..	/s   5B B< B77B<r   c                 F   t        || j                  j                        rd|d}nHt        || 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67
 -02  4==667DC4==>>?< G 
 mmC #99CFBSH %1,r&   c                      y r   r%   r   s    r'   r   zUrlFetchClient.close      r&   )TN7   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 	!' ' ## # c"	# en# 
sC}	# #;; ; c"	;>-y -s -x -2r&   r1   c                   .    e Zd ZU ed   ed<   ed   ed<   y)rL   r   rE   rF   NrG   rH   rI   r   rK   r%   r&   r'   rL   rL     s    
=
!!M""r&   rL   c                       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<   y)PycurlClient._ParsedProxyr   rE   rF   Nr$  r%   r&   r'   _ParsedProxyr'    s    }%%&&r&   r(  F)totalr5   _parsed_proxyTrR   rS   rT   c                 <   t         t        |   |||       |dd l}|}|| _        |j	                         | _        i | _        | j                  rNddlm	} | j                  }|j                         D ](  \  }}	 |t        t        |	            | j                  |<   * y y )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 	+ 	
 <DYY[
 ;;-[[F!' H .6d36F-G""6*H	 r&   c                     d|vri S |j                  dd      d   }t        j                  |      }t        d t        |      j	                         D              S )Nz
rs   c              3   F   K   | ]  \  }}|j                         |f  y wr   lower.0kvs      r'   	<genexpr>z-PycurlClient.parse_headers.<locals>.<genexpr>  s     Etq!QWWYNE   !)splitemailmessage_from_stringrW   r0  )r^   r   raw_headersr   s       r'   parse_headerszPycurlClient.parse_headers  sR    Ijj+A.++K8EtG}/B/B/DEEEr&   r   r+   c                 .    | j                  ||||d      S r   r   r   s        r'   r   zPycurlClient.request  r  r&   c                 .    | j                  ||||d      S r   r   r   s        r'   r   zPycurlClient.request_stream  r  r&   r   r   r   c                      y r   r%   r   s         r'   r   zPycurlClient._request_internal  r  r&   c                      y r   r%   r   s         r'   r   zPycurlClient._request_internal  r   r&   c           
      
   t               }t               }| j                  j                          | j                  |      }|r|j                  r:| j                  j                  | j                  j                  |j                         |j                  r:| j                  j                  | j                  j                  |j                         |j                  s|j                  rI| j                  j                  | j                  j                  |j                  d|j                         |dk(  r1| j                  j                  | j                  j                  d       n|dk(  ra| j                  j                  | j                  j                  d       | j                  j                  | j                  j                  |       n>| j                  j                  | j                  j                   |j#                                | j                  j                  | j                  j$                  |       | j                  j                  | j                  j&                  |j(                         | j                  j                  | j                  j*                  |j(                         | j                  j                  | j                  j,                  d       | j                  j                  | j                  j.                  d       | j                  j                  | j                  j0                  d       | j                  j                  | j                  j2                  t5        |      j7                         D 	
cg c]  \  }	}
|	d|
 c}
}	       | j8                  r?| j                  j                  | j                  j:                  t<        j>                         n0| j                  j                  | j                  j@                  d       	 | j                  jC                          |r|jI                  d	       |}n|jK                         jM                  d
      }| j                  jO                  | j                  jP                        }| jS                  |jK                         jM                  d
            }|||fS c c}
}	w # | j                  jD                  $ r}| jG                  |       Y d }~d }~ww xY w)N:getrs   post   r  r   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   r0  rQ   CAINFOr   r   SSL_VERIFYHOSTperformerrorr   seekgetvaluedecodegetinfoRESPONSE_CODErB  )r^   r   r   r   r   r   brl   rS   r:  r;  r   rcontentrcodes                 r'   r   zPycurlClient._request_internal  s`    I9 	

$~~

!!$++"3"3U^^Dzz

!!$++"7"7D~~

!!KK,,$~~u~~>
 U?JJdkk1115vJJdkk..2JJdkk44i@JJdkk77H 	

$++//3/

$++33QWW=

$++44hnnE

$++..2

$++44b9

$++--r2

KK""+/=+>+>+@A41aAA	
 !!JJdkk00&2G2GHJJdkk88%@	*JJ  FF1IHzz|**73H

""4;;#<#<=$$X%6%6%8%?%?%HI''+ B {{   	*&&q))	*s   S	S T(S>>Tr   c                    |j                   d   | j                  j                  | j                  j                  | j                  j                  fv rd}d}nD|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    66!9KK))KK..KK--
 
&   LVVAYKK$$KK..
 

&  !LG  !LmmC #99AFF1IEK <@aGr&   r   c                     | j                   rJ| j                   }|r|j                  d      d   nd }|r$|j                  ||j                  |dd             S y )NrH  r   )r*  r>  rI  )r^   r   rS   r2  s       r'   rN  zPycurlClient._get_proxyI  sR    &&E*-SYYs^A&4Fyy6!B<)@AAr&   c                      y 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`   rB  r   rJ   r   r"   r   r   r   r   r   r   r   r   r   r   r   rN  r   r  r	  s   @r'   r6   r6     s)   'y ' DL)) "&-16: H H 
))* H  (
3	 HDF BF
$+CH$5
	sCc**	+
 BF
$+CH$5
	wWS#X..	/
 '' ' c"	' dm' 
wS 	!' ' 11 1 c"	1 en1 
sCc**	+1 1F(F( F( c"	F( 
uS'\"Cc)::	;F(P!Hy !HX !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.requestTrR   rS   rT   c                 V   t         t        |   |||       |dd lm} |}|| _        dd lm} || _        d | _	        | j                  ra| j
                  j                  t        t        t        t        f   | j                              }| j
                  j                  |      | _	        y y r   )r   r7   r`   urllib.requestr   urllibrequesturllib.errorrg  urlliberror_openerrP   ProxyHandlerr   r	   rJ   build_opener)	r^   rR   rS   rT   r_   r|  r~  proxy_handlerr   s	           r'   r`   zUrllibClient.__init__X  s     	lD*-"7 	+ 	
 <2 D!*& ;; !..;;T#s(^T[[1M  --::=IDL r&   r   r   r   r+   c                 .    | j                  ||||d      S r   r   r   s        r'   r   zUrllibClient.requesty  r  r&   c                 .    | j                  ||||d      S r   r   r   s        r'   r   zUrllibClient.request_stream  r  r&   r   Fc                      y r   r%   r   s         r'   r   zUrllibClient._request_internal  r  r&   c                      y r   r%   r   s         r'   r   zUrllibClient._request_internal  s     ),r&   c           	      `   t        |t              r|j                  d      }| j                  j	                  ||t        t        t        t        f   |            }dvr
fd|_        	 | j                  r| j                  j                  |      n| j                  j                  |      }|r|}n|j                         }|j                  }	t        |j                               }t        d t)        t        |      j+                               D              }	|fS # | j                  j                   $ r?}
|
j                  }	|
j                         }t        |
j                               }Y d }
~
d }
~
w| j                  j"                  t$        f$ r}
| j'                  |
       Y d }
~
d }
~
ww xY w)NrL  )rI  rJ  c                  $     j                         S r   )r[  )r   s   r'   <lambda>z0UrllibClient._request_internal.<locals>.<lambda>  s    V\\^ r&   c              3   F   K   | ]  \  }}|j                         |f  y wr   r6  r8  s      r'   r<  z1UrllibClient._request_internal.<locals>.<genexpr>  s     ITQ1779a.Ir=  )rV   rJ   r  r|  Requestr   r   
get_methodr  openurlopenreadcoderW   infor~  	HTTPErrorURLErrorrX   r   iterr0  )r^   r   r   r   r   r   reqra   rn  ro  r   lhs    `          r'   r   zUrllibClient._request_internal  sc    i%!((1I  ((DS!97C
 (3CN	*
 << !!#&''//4  ##==?MME8==?+G IT$w-2E2E2G-HII"" )) 	%FFEvvxH1668nG  )):6 	*&&q))	*s%   *A<D F-65E00"F-F((F-r   c                 l    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  s>    K 	 mmC #99CFBSH %1,r&   c                      y 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  (
3	JD LP

 #
.5c3h.?
	sCc**	+
 LP

 #
.5c3h.?
	|S'#s("33	4
 ## # c"	# en# 
sC}	# # ,, , c"	, dm, 
|S#%	&, ,)#)# )# 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   HTTPXTimeoutc                 z   t        t        | 
  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 || _        || _        y )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)3F3<D

!!"99,, F8  %F83TZZ33=f=,4::,,6v6DLr&   c                 8    | j                   j                  |      S r   )r;   r   r   s     r'   r   zHTTPXClient.sleep_async  s    zz%%r&   r   r   r   c                     i }| j                   r| j                   |d<   | j                  r| j                  |d<   ||f||xs 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  sU     ;; $F9== $F9SMbCFC
 	
r&   r+   c                 8   | j                   t        d      | j                  ||||      \  }}	  | j                   j                  |i |}j                  }	|j                  }
|j                  }|	|
|fS # t        $ r}| j                  |       Y d }~Hd }~ww xY w)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<H ""**#++%555  	*&&q))	*s   A5 5	B>BBc                 &  K   | j                  ||||      \  }}	  | j                  j                  |i | d {   }j
                  }	|j                  }
|j                  }|	|
|fS 7 -# t        $ r}| j	                  |       Y d }~Jd }~ww xY wwr   )r  r  r   r   r   r   rk   r   r  s               r'   r   zHTTPXClient.request_async#  s      44C)
f	*7T//77HHHH ""**#++%555 I 	*&&q))	*=   BA* A(A* )B(A* *	B3B	B	BB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  K    C 	 $(7#3#35mmC #EE <@aGr&   c                 v   | j                   t        d      | j                  ||||      \  }}	 | j                   j                   | j                  j
                  |i |d      }j                         }	|j                  }
|j                  }|	|
|fS # t        $ r}| j                  |       Y d }~Ld }~ww xY w)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8$I&I ) H %%'**""W,,  	*&&q))	*s   7B 	B8B33B8c                 d  K   | j                  ||||      \  }}	 | j                  j                   | j                  j                  |i |d       d {   }j                         }	|j                  }
|j                  }|	|
|fS 7 1# t        $ r}| j                  |       Y d }~Nd }~ww xY ww)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8$I&I 5  H &&(**""W,,  	*&&q))	*s@   B0:B	 BB	 -B0B	 		B-B(#B0(B--B0c                 R    | j                   | j                   j                          y y r   )r  r   r   s    r'   r   zHTTPXClient.closem  s!    <<#LL  $r&   c                 T   K   | j                   j                          d {    y 7 wr   )r  acloser   s    r'   r   zHTTPXClient.close_asyncq  s       '')))   (&()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 c"	6 
uc738,,	-6< 66 6 c"	6 
uc738,,	-6(	Hy 	HX 	H LP-- #-.5c3h.?-	xWS#X%66	7-2 LP-- #-.5c3h.?-	}U#S'#s(*;;	<-&!*r&   r<   c                   P    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   AIOHTTPTimeoutc                 f    t        t        | 
  di | |dd l}|}|| _        || _        d | _        y )Nr   r%   )r   r>   r`   r=   r   _cached_session)r^   r   r_   r*   r=   r   s        r'   r`   zAIOHTTPClient.__init__x  s:     	mT+5f5<D#r&   c                 V   | j                   i }| j                  rDt        j                  t        j
                        }| j                  j                  |      |d<   n| j                  j                  d      |d<    | j                  j                  di || _         | j                   S )Nr  )r  	connectorF)
verify_sslr%   )	r  rQ   r  r  r   r   r=   TCPConnectorClientSession)r^   r*   ssl_contexts      r'   r   zAIOHTTPClient._session  s    'F%%!88!00 '+ll&?&?# '@ '{# '+ll&?&?$ '@ '{# $>4<<#=#=#G#GD ###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   k7  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     };;{{6"dkk'&:: Z  #kk'2F7O== $F9#y"vV|r&   c                    K   | j                  ||||       d {   \  }}}|j                          d {   ||fS 7 #7 	w)N)r   )r   r  )r^   r   r   r   r   r   rk   r  s           r'   r   zAIOHTTPClient.request_async  s[      ++CI , 
 
		

 lln${4DDD	
 %s   A?AAAA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                  j                  |i | d {   }j
                  }	|j                  }
|j                  }|	|
|fS 7 -# t        $ r}| j	                  |       Y d }~Jd }~ww xY wwr   )r  r   r   r   r   r   statusr   r  s               r'   r   z"AIOHTTPClient.request_stream_async  s      44C)
f	*2T]]22DCFCCH ""oo#++%555 D 	*&&q))	*r  c                      y r   r%   r   s    r'   r   zAIOHTTPClient.close  r!  r&   c                 T   K   | j                   j                          d {    y 7 wr   )r   r   r   s    r'   r   zAIOHTTPClient.close_async  s     mm!!###r  )r  Nr   )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  sp   D =?$%'7 789$$ $ $&#
uc738+<<= 

 #.5c3h.?. EE E c"	E 
uc738,,	-E"	Hy 	HX 	H
huosGCH<M&M N 
 LP66 #6.5c3h.?6	$c738+<<	=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                 ,    t        t        | 
  di | y )Nr%   )r   r?   r`   )r^   r*   r   s     r'   r`   z!NoImportFoundAsyncClient.__init__  s    &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&   r   r   r   c                 ,   K   | j                          y wr   r  r   s        r'   r   z&NoImportFoundAsyncClient.request_async        	,,.   c                 ,   K   | j                          y wr   r  r   s        r'   r   z-NoImportFoundAsyncClient.request_stream_async  r  r  c                 ,   K   | j                          y w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 
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     sk           
 $   2 ,     (713;?
* )3  )#  ),  )F5# 5 5 5.C
 C
L|/Z |/~AZ AH#Y #
G: GTz: zz`** `*Fx$J x$v/z /C.      s6   :D D  D+ DD D('D(+D32D3