HEX
Server: Apache
System: Linux 162-240-236-42.bluehost.com 3.10.0-1160.114.2.el7.x86_64 #1 SMP Wed Mar 20 15:54:52 UTC 2024 x86_64
User: bt667 (1004)
PHP: 8.2.29
Disabled: NONE
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	Os"t|d�r|j�}n|}t|�}|jdi�}|jitjd6tjd6�x*|j�D]\}}|j	||�qpWt
jdj||��y�tj
r�d|kr�tj|d<ntjr)ttdd�r)tj�}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_headerRtlogdebugtformattPY2_6Rt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_functionDs!:((RARB((RAs0/usr/libexec/kcare/python/kcarectl/http_utils.pytcheck_urlopen_retry_factoryCs	cCs+t|d�r|j�}n|jd�S(NRsfile:(RRt
startswith(R*((s0/usr/libexec/kcare/python/kcarectl/http_utils.pytis_local_urlPscOsq|jdt�}|jdtj�}t|�rCt|||�Stjtd|�d|�t�|||�S(NRAtretry_counttcount(	RR<RtRETRY_COUNTRER8RtretryRC(R*R.R2RARF((s0/usr/libexec/kcare/python/kcarectl/http_utils.pyturlopenVs
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_tokenRKtrequest((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_enviscCs"ttd��p!ttd��S(NRSRV(tboolR\(((s0/usr/libexec/kcare/python/kcarectl/http_utils.pyt
proxy_is_usedpstcheck_retrycCs�tjj|�}|s0tdj|���nttj|��}|j}|j	}|jpcd}|dkr�td��n|dkr�|jdkr�dnd}n|jdkr�tj
}n'|jdkr�tj}ntd��tjr�in
itjd	6}	||||	�}
i}|r@d
j|�|d<nd|d
<t|�|d<tj|d<z|
jd|�x*|j�D]\}}
|
j||
�q�W|
j�t|d��}|
j|�WdQX|
j�}|jdkrzy|j�}Wntk
rd}nXdj|j�}|dk	rO|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 hostnameRVi�iPRSsInvalid URL: unsupported schemeRs	Basic {0}RLsapplication/octet-streamsContent-TypesContent-Lengths
KC-VersiontPUTtrbNi�sFailed to upload file: HTTP {0}s - {0}(#RYtpathtgetsizet
ValueErrorRR
RtnstrthostnametportR"R[RtHTTPConnectiontHTTPSConnectionRRRtHTTP_UPLOAD_TIMEOUTR0Rt
putrequestRt	putheadert
endheaderstopentsendtgetresponsetstatustreadt	ExceptionRtlogerrorRtclose(t	file_patht
upload_urlROt	file_sizetparsedthostRhturl_pathtconn_clstconn_kwargstconnRR4R5tftresponset
error_bodyt	error_msg((s0/usr/libexec/kcare/python/kcarectl/http_utils.pytupload_filewsV		





"("RRYR;R!RR$ttypingRRtRRRRRtpy23RR	R
RRR
R8R<RCRERJR"RRR\R^tcheck_urlopen_retryRIR�(((s0/usr/libexec/kcare/python/kcarectl/http_utils.pyt<module>s$(.	1