403Webshell
Server IP : 23.254.227.96  /  Your IP : 216.73.216.46
Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k
System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64
User : viralblo ( 1001)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.6/site-packages/cloudinit/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.6/site-packages/cloudinit/__pycache__/url_helper.cpython-36.pyc
3

��b3T�@sJddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZddlZddlmZdd	lmZdd
lmZeje�ZdZdd
�Zdd�Zdd�ZGdd�de�Z Gdd�de �Z!Gdd�de�Z"Gdd�de#�Z$dd�Z%d*e"d�d d!�Z&d+d"d#�Z'Gd$d%�d%e�Z(d,d&d'�Z)d(d)�Z*dS)-�N)�	parsedate)�ENOENT)�partial)�	NOT_FOUND)�count)�quote�urlparse�
urlunparse)�
exceptions)�log)�version�REDACTEDcCs>tt|dd��}|dr6|dr6|d|d<d|d<t|�S)NZhttp)�scheme���)�listrr	)�urlZ
parsed_url�r� /usr/lib/python3.6/url_helper.py�	_cleanurl!s
rcGs(dd�}|}x|D]}|||�}qW|S)NcSsPtt|��}|d}|r,|jd�r,|d7}|tt|�dd�7}||d<t|�S)Nr�/z/:)Zsafe)rr�endswithr�strr	)r�add_onZ
url_parsed�pathrrr�combine_single,sz#combine_url.<locals>.combine_singler)�baseZadd_onsrrrrrr�combine_url+s
	
rcKs�|j�}|jd�rd|}|j�jd�r�|jd�r>tjd|�|td�d�}y"t|d��}|j�}WdQRXWnHt	k
r�}z,|j
}|j
tkr�t}t
||d|d�|�WYdd}~XnXt||d	�St|f|�SdS)
a0Wrapper 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.
    rz	file://%szfile://�dataz'Unable to post data to file resource %sN�rb)�cause�code�headersr)�contents)�lstrip�
startswith�lower�get�LOG�warning�len�open�read�IOError�errnorr�UrlError�FileResponse�readurl)r�kwargsZ	file_path�fpr$�er"rrr�read_file_or_url;s"


$r6c@s&eZdZd	dd�Zdd�Zdd�ZdS)
�StringResponse��cCs||_i|_||_d|_dS)N)r"r#r$r)�selfr$r"rrr�__init__[szStringResponse.__init__cOs|jdkrdSdS)Nr8FT)r")r9�argsr3rrr�okas
zStringResponse.okcCs|jjd�S)Nzutf-8)r$�decode)r9rrr�__str__fszStringResponse.__str__N)r8)�__name__�
__module__�__qualname__r:r<r>rrrrr7Zs
r7c@seZdZddd�ZdS)r1r8cCstj|||d�||_dS)N)r")r7r:r)r9rr$r"rrrr:kszFileResponse.__init__N)r8)r?r@rAr:rrrrr1jsr1c@sVeZdZdd�Zedd��Zedd��Zddd	�Zed
d��Zedd
��Z	dd�Z
dS)�UrlResponsecCs
||_dS)N)�	_response)r9�responserrrr:qszUrlResponse.__init__cCs|jjS)N)rC�content)r9rrrr$tszUrlResponse.contentscCs|jjS)N)rCr)r9rrrrxszUrlResponse.urlFcCs2d}|rd}d|jko |knr*dSdSdS)Ni,i�r8TF)r")r9Zredirects_ok�upperrrrr<|szUrlResponse.okcCs|jjS)N)rCr#)r9rrrr#�szUrlResponse.headerscCs|jjS)N)rC�status_code)r9rrrr"�szUrlResponse.codecCs|jjS)N)rC�text)r9rrrr>�szUrlResponse.__str__N)F)r?r@rAr:�propertyr$rr<r#r"r>rrrrrBps
	rBc@seZdZddd�ZdS)r0NcCs<tj|t|��||_||_||_|jdkr2i|_||_dS)N)r.r:rr!r"r#r)r9r!r"r#rrrrr:�s
zUrlError.__init__)NNN)r?r@rAr:rrrrr0�sr0cCs�i}t|�j}|dkr~|r~d|kr8|dr8|d|d<nd|d<d|krfd|krf|d|dg|d<nd|kr~t|d�|d<|S)NZhttpsZca_certsZverifyTZ	cert_fileZkey_fileZcert)rrr)r�ssl_detailsZssl_argsrrrr�
_get_ssl_args�s
rKrTF)�returncs
t|�}d|i}|jt||��|
|d<|s8|r4dnd}||d<|dk	rZtt|�d�|d<|dkrfg}d	}|r�tt|�d	d	�}d
dtj�i}�r�|j��|�|s��fdd
�}|}|r�||d<|dkr�d}g}�x(|
r�t�nt	d|�D�]}||�|d<i}x�|j
�D]t\}�|dk�r �q
|dk�rt|�rt�fdd�|D�}|�r|tj��||<x$|D]}t
|||<�q\Wn�||<�q
Wy�|�r�tjd||
�r�dn|||�|dk�r�tj�}|�}|jf|�}WdQRX|	�r�|j�tjd||jt|j�|d	�t|�Stjk
�r�}z�t|tj��rdt|d��rdt|jd��rd|jt||jj|jj |d��n"|jt||d��t|tj!��r�P|�r�||j�|d��r�P|
�r�|dk�s�|d	|k�r�|dk�r�|�r�tjd|�t"j#|�WYdd}~Xq�Xq�W|d�dS)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
    :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 which accepts the params
        msg and exception and returns a boolean 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.
    r�allow_redirectsZPOSTZGET�methodNr�timeoutrz
User-Agentz
Cloud-Init/%scs�S)Nr)r)r#rr�_cb�szreadurl.<locals>._cbrr#csg|]}�j|�r|�qSr)r()�.0�k)�vrr�
<listcomp>szreadurl.<locals>.<listcomp>z'[%s/%s] open '%s' with %s configuration�infinitez(Read from %s (%s, %sb) after %s attemptsrDrG)r"r#r)rz1Please wait %s seconds while we wait to try again���rVrV)$r�updaterK�max�float�intrZversion_stringr�range�items�copy�deepcopyr
r)�debug�requestsZSessionZrequestZraise_for_statusrGr+rErBr
ZRequestException�
isinstanceZ	HTTPError�hasattrrD�appendr0r#ZSSLError�time�sleep)rrrOZretriesZsec_betweenr#�
headers_cb�headers_redactrJ�check_statusrM�exception_cbZsessionrUZlog_req_resp�request_methodZreq_argsZmanual_triesZdef_headersrPZexcps�iZfiltered_req_argsrRZmatched_headers�keyZsess�rr5r)r#rSrr2�s�0




 r2c
Cs(tj�}
ddd�}|dkr|}dd�}d}
d}�x�|dk	rF|||
�}nt|
d�d}�x�|D�]�}tj�}|
dkr�|||
�r�P|dk	r�|r�|||
|kr�t|
||�}d	}d}y�|dk	r�||�}ni}t||||d
|	d�}|j�sd|j}tt|�|j|j|d
�}n8|j��s:d|j}tt|�|j|j|d
�}n
||jfSWn^tk
�rv}zd|}|}WYdd}~Xn0t	k
�r�}zd|}|}WYdd}~XnXttj�|
�}|�r�d|nd}d||||f}||�|r^|||d�q^W|||
��rP|
d}
t
jd|�tj|�q2WdS)aI
    urls:      a list of urls to try
    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
    timeout:   the timeout provided to urlopen
    status_cb: call method with string message when a url is not available
    headers_cb: call method with single argument of url to get headers
                for request.
    headers_redact: a list of header names to redact from the log
    exception_cb: call method with 2 arguments 'msg' (per status_cb) and
                  'exception', the exception that occurred.
    sleep_time_cb: call method with 2 arguments (response, loop_n) that
                   generates the next sleep time.
    request_method: indicate the type of HTTP request, GET, PUT, or POST
    returns: tuple of (url, response contents), on failure, (False, None)

    the idea of this routine is to wait for the EC2 metadata service to
    come up.  On both Eucalyptus and EC2 we have seen the case where
    the instance hit the MD before the MD service was up.  EC2 seems
    to have permanently fixed this, though.

    In openstack, the metadata service might be painfully slow, and
    unable to avoid hitting a timeout of even up to 10 seconds or more
    (LP: #894279) for a simple GET.

    Offset those needs with the need to not hang forever (and block boot)
    on a system where cloud-init is configured to look for EC2 Metadata
    service but is not going to find one.  It is possible that the instance
    data host (169.254.169.254) may be firewalled off Entirely for a system,
    meaning that the connection will block forever unless a timeout is set.

    A value of None for max_wait will retry indefinitely.
    NcSstj|�dS)N)r)r_)�msg�excrrr�
log_status_cb�sz#wait_for_url.<locals>.log_status_cbcSs$|dkrdS|dkp"tj�||kS)NFr)rd)�max_wait�
start_timerrr�timeup�szwait_for_url.<locals>.timeupr�rrF)r#rgrOrhrjzempty response [%s])r"r#rzbad status code [%s]zrequest error [%s]zunexpected error [%s]z%ssZ	unlimitedzCalling '%s' failed [%s/%s]: %s)rn�	exceptionz1Please wait %s seconds while we wait to try again)N)FN)
rdrZr2r$r"r0�
ValueErrorr#r<�	Exceptionr)r_re)ZurlsrqrOZ	status_cbrfrgZ
sleep_timeriZ
sleep_time_cbrjrrrprsZloop_nrDrZnow�reasonZurl_excr#r5Z
time_takenZmax_wait_strZ
status_msgrrr�wait_for_urlZs�/







ryc@s^eZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�ZdS)�OauthUrlHelperN�/run/oauth_skew.jsoncCst||_|pd|_||_||_||_d|_d|_|j|j|jf}t|�sNd|_nt|�s^t	d��|j
�}|pli|_dS)NrTrtFzBall or none of token_key, token_secret, or consumer_key can be set)�consumer_key�consumer_secret�	token_key�token_secret�skew_data_file�	_do_oauth�skew_change_limit�any�allrv�read_skew_file�	skew_data)r9r|r~rr}r�Zrequired�oldrrrr:�s
zOauthUrlHelper.__init__c	Cs8|jr4tjj|j�r4t|jdd��}tj|�SQRXdS)Nrm)�mode)r��osr�isfiler,�json�load)r9r4rrrr�
szOauthUrlHelper.read_skew_filec
CsT|js
dS|j�}|dkri}|||<t|jdd��}|jtj|��WdQRXdS)N�w)r�)r�r�r,�writer��dumps)r9�host�valueZcurr4rrr�update_skew_fileszOauthUrlHelper.update_skew_filec	Cs�t|t�o|jdkp|jdks"dSd|jkr>tjd|j�dS|jd}ytjt|��}Wn.t	k
r�}ztjd||�dSd}~XnXt
|tj��}t|j�j
}|jj|d�}t||�|jkr�|j||�tjd||�||j|<dS)Ni�i��datez$Missing header 'date' in %s responsez#Failed to convert datetime '%s': %srz$Setting oauth clockskew for %s to %d)rar0r"r#r)r*rdZmktimerrwrZrr�netlocr�r(�absr�r�)	r9rnrur�Zremote_timer5Zskewr�Zold_skewrrrris(



zOauthUrlHelper.exception_cbcCsZ|js
iSd}t|�j}|jr>||jkr>ttj��|j|}t||j|j|j	|j
|d�S)N)rr|r~rr}�	timestamp)r�rr�r�rZrd�
oauth_headersr|r~rr})r9rr�r�rrrrf7s
zOauthUrlHelper.headers_cbcCs6t|j|jd��|d<t|j|jd��|d<|||�S)Nrfri)r�_headers_cbr(�
_exception_cb)r9Zwrapped_funcr;r3rrr�_wrappedIs
zOauthUrlHelper._wrappedcOs|jt||�S)N)r�ry)r9r;r3rrrryRszOauthUrlHelper.wait_for_urlcOs|jt||�S)N)r�r2)r9r;r3rrrr2UszOauthUrlHelper.readurlcCs*d}z|r|||�}Wd|j||�X|S)N)ri)r9Zextra_exception_cbrnru�retrrrr�XszOauthUrlHelper._exception_cbcCs$i}|r||�}|j|j|��|S)N)rWrf)r9Zextra_headers_cbrr#rrrr�as
zOauthUrlHelper._headers_cb)NNNNr{)
r?r@rAr:r�r�rirfr�ryr2r�r�rrrrrz�s
		rzcCszyddlj}Wn,tk
r:}ztd�|�WYdd}~XnX|rJt|�}nd}|j|||||j|d�}|j|�\}	}
}|
S)Nrzoauth support is not available)Z
client_secretZresource_owner_keyZresource_owner_secretZsignature_methodr�)Zoauthlib.oauth1�oauth1�ImportError�NotImplementedErrorrZClientZSIGNATURE_PLAINTEXTZsign)rr|r~rr}r�r�r5ZclientZ_uriZsigned_headersZ_bodyrrrr�is 
r�cCs8t|t�sdS|jtkrdS|jr4t|jtj�r4dSdS)z�readurl exception_cb that will retry on NOT_FOUND and Timeout.

    Returns False to raise the exception from readurl, True to retry.
    FT)rar0r"rr!r`ZTimeout)rnrorrr�retry_on_url_exc�s

r�)NNrrNNNNTTNNFTN)	NNNNNrNNN)N)+r]r�r�rdZemail.utilsrr/r�	functoolsrZhttp.clientr�	itertoolsrZurllib.parserrr	r`r
Z	cloudinitrZloggingrZ	getLoggerr?r)r
rrr6�objectr7r1rBr.r0rKr2ryrzr�r�rrrr�<module>sj

!
|


Youez - 2016 - github.com/yon3zu
LinuXploit