PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /usr/libexec/kcare/python/kcarectl/__pycache__/
Server: Linux red.truehostdns.com 4.18.0-553.150.1.el8_10.x86_64 #1 SMP Fri Jul 31 15:23:31 EDT 2026 x86_64
IP: 51.161.15.103
Choose File :

Url:
Dir : //usr/libexec/kcare/python/kcarectl/__pycache__/http_utils.cpython-36.pyc

3

0�jE�@s�ddlZddlZddlZddlZddlmZddlmZmZmZm	Z	m
Z
ddlmZm
Z
mZmZmZmZdd�Zdd	d
�Zdd�Zd
d�Zddd�Zdd�Zdd�Ze�Ze
jed�ddd��ZdS)�N)�SSLError�)�config�	constants�errors�	log_utils�utils)�	HTTPError�Request�URLError�httplib�std_urlopen�urlparsec	Os�t|d�r|j�}n|}t|�}|jdi�}|jtjtjd��x |j�D]\}}|j	||�qJWt
jdj||��ydd|kr�t
j|d<t
jr�ttdd�r�tj�}d|_tj|_||d<t|f|�|�St|f|�|�Stk
�r&}z0|jd	k�rtj|j|j|j|j|j���WYdd}~Xn~tk
�r�}z`|j �r|t|j d
d��r||j d
j!t!j"k�r|tj|d	t#|�dd��dj||�|_$||_�WYdd}~XnXdS)
N�get_full_url�headers)z
KC-VersionzKC-Patch-Versionz#Requesting url: `{0}`. Headers: {1}�timeout�HAS_SNIF�contexti�r�errnozRequest for `{0}` failed: {1})%�hasattrrr
�pop�updater�VERSION�KC_PATCH_VERSION�items�
add_headerr�logdebug�formatr�HTTP_TIMEOUT�CHECK_SSL_CERTS�getattr�ssl�create_default_context�check_hostname�	CERT_NONE�verify_moder
r	�coder�NotFound�url�msg�hdrs�fpr�argsr�ENOENT�str�reason)	r(r,�kwargsZrequest_urlr�header�value�ctx�ex�r5�0/usr/libexec/kcare/python/kcarectl/http_utils.py�urlopen_bases>


.r7Tcs�fdd�}|S)Ncsbt|t�r�o|jdkSt|ttjttjf�r2dSt	|d�r^t
|j�dkr^|jdtj
kr^dSdS)Ni�Tr,�r)�
isinstancer	r&rr�
HTTPExceptionr�socketrr�lenr,rZ
ECONNRESET)�e�state)�retry_on_500r5r6�check_functionCs
(z3check_urlopen_retry_factory.<locals>.check_functionr5)r?r@r5)r?r6�check_urlopen_retry_factoryBs	rAcCst|d�r|j�}|jd�S)Nrzfile:)rr�
startswith)r(r5r5r6�is_local_urlOs
rCcOsV|jdd�}|jdtj�}t|�r2t|f|�|�Stjt|d�|d�t�|f|�|�S)Nr?T�retry_count)r?)�count)rr�RETRY_COUNTrCr7r�retryrA)r(r,r0r?rDr5r5r6�urlopenUs
rHcCsHt||d�}tjr*|r*|jddj|��tjrD|rD|jtj|�|S)N)�method�
Authorizationz	Basic {0})r
r�UPDATE_FROM_LOCALrrr�AUTH_TOKEN_HEADER)r(�auth_string�
auth_tokenrI�requestr5r5r6�http_request]srPcCs<|dkrtjd�ptjd�S|dkr8tjd�p6tjd�SdS)N�httpZ
http_proxyZ
HTTP_PROXY�httpsZhttps_proxyZHTTPS_PROXY)�os�getenv)�schemer5r5r6�get_proxy_from_envhsrVcCsttd��pttd��S)NrQrR)�boolrVr5r5r5r6�
proxy_is_usedosrX)Zcheck_retrycCs�tjj|�}|stdj|���ttj|��}|j}|j	}|jp@d}|dkrRtd��|dkrl|j
dkrhdnd}|j
dkr~tj}n|j
dkr�tj
}ntd	��|||tjd
�}	i}
|r�dj|�|
d<d
|
d<t|�|
d<tj|
d<z�|	jd|�x |
j�D]\}}|	j||�q�W|	j�t|d��}
|	j|
�WdQRX|	j�}|jdk�r�y|j�}Wntk
�rnd}YnXdj|j�}|dk	�r�|dj|�7}tj|�t||j|dd��Wd|	j �XdS)a�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
    z"Refusing to upload empty file: {0}�/NzInvalid URL: missing hostnamerRi��PrQzInvalid URL: unsupported scheme)rz	Basic {0}rJzapplication/octet-streamzContent-TypezContent-Lengthz
KC-Version�PUT�rbi�zFailed to upload file: HTTP {0}z - {0})!rS�path�getsize�
ValueErrorrrr�nstr�hostname�portrUr�HTTPConnection�HTTPSConnectionr�HTTP_UPLOAD_TIMEOUTr.rr�
putrequestr�	putheader�
endheaders�open�send�getresponse�status�read�	Exceptionr�logerrorr	�close)Z	file_path�
upload_urlrMZ	file_size�parsed�hostrbZurl_pathZconn_cls�connrr1r2�f�responseZ
error_body�	error_msgr5r5r6�upload_filevsT






rx)T)NN)N)rrSr;r!r�rrrrr�py23r	r
rrr
rr7rArCrHrPrVrX�check_urlopen_retryrGrxr5r5r5r6�<module>s  0