
    Aiw                        U d dl mZmZ d dlZd dlZd dl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 d dlZd dlmZmZmZ d dlZd dlmZmZmZmZm Z  d dl!m"Z" d dl#m$Z% d dl&m'Z' d dl(m)Z) d d	lm*Z* d d
l+m,Z,m-Z- d dl.m/Z/m0Z0m1Z1 d dl2m3Z3m4Z4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z:m;Z;m<Z< d dl=m>Z> d dl?m@Z@ erd dlAmBZB d dlCmDZD ed   ZEdaFeeG   eHd<   deGde@deIfdZJ G d deK      ZLy)    )BytesIOIOBaseN)
AnyAsyncIterableDictListMappingOptionalTupleUnioncastClassVar)TYPE_CHECKINGLiteralNoReturnUnpack)urlsplit
urlunsplitparse_qs)	log_debuglog_infodashboard_link_convert_to_stripe_objectget_api_mode)VERSION)MultipartDataGenerator)	urlencode)_api_encode_json_encode_date_callback)StripeResponseStripeStreamResponseStripeStreamResponseAsync)PERSISTENT_OPTIONS_KEYSRequestOptionsmerge_options)RequestorOptions_GlobalRequestorOptions)
HTTPClientnew_default_http_clientnew_http_client_async_fallback)BaseAddress)ApiMode)AppInfo)StripeObject)getpostdelete_default_proxymethodapi_modereturnc                     | dk(  xr |dk(  S )Nr1   V2 )r3   r4   s     H/var/www/html/immo/lib/python3.12/site-packages/stripe/_api_requestor.pyis_v2_delete_respr:   I   s    X2(d"22    c                   $   e Zd ZU dZed   ed<   	 	 d.dee   dee   fdZ	defdZ
dee   dd fd	Zed
        Zed        Zed        Zed        Zed        Zedee   dd fd       Zed        Z	 	 d.dddededeeeef      dee   dedeee      ddfdZ	 	 d.dddededeeeef      dee   dedeee      ddfdZ	 	 d.dddededeeeef      dee   dedeee      defdZ 	 	 d.dddededeeeef      dee   dedeee      de!fdZ"de#fdZ$d Z%d Z&d Z'de(d e)defd!Z*	 	 d.dddededeeeef      dee   ded e)deee      fd"Z+	 	 	 d/dddededeeeef      dee   d#e,ded e)deee      de-e.e/eeef   f   fd$Z0	 	 	 d/dddededeeeef      dee   d#e,ded e)deee      de-e1e2   e/eeef   f   fd%Z3d&e/de,fd'Z4d(e.d&e/d)eeef   d e)de5f
d*Z6d+e7d&e/d)eeef   d e)def
d,Z8d+e1e2   d&e/d)eeef   d e)de!f
d-Z9y)0_APIRequestorNz_APIRequestor|None	_instanceoptionsclientc                 8    |
t               }|| _        || _        y N)r&   _options_client)selfr?   r@   s      r9   __init__z_APIRequestor.__init__P   s    
 ?&(Gr;   r5   c           	         | j                   }|t        j                  sQt        j                  t        j                  d}t        ddt        di |i|t        _        t        j                  an,t        j                  t        k7  rdd l}|j                  d       t        j                  J t        j                  S |S )N)verify_ssl_certsproxyasync_fallback_clientr   zstripe.proxy was updated after sending a request - this is a no-op. To use a different proxy, set stripe.default_http_client to a new client configured with the proxy.r8   )
rD   stripedefault_http_clientrH   rI   r)   r*   r2   warningswarn)rE   r@   kwargsrM   s       r9   _get_http_clientz_APIRequestor._get_http_client^   s    > --(.(?(?#\\ .E .*H + +. 	.* "(/1 --999---r;   c                     |xs i }| j                   j                         }t        D ]  }||v s||   ||   ||<    t        t	        di || j
                        S )z
        Returns a new _APIRequestor instance with the same HTTP client but a (potentially) updated set of options. Useful for ensuring the original isn't modified, but any options the original had are still used.
        r?   r@   r8   )rC   to_dictr#   r=   r&   rD   )rE   r?   new_optionskeys       r9   _new_requestor_with_optionsz)_APIRequestor._new_requestor_with_options   sl     -Rmm++-* 	0Cg~'#,":#*3<C 	0 $3{3DLL
 	
r;   c                 .    | j                   j                  S rB   )rC   api_keyrE   s    r9   rX   z_APIRequestor.api_key   s    }}$$$r;   c                 .    | j                   j                  S rB   )rC   stripe_accountrY   s    r9   r[   z_APIRequestor.stripe_account       }}+++r;   c                 .    | j                   j                  S rB   )rC   stripe_versionrY   s    r9   r^   z_APIRequestor.stripe_version   r\   r;   c                 .    | j                   j                  S rB   )rC   base_addressesrY   s    r9   r`   z_APIRequestor.base_addresses   r\   r;   c                 `    | j                    | t               d      | _         | j                   S )z
        Returns the singleton instance of _APIRequestor, to be used when
        calling a static method such as stripe.Customer.create(...)
        NrR   )r>   r'   )clss    r9   _global_instancez_APIRequestor._global_instance   s*     == (?(A$OCM}}r;   paramsc                  H    t         j                         j                  |       S rB   )r=   rc   rV   )rd   s    r9   _global_with_optionsz"_APIRequestor._global_with_options   s#     --/KK
 	
r;   c                 R    |d   }|d   r|d|d   z  }|d   r|d|d   dz  }|S )Nnameversion/urlz ()r8   )rb   infostrs      r9   _format_app_infoz_APIRequestor._format_app_info   s@    6l	?DO--C;d5k++C
r;   )usager3   rk   base_addressrp   r.   c          
          t        |      }| j                  |      }|j                  |j                         ||d||||      \  }	}
}|j	                  |	|
||      }t        ||||t        ||            }|S NFis_streamingr4   rq   r?   rp   )resprd   	requestorr4   is_v2_deleted_object)r   rV   request_rawlower_interpret_responser   r:   rE   r3   rk   rd   r?   rq   rp   r4   rw   rbodyrcoderheadersrv   objs                 r9   requestz_APIRequestor.request   s      $44W=	!*!6!6LLN% "7 	"
uh ,,UE8XN'!268!D
 
r;   c          
        K   t        |      }| j                  |      }|j                  |j                         ||d||||       d {   \  }	}
}|j	                  |	|
||      }t        ||||t        ||            }|S 7 8wrs   )r   rV   request_raw_asyncrz   r{   r   r:   r|   s                 r9   request_asyncz_APIRequestor.request_async   s       $44W=	'0'B'BLLN% (C 	(
 	"
uh ,,UE8XN'!268!D
 
)	"
s   AB	B
9Bc          
          t        |      }| j                  |j                         ||d||||      \  }}	}
| j                  t	        t
        |      |	|
|      }|S NTrt   )r   ry   rz   _interpret_streaming_responser   r   rE   r3   rk   rd   r?   rq   rp   r4   streamr~   r   rv   s               r9   request_streamz_APIRequestor.request_stream   sv      $"&"2"2LLN% #3 	#
x 11  
 r;   c          
         K   t        |      }| j                  |j                         ||d||||       d {   \  }}	}
| j                  ||	|
|       d {   }|S 7 &7 wr   )r   r   rz   #_interpret_streaming_response_asyncr   s               r9   request_stream_asyncz"_APIRequestor.request_stream_async  s       $(,(>(>LLN% )? 	)
 	#
x ==	
 
 !	#

s!   6A#AA#A!A#!A#c                 "   	 |d   }d }t	        |t
              r| j                  |||||      }|/|dk(  r| j                  |||||      n| j                  |||||      }|# t         t        f$ r t        j                  d||fz  |||      w xY w)Nerrorz@Invalid response object from API: %r (HTTP response code was %d)r7   )	KeyError	TypeErrorr   APIError
isinstancern   specific_oauth_errorspecific_v2_api_errorspecific_v1_api_error)rE   r}   r~   rv   r   r4   
error_dataerrs           r9   handle_error_responsez#_APIRequestor.handle_error_response<  s    		gJ 
 j#&++udHjC ;
 t# **5$* //5$*  	= )$ 	.."EN+ 	s   A! !-Bc           	      r   |j                  d      }|j                  d      }|j                  d      }||||||d}	t        d||j                  d      ||j                  d             |dk(  rt        j                  ||||||      S |d	k(  rt        j                  d
i |	S | j                  |||||      S )Ntypecodemessage)r   	http_bodyhttp_status	json_bodyheadersr   zStripe v2 API error receivedparam
error_code
error_typeerror_messageerror_paramidempotency_errortemporary_session_expiredr8   )r/   r   r   IdempotencyErrorTemporarySessionExpiredErrorr   )
rE   r}   r~   rv   r   r   r   r   r   
error_argss
             r9   r   z#_APIRequestor.specific_v2_api_errora  s    ~~f%~~f%..+ 

 	*!~~f-!"w/	
 &&))  0055C
CC ))5$*
 	
r;   c           	         t        d|j                  d      |j                  d      |j                  d      |j                  d             |dk(  s|dk(  r<|j                  d      d	k(  r(t        j                  |j                  d      ||||      S |d
v r|j                  d      dk(  r(t        j                  |j                  d      ||||      S t        j
                  |j                  d      |j                  d      |j                  d      ||||      S |dk(  r(t        j                  |j                  d      ||||      S |dk(  rHt        j                  |j                  d      |j                  d      |j                  d      ||||      S |dk(  r(t        j                  |j                  d      ||||      S t        j                  |j                  d      ||||      S )NzStripe v1 API error receivedr   r   r   r   r   i    
rate_limit)r   i  r   i  i  i  )
r   r/   r   RateLimitErrorr   InvalidRequestErrorAuthenticationError	CardErrorPermissionErrorr   )rE   r}   r~   rv   r   r   s         r9   r   z#_APIRequestor.specific_v1_api_error  s   *!~~f-!~~f-$..3"w/	
 C<SLZ^^F3|C''y)5%x  j ~~f%)<<--NN9-ueT8  00NN9-NN7+NN6*  c\,,y)5%x  c\??y)w'v&  c\((y)5%x  >>y)5%x r;   c                 h   |j                  d|      }t        d||       ||||||g}|dk(  rt        j                  | S |dk(  rt        j                  | S |dk(  rt        j
                  | S |dk(  rt        j                  | S |dk(  rt        j                  | S |d	k(  rt        j                  | S y )
Nerror_descriptionzStripe OAuth error received)r   r   invalid_clientinvalid_grantinvalid_requestinvalid_scopeunsupported_grant_typeunsupported_response_type)	r/   r   oauth_errorInvalidClientErrorInvalidGrantErrorr   InvalidScopeErrorUnsupportedGrantTypeErrorUnsupportedResponseTypeError)rE   r}   r~   rv   r   r   descriptionargss           r9   r   z"_APIRequestor.specific_oauth_error  s    hh2J?)!)	
 KtXF))11488?*00$77,,22D99?*00$773388$??66;;TBBr;   r4   c                    d|j                         dt        }t        j                  r%|d| j	                  t        j                        z   z  }t        dd| j                         j                  d}dt        j                  gdt        j                  gd	d
 gfD ]  \  }}	  |       }|||<    t        j                  rt        j                  |d<   t        j                  |      |d|j                  d      d}	|j                  d      }
|
r|
|	d<   |j                  d      }|rt        |      rt        |      |	d<   |j                  d      }|r||	d<   |dk(  s
|dk(  r2|dk(  r-|	j                  dt        t        j                                       |dk(  r|dk(  rd|	d<   nd|	d<   |j                  d      }|r||	d<   |	S # t        $ r d}Y *w xY w)NzStripe/z PythonBindings/ pythonrK   )bindings_versionlang	publisherhttpliblang_versionplatformunamec                  H    dj                  t        j                               S )Nr   )joinr   r   r8   r;   r9   <lambda>z/_APIRequestor.request_headers.<locals>.<lambda>  s    chhx~~'78 r;   z
(disabled)applicationzBearer rX   )zX-Stripe-Client-User-Agentz
User-AgentAuthorizationr[   zStripe-Accountstripe_contextzStripe-Contextidempotency_keyzIdempotency-Keyr0   r7   r1   zapplication/jsonContent-Typez!application/x-www-form-urlencodedr^   zStripe-Version)rz   r   rK   app_inforo   rP   rh   r   python_version	Exceptionjsondumpsr/   rn   
setdefaultuuiduuid4)rE   r3   r4   r?   
user_agentuaattrfuncvalr   r[   r   r   r^   s                 r9   request_headersz_APIRequestor.request_headers  s    NN

 ??# 5 5foo FFFJ !(!,,.33	0
 X445**+89
 		JD$
#f BtH		 ?? &B} +/**R.$,3KK	,BD#
 !%56(6G$% %56c.1(+N(;G$%!++&78)8G%& VD 0Vx5G0#djjl2CDV4*<'*M' %56(6G$%M  #"#s   "GGGc          
      r   t        | j                  |      }|rd|v r|d   |d   |d<   |j                  d      t        j                  d      | j                  j
                  j                  |      |}	|xs i }|r|dk(  s|dk(  ri }
t        t        |      j                        j                         D ]7  \  }}|j                  d      r	||
|dd <    t        |      d	k(  r|d
   n||
|<   9 d|
v r%d|v r!t        t        g |
d   |d               |d<   i |
|}t        t        t        |xs i |                  }|j!                  dd      j!                  dd      }|dk(  r t#        j$                  |xs i t&              }n|}d}d|v r|d   t)        |d         }| j+                  t-        t.        |      ||      }|dk(  s|dk(  r&|r!t        |	      \  }}}}}t1        |||||f      }	d}ny|dk(  r[|V|j                  d      dk(  rBt3               }|j5                  |xs i        |j7                         }d|j8                  |d<   n|}nt        j:                  d|d      ||j                         D ]
  \  }}|||<    |j                  d      }||	||||||j                  d      fS )z`
        Mechanism for issuing an API call.  Used by request_raw and request_raw_async.
        r^   NrX   zNo API key provided. (HINT: set your API key using "stripe.api_key = <API-KEY>"). You can generate API keys from the Stripe web interface.  See https://stripe.com/api for details, or email support@stripe.com if you have any questions.r/   r1   z[]   r   expandz%5B[z%5D]r7   )defaultr   r0   content_typezmultipart/form-datazmultipart/form-data; boundary=r   zUnrecognized HTTP method ze.  This may indicate a bug in the Stripe bindings.  Please contact support@stripe.com for assistance.max_network_retries)r%   rC   r/   r   r   r`   r   r   queryitemsendswithlenlistsetr   r   replacer   r   r   dictr   r   HttpVerbr   r   
add_paramsget_post_databoundaryAPIConnectionError)rE   r3   rk   rd   r?   rq   r4   rp   request_optionsabs_urlexisting_paramskvencoded_paramsencoded_bodysupplied_headersr   schemenetlocpath_fragment	post_data	generatorrU   valuer   s                              r9   _args_for_request_with_retriesz,_APIRequestor._args_for_request_with_retries  sS    (w?  G+)*6 188H0IO,-y)1++  MM((,,\:

 2v&H*< !O #!4!45;;= D1::d#./OAcrF+ 25Q11!OA&D ?*x6/A#'G/(3GfX6FGH$x ! F #4FLb((K#LM
 (//s;CCE3Ot::"&@L *L(	*6#OI$>?&&6"	
 U?f0 5=W4E1a$VT>8D Iv#KK/3HH24	$$V\r2%335	:C:L:LN ' )	** "(*  '.446 %
U$% .112GH  01
 	
r;   ru   c          	         | j                  |||||||      \  }}	}
}}}}}t        d||	       t        d||       |r*| j                         j	                  ||	|
|||      \  }}}n)| j                         j                  ||	|
|||      \  }}}t        d|	|       t        d	|
       d|v r|d   }t        dt        |             |||fS )Nrq   r4   rp   Request to Stripe apir3   rk   Post detailsr  api_versionr   _usageStripe API responser  response_codeAPI response bodybody
Request-IdDashboard link for requestlink)r  r   r   rP   request_stream_with_retriesrequest_with_retriesr   rE   r3   rk   rd   r?   ru   rq   r4   rp   r   r   r  r   r   r  rcontentr~   r   
request_ids                      r9   ry   z_APIRequestor.request_raw  s7   * //% 0 
		
 	(WEn+	
 
 %%'CC$7 D 	 %%'<<$7 = 	 	&WEJ%H58#!,/J,#J/
 ((r;   c          	        K   |xs g }|dgz   }| j                  |||||||      \  }}	}
}}}}}t        d||	       t        d||       |r2| j                         j	                  ||	|
|||       d{   \  }}}n1| j                         j                  ||	|
|||       d{   \  }}}t        d	|	|
       t        d|       d|v r|d   }t        dt        |             |||fS 7 y7 Iw)z3
        Mechanism for issuing an API call
        asyncr  r  r  r  r  r  Nr  r  r  r  r  r  r  )r  r   r   rP   !request_stream_with_retries_asyncrequest_with_retries_asyncr   r!  s                      r9   r   z_APIRequestor.request_raw_async  sk      	! //% 0 
		
 	(WE$#	
 
 ++-OO$7 P  	 ++-HH$7 I  	 	&WEJ%H58#!,/J,#J/
 ((As%   A4C46C071C4(C2)AC42C4r~   c                 &    d|cxk  xr dk   S c  S )N   i,  r8   )rE   r~   s     r9   _should_handle_code_as_errorz*_APIRequestor._should_handle_code_as_errorG  s    %%#%%%%%%r;   r}   r   c                 d   	 t        |d      rt        t        |      j                  d      }t	        t        t
        |      ||      }| j                  |      r| j                  |||j                  ||       |S # t        $ r, t        j                  d||fz  t        t        |      ||      w xY w)Ndecodezutf-8z>Invalid response body from API: %s (HTTP response code was %d))hasattrr   bytesr,  r    rn   r   r   r   r*  r   data)rE   r}   r~   r   r4   rv   s         r9   r{   z!_APIRequestor._interpret_responseJ  s    	uh' UE*11':!S% D ,,U3&&udii8   	...16?UE" 	s   AA: :5B/r   c                 X   | j                  |      rt        |d      rt        t        |      j	                         }nCt        |d      r|j                         }n&t        d| j                         j                  z        | j                  ||||       t        d      t        |||      S )Ngetvaluereadz`HTTP client %s does not return an IOBase object which can be consumed when streaming a response./_interpret_response should have raised an error)r*  r-  r   r   r1  r2  NotImplementedErrorrP   rh   r{   RuntimeErrorr!   )rE   r   r~   r   r4   json_contents         r9   r   z+_APIRequestor._interpret_streaming_responsei  s     ,,U3vz*#GV4==?(%{{})A++-223  $$\5(HMA  (x@@r;   c                    K   | j                  |      rdj                  |2 cg c3 d {   }|t	        |||      S 7 6 nc c}w c}      }| j                  ||||       t        d      w)Nr;   r3  )r*  r   r{   r5  r"   )rE   r   r~   r   r4   chunkr6  s          r9   r   z1_APIRequestor._interpret_streaming_response_async  sq      ,,U388f$E$EUU -VUHEE %F$E$EFL$$\5(HMA s3   !A-AA 
>A 
AA-A 
 A,A-)NN)NNF):__name__
__module____qualname__r>   r   __annotations__r
   r&   r(   rF   rP   r$   rV   propertyrX   r[   r^   r`   classmethodrc   staticmethodr   rf   ro   rn   r	   r   r+   r   r   r   r!   r   r"   r   r   r   r   r   r   r   r,   r   r  boolr   objectintry   r   r.  r   r*  r    r{   r   r   r   r8   r;   r9   r=   r=   M   s   04Ix,-4 /3'+*+ $ *  D
/
	
 % % , , , , , , 	 	 
(
	
 
   /3,0  &*     c*+	 
 .)  "  S	"  
 L /3,0  &*     c*+	 
 .)  "  S	"  
 L /3,0 &*  c*+	
 .) " S	" 
F /3,0 &*  c*+	
 .) " S	" 
#:#	#J%
N4l4==*1=<J=F /3,0O
 &*O
O
 O
 c*+	O

 .)O
 "O
 O
 S	"O
j /3,0"I) &*I)I) I) c*+	I)
 .)I) I) "I) I) S	"I) 
vsGCH--	.I)^ /3,0"R) &*R)R) R) c*+	R)
 .)R) R) "R) R) S	"R) 
}U#S'#s(*;;	<R)h&# &$ &  #s(#	
  
>AA A #s(#	A
 A 
A>Fe$F F #s(#	F
 F 
#Fr;   r=   )Mior   r   r   r   typingr   r   r   r   r	   r
   r   r   r   r   typing_extensionsr   r   r   r   r   urllib.parser   r   r   rK   stripe._utilr   r   r   r   r   stripe._versionr   stripe._error_errorr   stripe.oauth_errorr    stripe._multipart_data_generatorr   r   stripe._encoder   r   stripe._stripe_responser    r!   r"   stripe._request_optionsr#   r$   r%   stripe._requestor_optionsr&   r'   stripe._http_clientr(   r)   r*   stripe._base_addressr+   stripe._api_moder,   stripe._app_infor-   stripe._stripe_objectr.   r   r2   rn   r<  r@  r:   rA  r=   r8   r;   r9   <module>rV     s            7 7   $  ( C " B 
 
  - $(2*+ !% $3c 3W 3 3JFF JFr;   