MOON
Server: Apache
System: Linux server2.shieldcogroup.com 3.10.0-1160.119.1.el7.tuxcare.els12.x86_64 #1 SMP Fri Nov 8 05:49:38 UTC 2024 x86_64
User: jacom (1029)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/libexec/kcare/python/kcarectl/http_utils.pyc
�
%��ic@s(ddlZddlZddlZddlZddlmZer_ddlmZmZnddl	m
Z
mZmZm
Z
mZddlmZmZmZmZmZmZd�Zed�Zd	�Zd
�Zddd�Zd�Zd
�Ze�Zej de�dd��Z!dS(i����N(tSSLError(tOptionaltUnioni(tconfigt	constantsterrorst	log_utilstutils(t	HTTPErrortRequesttURLErrorthttplibtstd_urlopenturlparsec	Ost|d�r|j�}n|}t|�}|jdi�}|jitjd6tjd6�x*|j�D]\}}|j	||�qpWt
jdj||��y�d|kr�t
j|d<nt
jrttdd�rtj�}t|_tj|_||d<t|||�St|||�SWn�tk
r�}|jd	kr~tj|j|j|j|j|j ��n�n�t!k
r}|j"r�t|j"d
d�r�|j"d
j#t#j$kr�tj|d	t%|�dd��ndj||�|_&||_�nXdS(
Ntget_full_urltheaderss
KC-VersionsKC-Patch-Versions#Requesting url: `{0}`. Headers: {1}ttimeouttHAS_SNItcontexti�iterrnosRequest for `{0}` failed: {1}('thasattrRR	tpoptupdateRtVERSIONtKC_PATCH_VERSIONtitemst
add_headerRtlogdebugtformatRtHTTP_TIMEOUTtCHECK_SSL_CERTStgetattrtssltNonetcreate_default_contexttFalsetcheck_hostnamet	CERT_NONEtverify_modeRRtcodeRtNotFoundturltmsgthdrstfpR
targsRtENOENTtstrtreason(	R)R-tkwargstrequest_urlRtheadertvaluetctxtex((s0/usr/libexec/kcare/python/kcarectl/http_utils.pyturlopen_bases@
	
-8$	cs�fd�}|S(Ncs�t|t�r"�o!|jdkSt|ttjttjf�rGt	St
|d�r�t|j�dkr�|jdt
jkr�t	SdS(Ni�R-ii(t
isinstanceRR'R
Rt
HTTPExceptionRtsocketRtTrueRtlenR-Rt
ECONNRESET(tetstate(tretry_on_500(s0/usr/libexec/kcare/python/kcarectl/http_utils.pytcheck_functionCs!:((R@RA((R@s0/usr/libexec/kcare/python/kcarectl/http_utils.pytcheck_urlopen_retry_factoryBs	cCs+t|d�r|j�}n|jd�S(NRsfile:(RRt
startswith(R)((s0/usr/libexec/kcare/python/kcarectl/http_utils.pytis_local_urlOscOsq|jdt�}|jdtj�}t|�rCt|||�Stjtd|�d|�t�|||�S(NR@tretry_counttcount(	RR;RtRETRY_COUNTRDR7RtretryRB(R)R-R1R@RE((s0/usr/libexec/kcare/python/kcarectl/http_utils.pyturlopenUs
cCsht|d|�}tjr>|r>|jddj|��ntjrd|rd|jtj|�n|S(Ntmethodt
Authorizations	Basic {0}(R	RtUPDATE_FROM_LOCALRRRtAUTH_TOKEN_HEADER(R)tauth_stringt
auth_tokenRJtrequest((s0/usr/libexec/kcare/python/kcarectl/http_utils.pythttp_request]scCsT|dkr(tjd�p'tjd�S|dkrPtjd�pOtjd�SdS(Nthttpt
http_proxyt
HTTP_PROXYthttpsthttps_proxytHTTPS_PROXY(tostgetenv(tscheme((s0/usr/libexec/kcare/python/kcarectl/http_utils.pytget_proxy_from_envhscCs"ttd��p!ttd��S(NRRRU(tboolR[(((s0/usr/libexec/kcare/python/kcarectl/http_utils.pyt
proxy_is_usedostcheck_retrycCsttjj|�}|s0tdj|���nttj|��}|j}|j	}|jpcd}|dkr�td��n|dkr�|jdkr�dnd}n|jdkr�tj
}n'|jdkr�tj}ntd��|||d	tj�}	i}
|r'd
j|�|
d<nd|
d
<t|�|
d<tj|
d<z|	jd|�x*|
j�D]\}}|	j||�qnW|	j�t|d��}
|	j|
�WdQX|	j�}|jdkray|j�}Wntk
rd}nXdj|j�}|dk	r6|dj|�7}ntj|�t ||j|dd��nWd|	j!�XdS(s�Upload a file to the given URL using HTTP PUT with chunked streaming.
    Note: The standard library urllib doesn't support PUT with data
    We need to use httplib directly for this

    This function uses streaming upload to support large files up to 1GB
    without loading the entire file into memory.

    :param file_path: Path to the file to upload
    :param upload_url: Full URL to upload the file to. Query params are ignored.
    :param auth_string: Optional authentication string for Basic Auth
    :return: None if upload succeeded
    :raises HTTPError: If upload fails with HTTP status >= 400
    :raises ValueError: If URL is invalid
    s"Refusing to upload empty file: {0}t/sInvalid URL: missing hostnameRUi�iPRRsInvalid URL: unsupported schemeRs	Basic {0}RKsapplication/octet-streamsContent-TypesContent-Lengths
KC-VersiontPUTtrbNi�sFailed to upload file: HTTP {0}s - {0}("RXtpathtgetsizet
ValueErrorRR
RtnstrthostnametportR!RZRtHTTPConnectiontHTTPSConnectionRtHTTP_UPLOAD_TIMEOUTR/RRt
putrequestRt	putheadert
endheaderstopentsendtgetresponsetstatustreadt	ExceptionRtlogerrorRtclose(t	file_patht
upload_urlRNt	file_sizetparsedthostRgturl_pathtconn_clstconnRR3R4tftresponset
error_bodyt	error_msg((s0/usr/libexec/kcare/python/kcarectl/http_utils.pytupload_filevsT		





"("RRXR:R RR#ttypingRRtRRRRRtpy23RR	R
RRR
R7R;RBRDRIR!RQR[R]tcheck_urlopen_retryRHR�(((s0/usr/libexec/kcare/python/kcarectl/http_utils.pyt<module>s$(.	0