+
    i                          ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	H
t
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHtHtHtHtHtHtHtHt ^ R	I H!t!H"t"H#t#H$t$ ^ RI%t%^ R
I%H&t& ^ RI'H(t(H)t)H*t* ]PV                  ! ],4      t-Rt.]]R.]/3,          ,          t0R t1R t2R R lt3RNR R llt4R R lt5R R lt6 ! R R4      t7 ! R R]74      t8 ! R R]74      t9 ! R R4      t: ! R  R];4      t<R! t=R" R# lt>R$R/R% R& llt?R'RR(RR)^ R*^R+RR,RR-RR.RR/R0R1R0R$RR2RR3R4R5R0R6R7R8R4/R9 R: llt@ROR; R< lltARPR> R? lltB ! R@ RA]4      tCRB]D! RC4      R(RRD]-P                  R,RR-RRERR$RRFRR6R7RGR0RHR=/RI RJ lltF ! RK RL4      tGRORM ltHR# )Q    N)ThreadPoolExecutorTimeoutErroras_completed)	parsedate)partial)	NOT_FOUND)count)create_default_context)	AnyCallableIteratorListMapping
NamedTupleOptionalTupleUnion)quoteurlparseurlsplit
urlunparse)
exceptions)performanceutilversionREDACTEDUrlErrorc                     \        \        V R R7      4      pV^,          '       g!   V^,          '       d   V^,          V^&   RV^&   \        V4      # )http)scheme )listr   r   )url
parsed_urls   & 6/usr/lib/python3/dist-packages/cloudinit/url_helper.py	_cleanurlr&   1   sG    hs623Ja==Z]] #1
1
1j!!    c                 2    R  pT pV F  pV! W44      pK  	  V# )c                     \        \        V 4      4      pV^,          pV'       d!   VP                  R4      '       g
   VR,          pV\        \	        V4      RR7      ,          pW2^&   \        V4      # )   /z/:)safe)r"   r   endswithr   strr   )r#   add_on
url_parsedpaths   &&  r%   combine_single#combine_url.<locals>.combine_single<   sZ    (3-(
!}c**CKDc&k--1*%%r'    )baseadd_onsr2   r#   r/   s   &*   r%   combine_urlr7   ;   s'    & CS) Jr'   c                $    V ^8  d   QhR\         /# r*   returnint)formats   "r%   __annotate__r>   K   s      s r'   c           
     t   \         P                  R\         P                  R\         P                  R\         P                  R\
        R/pVP                  \        V 4      4      pV'       gN   \        V \        4      '       d!   V P                  '       d   V P                  pV# \        P                  R4       RpV# )z4helper for read_ftps to map return codes to a number,      iX  i  z9Unexpected exception type while connecting to ftp server.i)ftpliberror_reply
error_temp
error_permerror_protoEOFErrorgettype
isinstanceOSErrorerrnoLOGwarning)excftp_error_codescodes   &  r%   "ftp_get_return_code_from_exceptionrS   K   s     	C33C#O tCy)Dc7##			99D K	 KKK DKr'   c                @    V ^8  d   QhR\         R\        R\        RR/# )r*   r#   timeoutkwargsr:   FtpResponse)r.   floatdict)r=   s   "r%   r>   r>   b   s.      3    r'   c           
        \        V 4      pVP                  '       g   \        R\        RV R7      h\        P
                  ! 4       ;_uu_ 4       pVP                  ;'       g    ^pVP                  ;'       g    RpRVP                  8X  EdW    \        P                  ! \        4       R7      p\        P                  RV V4       TP                  VP                  TT;'       g    RR	7       \        P                  RT4        TP#                  TTP$                  ;'       g    RR7       \        P                  R4       TP'                  4         \        P                  RTP,                  4       TP/                  RTP,                   2TP0                  R7       \3        TP5                  4       T 4      \        P                  R4       TP7                  4        uuRRR4       #  \        P8                  ! 4       p
\        P                  RW4       T
P                  VP                  TT;'       g    RR	7       \        P                  RV4       T
P#                  TVP$                  ;'       g    RR7       \        P                  RVP,                  4       V
P/                  RVP,                   2VP0                  R7       \3        VP5                  4       V 4      \        P                  R4       V
P7                  4        uuRRR4       #   \        P                   d(   p\!        T4      p	\        R
T  RT	 R2T	RT R7      ThRp?ii ; i  \        P(                   d+   p\        P+                  R4       \        RRRT R7      ThRp?ii ; i  \        P                   d(   p\!        T4      p	\        RT  RT	 R2T	RT R7      ThRp?ii ; i  \        P                  R4       TP7                  4        i ; i  \        P                   d(   p\!        T4      p	\        RT  RT	 R2T	RT R7      ThRp?ii ; i  \        P                  R4       X
P7                  4        i ; i  + '       g   i     R# ; i)aO  connect to URL using ftp over TLS and read a file

when using strict mode (ftps://), raise exception in event of failure
when not using strict mode (ftp://), fall back to using unencrypted ftp

url: string containing the destination to read a file from. The url is
    parsed with urllib.urlsplit to identify username, password, host,
    path, and port in the following format:
        ftps://[username:password@]host[:port]/[path]
    host is the only required component
timeout: maximum time for the connection to take
kwargs: unused, for compatibility with read_url
returns: UrlResponse
zInvalid url providedNcauserR   headersr#   	anonymousftps)contextz3Attempting to connect to %s via port [%s] over tls.      @)hostportrU   z1Reading file from server over tls failed for url z []z"Attempting to login with user [%s]r!   )userpasswdzCreating a secure connectionzAttempted to connect to an insecure ftp server but used a scheme of ftps://, which is not allowed. Use ftp:// to allow connecting to insecure ftp servers.rB   zReading file: %szRETR )callbackzClosing connectionz,Reading file from ftp server failed for url z(Attempting to connect to %s via port %s.)r   hostnamer   r   ioBytesIOrc   usernamer    rC   FTP_TLSr
   rN   debugconnect
all_errorsrS   loginpasswordprot_prF   rO   r1   
retrbinarywriterW   getvaluecloseFTP)r#   rU   rV   	url_partsbufferrc   re   ftp_tlserR   ftps   &&,        r%   	read_ftpsr}   b   s      I(y$C
 	
 
~~##!!00[Y%%% ..24 		I
 "++#NNs     II:DA$--33   		89 " 		,inn=""INN+,v|| #  #6??#4c: 		./S 
Vjjl		> "++#NNs  
 		>E		$--33   		,inn=y~~&67&,,O"6??#4c: 		./		U 
$ $$ 
9!<**-ba9   
& $$ C
 N  	 	. $$ 
9!<++.%r$q:   
 		./( $$ 
9!<++.%r$q:   
 		./		U 
s   )Q8QAL$L,QM"-MA#N3%Q$BO1,A+O1%QM"L>>MQN%N  NQO"N??OO'O..Q1P-"P((P--P00'QQQ+	c                (    V ^8  d   QhR\         RR/# )r*   r1   r:   FileResponser.   )r=   s   "r%   r>   r>      s     M MS M~ Mr'   c                <   VP                  R4      '       d   \        P                  RV 4        \        P                  ! V 4      p\        W 4      #   \         d   p\        T\        RT R7      ThRp?i\         d   p\        Y3P                  RT R7      ThRp?ii ; i)zeread a binary file and return a FileResponse

matches function signature with read_ftps and read_url
dataz'Unable to post data to file resource %sNr[   )rI   rN   rO   r   load_binary_filer   FileNotFoundErrorr   r   IOErrorrM   )r1   rV   contentsr{   s   &,  r%   
_read_filer      s    
 zz&=tDM((.H++ OQY$GQN MQWWdE1LMs)    A BA//B<B=BBc                2    V ^8  d   QhR\         R,          /# )r*   r:   )r   UrlResponserW   )r   )r=   s   "r%   r>   r>      s     & &
78&r'   c                   V P                  4       p  \        V 4      pTP                  pTR8X  g   T '       d%   RT ^ ,          8X  d   \        TP                  3/ TB # TR9   d   \        T 3/ TB # TR9   d   \        T 3/ TB # \        P                  RT4       \        T 3/ TB #   \         d   p\        Y0R7      ThRp?ii ; i)a   Wrapper function around readurl to allow passing a file path as url.

When url is not a local file path, passthrough any kwargs to readurl.

In the case of parameter passthrough to readurl, default values for some
parameters. See: call-signature of readurl in this module for param docs.
)r\   r#   Nfiler+   zAttempting unknown protocol %s)r|   r_   )r   https)lstripr   
ValueErrorr   r    r   r1   r}   readurlrN   rO   )r#   rV   parsedr{   r    s   &,   r%   read_file_or_urlr      s     **,C0# ]]FCC3q6M&++000	?	"'''	$	$s%f%%4f=s%f%%  0Q(a/0s   B$ $C/B<<Cc                   6   a  ] tR tRt o RR ltR tR tRtV tR# )StringResponsei  c                8    W0n         / V n        Wn        W n        R # N)rR   r]   r   r#   )selfr   r#   rR   s   &&&&r%   __init__StringResponse.__init__  s    	 r'   c                     V P                   ^8H  #    rR   r   argsrV   s   &*,r%   okStringResponse.ok  s    yyCr'   c                8    V P                   P                  R 4      # )zutf-8)r   decoder   s   &r%   __str__StringResponse.__str__  s    }}##G,,r'   )rR   r   r]   r#   Nr   )	__name__
__module____qualname____firstlineno__r   r   r   __static_attributes____classdictcell____classdict__s   @r%   r   r     s      - -r'   r   c                   B   a a ] tR tRt oRV3R lV 3R llltRtVtV ;t# )r   i   c                &   < V ^8  d   QhRS[ RS[/# r*   r   r#   bytesr.   )r=   r   s   "r%   r>   FileResponse.__annotate__!  s     3 3 3S 3r'   c                *   < \         SV `  WVR 7       R# )r   Nsuperr   )r   r   r#   rR   	__class__s   &&&&r%   r   FileResponse.__init__!  s    T2r'   r4   r   r   r   r   r   r   r   r   __classcell__r   r   s   @@r%   r   r      s     3 3 3r'   r   c                   >   a a ] tR tRt oV3R lV 3R lltRtVtV ;t# )rW   i%  c                &   < V ^8  d   QhRS[ RS[/# r   r   )r=   r   s   "r%   r>   FtpResponse.__annotate__&  s     ( ( (S (r'   c                &   < \         SV `  W4       R # r   r   )r   r   r#   r   s   &&&r%   r   FtpResponse.__init__&  s    'r'   r4   r   r   s   @@r%   rW   rW   %  s     ( ( (r'   rW   c                      a  ] tR tRt o V 3R lR lt]V 3R lR l4       t]V 3R lR l4       tRV 3R lR	 llt]R
 4       t	]V 3R lR l4       t
R tRV 3R lR lltRtV tR# )r   i*  c                4   < V ^8  d   QhRS[ P                  /# )r*   response)requestsResponse)r=   r   s   "r%   r>   UrlResponse.__annotate__+  s     " "!2!2 "r'   c                    Wn         R # r   	_response)r   r   s   &&r%   r   UrlResponse.__init__+  s    !r'   c                    < V ^8  d   QhRS[ /# r9   )r   )r=   r   s   "r%   r>   r   /  s     & &% &r'   c                b    V P                   P                  f   R# V P                   P                  # )Nr'   )r   contentr   s   &r%   r   UrlResponse.contents.  s%    >>!!)~~%%%r'   c                    < V ^8  d   QhRS[ /# r9   r   )r=   r   s   "r%   r>   r   5  s     " "S "r'   c                .    V P                   P                  # r   )r   r#   r   s   &r%   r#   UrlResponse.url4  s    ~~!!!r'   c                    < V ^8  d   QhRS[ /# r9   )bool)r=   r   s   "r%   r>   r   8  s       r'   c                \    R pV'       d   Rp^V P                   u;8:  d
   V8  d    R#  R# R# )r@   rA   TFr   )r   redirects_okuppers   && r%   r   UrlResponse.ok8  s-    E$))#e# $ r'   c                .    V P                   P                  # r   )r   r]   r   s   &r%   r]   UrlResponse.headersA  s    ~~%%%r'   c                    < V ^8  d   QhRS[ /# r9   r;   )r=   r   s   "r%   r>   r   F  s     * *c *r'   c                .    V P                   P                  # r   )r   status_coder   s   &r%   rR   UrlResponse.codeE  s    ~~)))r'   c                .    V P                   P                  # r   )r   textr   s   &r%   r   UrlResponse.__str__I  s    ~~"""r'   c                L   < V ^8  d   QhRS[ S[,          RS[RS[S[,          /# )r*   
chunk_sizedecode_unicoder:   )r   r<   r   r   r   )r=   r   s   "r%   r>   r   L  s2     K K"3-K=AK	%Kr'   c              #  X   "   V P                   P                  W4       Rj  xL
  R#  L5i)aD  Iterates over the response data.

When stream=True is set on the request, this avoids reading the content
at once into memory for large responses.

:param chunk_size: Number of bytes it should read into memory.
:param decode_unicode: If True, content will be decoded using the best
available encoding based on the response.
N)r   iter_content)r   r   r   s   &&&r%   r   UrlResponse.iter_contentL  s      >>..zJJJs   *(*r   N)F)   F)r   r   r   r   r   propertyr   r#   r   r]   rR   r   r   r   r   r   s   @r%   r   r   *  s     " " & &
 " "  & & * *#K K Kr'   r   c                   6   a  ] tR tRt o RV 3R lR lltRtV tR# )r   i[  Nc          	      b   < V ^8  d   QhRS[ RS[S[,          RS[S[,          RS[S[,          /# )r*   r\   rR   r]   r#   )r   r   r<   r   r.   )r=   r   s   "r%   r>   UrlError.__annotate__\  s@       sm '"	
 c]r'   c                    \         P                  V \        V4      4       Wn        W n        Vf   / MTV n        W@n        R # r   )r   r   r.   r\   rR   r]   r#   )r   r\   rR   r]   r#   s   &&&&&r%   r   UrlError.__init__\  s4     	s5z*
	&-o7r'   r[   )NNN)r   r   r   r   r   r   r   r   s   @r%   r   r   [  s       r'   c                 $   / p\        V 4      P                  pVR 8X  dr   V'       dj   RV9   d   VR,          '       d   VR,          VR&   MRVR&   RV9   d   RV9   d   VR,          VR,          .VR&   V# RV9   d   \        VR,          4      VR&   V# )r   ca_certsverifyT	cert_filekey_filecert)r   r    r.   )r#   ssl_detailsssl_argsr    s   &&  r%   _get_ssl_argsr   j  s    Hc]!!F[$Z)@)@!,Z!8HX!%HX+%**CK(J' HV O K'";{#;<HVOr'   c                0    V ^8  d   QhR\         R\        /# )r*   retry_afterr:   )r.   rX   )r=   s   "r%   r>   r>   |  s     ! !# !% !r'   c                    \        V 4      pV#   \         d   p \        T 4      pT'       g   \        R4      Th\        \        P                  ! T4      \        P                  ! 4       ,
          4      pM)  \         d    \
        P                  RT 4       ^p Mi ; iT^ 8  d   \
        P                  R4       ^p Rp?T# Rp?ii ; i)a(  Parse a Retry-After header value into an integer.

: param retry_after: The value of the Retry-After header.
    https://www.rfc-editor.org/rfc/rfc9110.html#section-10.2.3
    https://www.rfc-editor.org/rfc/rfc2616#section-3.3
: return: The number of seconds to wait before retrying the request.
z(Failed to parse Retry-After header valuezGFailed to parse Retry-After header value: %s. Waiting 1 second instead.zBRetry-After header value is in the past. Waiting 1 second instead.N)rX   r   r   timemktimerN   info)r   to_waitrP   
time_tuples   &   r%   _get_retry_afterr   |  s    $0 N/  	";/J > DKK
3diikABG 	HH,
 G	 Q;HH, GN/s3    CAA43C4#BCB!CCexception_cbc                R    V ^8  d   QhR\         R\        R\        \        ,          /# )r*   errorr   r:   )r   ExceptionCallbackr   rX   )r=   s   "r%   r>   r>     s,          $  e_	 r'   c               l   V'       d   V! V 4      '       d   R# V P                   '       d   V P                   R8X  do   \        P                  RV P                  4       V P                  '       d&   \        V P                  P                  RR4      4      # \        P                  R4       ^# V'       g   R# V h)a  Handle exceptions raised during request processing.

If we have no exception callback or the callback handled the error or we
got a 503, return with an optional timeout so the request can be retried.
Otherwise, raise the error.

:param error: The exception raised during the request.
:param response: The response object.
:param exception_cb: Callable to handle the exception.

:return: Optional time to wait before retrying the request.
Ni  zNEndpoint returned a 503 error. HTTP endpoint is overloaded. Retrying URL (%s).zRetry-After1z7Unable to introspect response header. Waiting 1 second.)rR   rN   rO   r#   r]   r   rI   r   )r  r   s   &$r%   _handle_errorr    s    " U++zzzejjC'>II	

 ===#EMM$5$5mS$IJJJK
Kr'   r   rU   retriessec_betweenr]   
headers_cbheaders_redactr   check_statusTallow_redirectssessioninfiniteFlog_req_resprequest_methodr!   streamc                <    V ^8  d   QhR\         R\        R\        /# )r*   r   r  r:   )r  r   r   )r=   s   "r%   r>   r>     s/     m= m= $m=$ %m=& 'm=r'   c          	        \        V 4      p RV RV/pVP                  \        W4      4       V
VR&   V'       g   V'       d   RMRpVVR&   Ve5   \        V\        4      '       d   VVR&   M\        \        V4      ^ 4      VR&   Vf   . p^pV'       d   \        \        V4      ^,           ^4      pR	\        P                  ! 4       ,          pVe   VP                  4       pM/ pV'       d   VVR
&   Vf   RpVf   \        P                  ! 4       p\        4        EFc  pV'       d	   V! V 4      pRV9  d   VVR&   VVR&   / pVP                  4        F  w  ppVR
8X  d   K  VR8X  dq   V'       di   V Uu. uF  pVP                  V4      '       g   K  VNK   	  ppV'       d5   \        P                   ! V4      VX&   V F  p\"        VV,          V&   K  	  K  K  VVV&   K  	   V'       d$   \$        P'                  RTV'       d   RMTV V4       VP(                  ! R/ VB pV	'       d   VP+                  4        \$        P'                  RV VP,                  \/        VP0                  4      V^,           4       \3        V4      u # 	  \I        R4      hu upi   \4        P6                   d   p\9        TT R7      ThRp?i\4        P:                   dD   p\9        TTP<                  P,                  TP<                  P>                  T R7      pTp Rp?M6Rp?i\4        P@                   d   p\9        TT R7      pTpRp Rp?MRp?ii ; i\C        TTR7      pT'       g"   T;'       g    T^,           T8  pT'       g   TThT;'       g    Tp T^ 8  g   EKs  T'       d   \$        P'                  RT4       \D        PF                  ! T 4       EK  )a  Wrapper around requests.Session to read the url and retry if necessary

:param url: Mandatory url to request.
:param data: Optional form data to post the URL. Will set request_method
    to 'POST' if present.
:param timeout: Timeout in seconds to wait for a response. May be a tuple
    if specifying (connection timeout, read timeout).
:param retries: Number of times to retry on exception if exception_cb is
    None or exception_cb returns True for the exception caught. Default is
    to fail with 0 retries on exception.
:param sec_between: Default 1: amount of seconds passed to time.sleep
    between retries. None or -1 means don't sleep.
:param headers: Optional dict of headers to send during request
:param headers_cb: Optional callable returning a dict of values to send as
    headers during request
:param headers_redact: Optional list of header names to redact from the log
:param ssl_details: Optional dict providing key_file, ca_certs, and
    cert_file keys for use on in ssl connections.
:param check_status: Optional boolean set True to raise when HTTPError
    occurs. Default: True.
:param allow_redirects: Optional boolean passed straight to Session.request
    as 'allow_redirects'. Default: True.
:param exception_cb: Optional callable to handle exception and returns
    True if retries are permitted.
:param session: Optional exiting requests.Session instance to reuse.
:param infinite: Bool, set True to retry indefinitely. Default: False.
:param log_req_resp: Set False to turn off verbose debug messages.
:param request_method: String passed as 'method' to Session.request.
    Typically GET, or POST. Default: POST if data is provided, GET
    otherwise.
:param stream: if False, the response content will be immediately
downloaded.
r#   r  r  POSTGETmethodNrU   zCloud-Init/%sr   z
User-Agentr]   z'[%s/%s] open '%s' with %s configurationr  z(Read from %s (%s, %sb) after %s attempts)r#   rR   r]   r#   r   1Please wait %s seconds while we wait to try againz"This path should be unreachable...r4   )%r&   updater   rK   tuplemaxrX   r<   r   version_stringcopyr   Sessionr	   itemsrI   deepcopyr   rN   rm   requestraise_for_statusr   lenr   r   r   SSLErrorr   	HTTPErrorr   r]   RequestExceptionr  r   sleepRuntimeError)!r#   r   rU   r  r  r]   r	  r
  r   r  r  r   r  r  r  r  r  req_argsmanual_tries
user_agentifiltered_req_argskvmatched_headerskeyr   r{   	url_errorraised_exceptionresponse_sleep_time
will_retry
sleep_times!   &$$$$$$$$$$$$$$$$                r%   r   r     sg   j C.Cs&H OOM#34"1H#'U'HXgu%%")HY"%eGna"8HYL3w<!+Q/ G$:$:$<=J,,.""$ W oGw&$.GL!%NN$DAqF{I~..<"Ina11n"I"+/==+;%a(.4<)!,S1  / #
 ()!!$ %(			="*J% 22H))+II:$$H$$%Q x(([ f ;
<<M #JB "" 	. 1#&A-## 	! ZZ++

**	I  !** 	 ,I H	
 ,%
 #!;;a!el&:J%55(77K
?		G JJz"s[   0J
J
J&J?#J#AJL;$J22L;	L;
9LL;L; L66L;c                    V ^8  d   QhR\         R\        3,          R\        R\        R\        P
                  R\        \        ,          R\        /# )r*   func.addrrU   eventdelayr:   )r   r   r.   r<   	threadingEventr   rX   )r=   s   "r%   r>   r>   s  sU      
38

  ??	
 E? 	r'   c                V    V'       d   VP                  VR7      '       d   R# V ! W4      # )z Execute func with optional delayrU   Nwaitr:  r;  rU   r<  r=  s   &&&&&r%   _run_func_with_delayrE  s  s(     
 ::e:$$r'   333333?c                    V ^8  d   QhR\         R\        3,          R\        \        ,          R\        R\
        R\        \        \        ,          \        \        ,          3,          /# )r*   r:  .	addressesstagger_delayrU   r:   )	r   r   r   r.   rX   r<   r   r   r   )r=   s   "r%   r>   r>     sa     P- P-
38
P-CyP- P- 	P-
 8C=(;//0P-r'   c                   RpRpRp. p\         P                  ! 4       p\        \        V4      R7      p	 \	        V4       U
Uu/ uF'  w  rV	P                  \        V VVVW,          R7      VbK)  	  pp
p\        WR7       Fx  pW,          pVP                  4       pV'       d   TpVP                  ! V4       K9  VP                  4       pV'       g   KS  VP                  4        WT3u V	P                  RR7       # 	  V'       d   \        P                  RVV4       Vh\        P                  RV4       \!        R	4      hu upp
i   \"         dG    \        P                  R
RP%                  T4      RP%                  \'        \(        T4      4      4        Mi ; i T	P                  RR7       YT3#   T	P                  RR7       i ; i)a  execute multiple callbacks in parallel

Run blocking func against two different addresses staggered with a
delay. The first call to return successfully is returned from this
function and remaining unfinished calls are cancelled if they have not
yet started
N)max_workersrD  rA  FrB  z<Exception(s) %s during request to %s, raising last exceptionzEmpty result for address %szNo result returnedzJTimed out waiting for addresses: %s, exception(s) raised while waiting: %s )r>  r?  r   r%  	enumeratesubmitrE  r   	exceptionappendresultsetshutdownrN   rm   r  r   r   joinmapr.   )r:  rH  rI  rU   return_resultreturned_addresslast_exceptionr   is_doneexecutorr.  r;  futuresfuturereturn_exceptions   &&&&           r%   
dual_stackr^    s    M.2NJooG "c)n=H5& %Y/

 0 OO$(    0 	 

 #7<F&%//1!1!!.1 & = KKM,<<2 	u%O =$ II- 	 ! II35EF122S

X  
		4HHYHHSj)*		

	
 	u%,, 	u%sD   E -D</AE E 8	E A E AFF, FF, ,G c                   ,   a  ] tR tRt o V 3R ltRtV tR# )HandledResponsei  c                n   < V ^8  d   Qh/ S[ S[,          ;R&   S[ S[,          ;R&   S[ S[,          ;R&   # )r*   r#   r   	wait_time)r   r.   r   rX   )r=   r   s   "r%   r>   HandledResponse.__annotate__  s7     	#  {##   r'   r4   N)r   r   r   r   __annotate_func__r   r   r   s   @r%   r`  r`    s      r'   r`  max_waitinf	status_cbr8  sleep_time_cbconnect_synchronouslyasync_delayc                   V ^8  d   QhR\         R\        \         ,          R\        R\        \        ,          R\        \         ,          R\        R\        \        \        \         .\         3,          ,          R\
        R	\        R
\         /
# )r*   re  rU   rg  r	  r8  r   rh  r  ri  rj  )rX   r   r   r  r   r.   r   )r=   s   "r%   r>   r>     s     | | | e_	|
 | "| | $| Hc5\5%89:| |  | |r'   c                 a aaaaa	aaaaaaa R V3R llpRR R lloR R loR VV3R lloR	 VVV	3R
 lloR VVVVVVV 3R llpR VVVV 3R llp\         P                  ! 4       pS'       d   V'       d   \        R4      hV
'       d   TMTpT;'       g    Tp^ oRp V! WWs4      pRoVP                  '       d#   VP                  VP                  P
                  3# VP                  '       d.   \         P                  ! VP                  4       S^,           oRoK  V! VS4      pS! SVV4      '       d    R# S^,           o\        P                  RV4       \         P                  ! V4       \         P                  ! 4       pV'       g   K  VV,           VS,           8  g   EK  SVV,
          ,
          pV^ 8:  g   EK!   R# )a  Wait for a response from one of the urls provided.

:param urls: List of urls to try
:param max_wait: Roughly the maximum time to wait before giving up
    The max time is *actually* len(urls)*timeout as each url will
    be tried once and given the timeout provided.
    a number <= 0 will always result in only one try
:param timeout: Timeout provided to urlopen
:param status_cb: Callable with string message when a url is not available
:param headers_cb: Callable with single argument of url to get headers
    for request.
:param headers_redact: List of header names to redact from the log
:param sleep_time: Amount of time to sleep between retries. If this and
    sleep_time_cb are None, the default sleep time defaults to 1 second
    and increases by 1 seconds every 5 tries. Cannot be specified along
    with `sleep_time_cb`.
:param exception_cb: Callable to handle exception and returns True if
    retries are permitted.
:param sleep_time_cb: Callable with 2 arguments (response, loop_n) that
    generates the next sleep time. Cannot be specified
    along with 'sleep_time`.
:param request_method: Indicates the type of HTTP request:
    GET, PUT, or POST
:param connect_synchronously: If false, enables executing requests
    in parallel
:param async_delay: Delay before parallel metadata requests, see RFC 6555

:return: tuple of (url, response contents), on failure, (False, None)

:raises: UrlError on unrecoverable error
c                0    V ^8  d   QhR\         R\        /# )r*   loop_numberr:   )r<   rX   )r=   s   "r%   r>   "wait_for_url.<locals>.__annotate__  s     N N3 N5 Nr'   c                 0   < Se   S# V^,          ^,           # r   r4   )_rn  r8  s   &&r%   default_sleep_time(wait_for_url.<locals>.default_sleep_time  s    '3zM9IA9MMr'   c                <    V ^8  d   QhR\         R\         R\         /# )r*   re  
start_timer8  )rX   )r=   s   "r%   r>   ro    s!     
 
 
E 
u 
r'   c                    V \        R4      R39   d   R# V ^ 8*  ;'       g'    \        P                  ! 4       V,
          V,           V 8  # )z4Check if time is up based on start time and max waitrf  NF)rX   r   	monotonic)re  ru  r8  s   &&&r%   timeupwait_for_url.<locals>.timeup  sE    ed++A 
 
NNz)J6A	
r'   c                    V ^8  d   QhR\         \        ,          R\         \        ,          R\        \         \        ,          \        3,          /# )r*   r   r#   r:   )r   r   r.   r   r   )r=   s   "r%   r>   ro    s<     '! '!;''!.6sm'!	x!3&	''!r'   c                   RpRpV '       d	   V'       g   Rp\        \        V4      4      pW23#  V P                  P                  4        T P                  '       gC   RT P                  ,          p\        \        T4      T P                  T P                  TR7      pY23# T P                  4       '       g@   RT P                  ,          p\        \        T4      T P                  T P                  TR7      pY23#   \        P
                  P                   dO   p\        TTP                  P                  TP                  P                  TR7      pT\        T4      3u Rp?# Rp?ii ; i)z?Map requests response code/contents to internal "UrlError" typer!   NzRequest timed outr  zempty response [%s]zbad status code [%s])r   r   r   r$  r   r   r'  r   r   r]   r.   r   rR   r   )r   r#   reasonurl_excr{   s   &&   r%   handle_url_response)wait_for_url.<locals>.handle_url_response  s7    S(Fz&12G?"	# //1    *hmm<F6"]] ((	G    +x}}=F6"]] ((	G   3 "",, 	#ZZ++

**	G CF?"	#s   C5 5E"AEE"E"c                
   V ^8  d   QhR\         \        .\        \        \        ,          \        \
        ,          3,          3,          R\        \        \        \        ,          3,          R\        R\        R\         R\        /# )r*   url_reader_cburlsru  exc_cblog_cbr:   )r   r   r   r   r.   r   r   r   r<   r  r`  )r=   s   "r%   r>   ro  D  su     *
 *
E5#(==>>
*
 CcN#	*

 *
 "*
 *
 
*
r'   c           	       < RpRp V ! V4      w  rgS! Wv4      w  rV'       g   \        WgRR7      #  \        \        P
                  ! 4       V,
          4      p
S'       d
   RS,          MRpRT;'       g    \        VR	R	4      : R
V
: RV: RV: 2pV! V4       \        RR\        V\        4      '       d   \        WR7      R7      # RR7      #   \         d   p	RT	,          pT	p Rp	?	LRp	?	i\         d   p	RT	,          pT	p Rp	?	LRp	?	ii ; i)z:Execute request, handle response, optionally log exceptionr!   N)rb  zrequest error [%s]zunexpected error [%s]z%ss	unlimitedz	Calling 'r#   z
' failed [r+   z]: r  r#   r   rb  )	r`  r   	Exceptionr<   r   rw  getattrrK   r  )r  r  ru  r  r  r|  r#   r   r}  r{   
time_takenmax_wait_str
status_msgr~  re  s   &&&&&        r%   read_url_handle_exceptions0wait_for_url.<locals>.read_url_handle_exceptionsD  s    
	)$/MC1(@OG&sEE  )J67
+3ux'1177E511	

 	z gx00 g;	
 	
 
 	
!  	)A-FG 	,q0FG	s)   (C DC((D5D6DDc                <    V ^8  d   QhR\         R\        R\        /# )r*   r#   rU   r:   )r.   r<   r   )r=   s   "r%   r>   ro  p  s!     
 
 
s 
{ 
r'   c           	      >   < \        T Sf   / MS! V 4      SVRSR7      # )NF)r]   r
  rU   r  r  )r   )r#   rU   r	  r
  r  s   &&r%   read_url_cb!wait_for_url.<locals>.read_url_cbp  s-    $,B*S/))
 	
r'   c                $    V ^8  d   QhR\         /# r9   r`  )r=   s   "r%   r>   ro  z  s     "M "M	"Mr'   c                  <a R VV3R llp. pS F  p\         P                  ! 4       pS
^ 8w  db   S'       gZ   S! SV 4      '       d   \        RRRR7      u # Se7   S'       d/   VS,           V S,           8  d   \        V S,           V,
          4      oS! WFWV4      pVP                  '       d   Vu # VP
                  '       g   K  VP                  VP
                  4       K  	  V'       d   \        V4      MRp	\        RRV	R7      # )zliterate over list of urls, request each one and handle responses
and thrown exceptions individually per url
c                $    V ^8  d   QhR\         /# )r*   r#   r   )r=   s   "r%   r>   ;wait_for_url.<locals>.read_url_serial.<locals>.__annotate__  s     	4 	43 	4r'   c                    < V S! V S4      3# r   r4   )r#   r  rU   s   &r%   url_reader_serial@wait_for_url.<locals>.read_url_serial.<locals>.url_reader_serial  s    S'233r'   Nr  )r   rw  r`  r<   r   rb  rP  r  )ru  rU   r  r  r  
wait_timesr#   nowoutrb  loop_nre  must_try_againr  r  rx  r  s   &f&&      r%   read_url_serial%wait_for_url.<locals>.read_url_serialz  s    	4 	4 
C.."C{>(J//* 44  (w*x*?@ ":#8C"?@G,!
FC |||
!!#--0+ , (2C
Ot	4$)LLr'   c                $    V ^8  d   QhR\         /# r9   r  )r=   s   "r%   r>   ro    s     
 
	
r'   c                @   < \        \        SSVR7      pS! VSWV4      # )zpass list of urls to dual_stack which sends requests in parallel
handle response and exceptions of the first endpoint to respond
)rI  rU   )r   r^  )	ru  rU   r  r  url_reader_parallelrj  r  r  r  s	   &&&& r%   read_url_parallel'wait_for_url.<locals>.read_url_parallel  s4     &%	
 *z6
 	
r'   z3sleep_time and sleep_time_cb are mutually exclusiveNTFr  )r   )FN)
r   rw  r   r   r#   r   rb  r)  rN   rm   )r  re  rU   rg  r	  r
  r8  r   rh  r  ri  rj  rr  r  r  ru  do_read_urlcalculate_sleep_timer   respcurrent_sleep_timecurrent_timer~  r  r  r  r  rx  s   fd$$ddd$$d$d          @@@@@@r%   wait_for_urlr    s   ^N N
'!R*
 *
X
 
"M "MH
 
  !JmNOO 16G  )>>,>FH
:H===88T]]3333^^^JJt~~&aZF!N1(FC(J(:;;"  !		?	
 	

%& ~~'7|g-
X0EE,";<G!|r'   c                   `   a  ] tR tRt o RR ltR tR tR tR tR t	R	 t
R
 tR tR tRtV tR# )OauthUrlHelperi  Nc                f   Wn         T;'       g    R V n        W n        W0n        WPn        RV n        ^V n        V P                  V P                  V P                   3p\        V4      '       g	   RV n        M\        V4      '       g   \        R4      hV P                  4       pT;'       g    / V n        R# )r!   TFzBall or none of token_key, token_secret, or consumer_key can be setN)consumer_keyconsumer_secret	token_keytoken_secretskew_data_file	_do_oauthskew_change_limitanyallr   read_skew_file	skew_data)r   r  r  r  r  r  requiredolds   &&&&&&  r%   r   OauthUrlHelper.__init__  s     ).44""(,!"NND$5$5t7H7HI8}}"DNX* 
 !!#r'   c           	        V P                   '       d   \        P                  P                  V P                   4      '       dw   \        P
                  ! R V P                    24      ;_uu_ 4        \        V P                   RR7      ;_uu_ 4       p\        P                  ! V4      uuRRR4       uuRRR4       # R#   + '       g   i     M; iRRR4       R#   + '       g   i     R# ; i)zReading rmodeN)	r  osr1   isfiler   Timedopenjsonload)r   fps   & r%   r  OauthUrlHelper.read_skew_file  s    277>>$2E2E#F#F""Xd.A.A-B#CDDd###G Gyy}G GDD 	G GD 	 ED s$   - CB:	#
C:C
CC(	c           	        V P                   '       g   R # V P                  4       pVf   / pW#V&   \        P                  ! RV P                    24      ;_uu_ 4        \	        V P                   RR7      ;_uu_ 4       pVP                  \        P                  ! V4      4       R R R 4       R R R 4       R #   + '       g   i     L; i  + '       g   i     R # ; i)NzWriting wr  )r  r  r   r  r  rt   r  dumps)r   rb   valuecurr  s   &&&  r%   update_skew_fileOauthUrlHelper.update_skew_file  s    """!!#;CD	$*=*=)>?@@$cC
 C
HHTZZ_%C
@@ C
 C
@@@s$    C:&B2	 C2C=CC	c                   \        V\        4      '       d#   VP                  R 8X  g   VP                  R8X  g   R# RVP                  9  d#   \        P                  RVP                  4       R# VP                  R,          p \        P                  ! \        V4      4      p\        T\        P                  ! 4       ,
          4      p\        TP                  4      P                  pT P                  P                  T^ 4      p\!        Yu,
          4      T P"                  8  d(   T P%                  Ye4       \        P                  RYe4       YPP                  T&   R#   \         d"   p\        P                  RY$4        Rp?R# Rp?ii ; i)i  i  Ndatez$Missing header 'date' in %s responsez#Failed to convert datetime '%s': %sz$Setting oauth clockskew for %s to %d)rK   r   rR   r]   rN   rO   r   r   r   r  r<   r   r#   netlocr  rI   absr  r  )r   rO  r  remote_timer{   skewrb   old_skews   &&      r%   r   OauthUrlHelper.exception_cb  s   y(++3&)..C*?***KK>	O  (	++io6K
 ;,-	&-->>%%dA.x$"8"88!!$-KK>K#t  	KK=tG	s   E F#E??Fc           	     z   V P                   '       g   / # R p\        V4      P                  pV P                  '       dG   W0P                  9   d7   \	        \
        P
                  ! 4       4      V P                  V,          ,           p\        VV P                  V P                  V P                  V P                  VR7      # )N)r#   r  r  r  r  	timestamp)r  r   r  r  r<   r   oauth_headersr  r  r  r  )r   r#   r  rb   s   &&  r%   r	  OauthUrlHelper.headers_cb-  s    ~~~I	}##>>>dnn4DIIK(4>>$+??I**nn** 00
 	
r'   c                    \        V P                  VP                  R 4      4      VR &   \        V P                  VP                  R4      4      VR&   V! V/ VB # )r	  r   )r   _headers_cbrI   _exception_cb)r   wrapped_funcr   rV   s   &&&&r%   _wrappedOauthUrlHelper._wrapped?  s\    &fjj6 
| ")

> :"
~ T,V,,r'   c                .    V P                  \        W4      # r   )r  r  r   s   &*,r%   r  OauthUrlHelper.wait_for_urlH  s    }}\488r'   c                .    V P                  \        W4      # r   )r  r   r   s   &*,r%   r   OauthUrlHelper.readurlK  s    }}Wd33r'   c                z    R p V'       d	   V! V4      pV P                  V4       V#   T P                  T4       i ; i)Tr  )r   extra_exception_cbrO  rets   &&& r%   r  OauthUrlHelper._exception_cbN  s>    	)!(3i(
 i(s   ' ' :c                j    / pV'       d	   V! V4      pVP                  V P                  V4      4       V# r   )r  r	  )r   extra_headers_cbr#   r]   s   &&& r%   r  OauthUrlHelper._headers_cbW  s.    &s+Gts+,r'   )r  r  r  r  r  r  r  r  )NNNNz/run/oauth_skew.json)r   r   r   r   r   r  r  r   r	  r  r  r   r  r  r   r   r   s   @r%   r  r    s<     #6&8
$-94 r'   r  c           	           ^ RI Hp T'       d   \	        T4      pMRpTP                  TTTTTP                  TR7      pTP                  T 4      w  rpT
#   \         d   p\        R4      ThRp?ii ; i)r   Nzoauth support is not available)client_secretresource_owner_keyresource_owner_secretsignature_methodr  )oauthlib.oauth1oauth1ImportErrorNotImplementedErrorr.   ClientSIGNATURE_PLAINTEXTsign)r#   r  r  r  r  r  r  r{   client_urisigned_headers_bodys   &&&&&&      r%   r  r  _  s    K( 	N		]]%$*33  F #)++c"2D%#  K!"BCJKs   A A1 A,,A1)ra   r   )rF  
   )Ir  rC   ri   r  loggingr  r>  r   concurrent.futuresr   r   r   email.utilsr   	functoolsr   http.clientr   	itertoolsr	   sslr
   typingr   r   r   r   r   r   r   r   r   urllib.parser   r   r   r   r   r   	cloudinitr   r   r   	getLoggerr   rN   r   r   r  r&   r7   rS   r}   r   r   r   r   rW   r   r   r   r   r   r  r   rE  r^  r`  rX   rm   r  r  r  r4   r'   r%   <module>r
     sd     	   	   M M !  !  &
 
 
 ? >   0 0!XzlD&89: " .DM &<- -3> 3
(. (
.K .Kbw $!H  '+ Fm= 
m= 	m=
 m= m= m= m= m= m= m= m= '+m= m= m=  !m=" #m=$ %m=`$P-fj | El|  $	|
 ))| &*| | #'| '+| >B| | #'| |~| |~r'   