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

Dir : /usr/libexec/kcare/python/kcarectl/__pycache__/
Server: Linux server2.noticiasdecolima.com 4.18.0-553.30.1.el8_10.x86_64 #1 SMP Tue Nov 26 02:30:26 EST 2024 x86_64
IP: 107.161.180.42
Choose File :

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

3

�;j[#�@sdddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
ddlmZej
d�ZdZed�Zed	�Zed�Zd<d
d�Zd=dd�Zd>dd�Zd?dd�Zdd�Zd@dd�Zdedfdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Z ed)d*��Z!d+d,�Z"dAd-d.�Z#dBd/d0�Z$d1d2�Z%dCd4d5�Z&d6d7�Z'd8d9�Z(de)fdfd:d;�Z*dS)D�)�print_functionN)�datetime�)�	constantsz^(\d+[.]\d+[-]\d+)���F�w�c
Cs�tjj|�}|r(tjj|�r(tj|�ytj|�j}Wntk
rP|}YnXtj	||tjj
|�ddd��<}tj|j�|�|j
|�|j�tj|j��|j}WdQRXtj|tj�}	ztj|	�Wdtj|	�Xtj||�dS)N�.F)�mode�dir�prefix�delete)�os�path�dirname�exists�makedirs�stat�st_mode�	Exception�tempfile�NamedTemporaryFile�basename�fchmod�fileno�write�flush�fsync�name�open�O_RDONLY�close�rename)
�fname�content�
ensure_dirrZcreate_modeZdnamer�fZ	tmp_fnameZ	folder_fd�r)�+/usr/libexec/kcare/python/kcarectl/utils.py�atomic_write"s$

 
r+�utf-8cCs4t|�tkr|St|�tkr&|j|�S|j|�SdS)N)�type�ntype�btype�decode�encode)�data�encodingr)r)r*�nstr>s

r4�latin1cCst|�tkr|j|�}|S)N)r-�utyper1)r2r3r)r)r*�bstrHs
r7cCst|�tkr|j|�}|S)N)r-r/r0)r2r3r)r)r*�ustrOs
r8cs4i�tj����fdd��}�|_�j|_�|_|S)NcsH|tt|j���f}y�|Stk
r0YnX�||�}�|<|S)N)�tuple�sorted�items�KeyError)�args�kwargsZ	cache_key�result)�cache�fnr)r*�innerZszcached.<locals>.inner)�	functools�wrapsr@�clear�orig)rArBr))r@rAr*�cachedVs
rGcsF�dkrtj��dkrtj��dkr*tj�i������fdd�}|S)Ncs������fdd�}|S)Ncs��}xlt��D]`}y
�||�Stk
rJ}z�|��s:�WYdd}~XnXtj|�t|tjd��tj�}qWy
�||�Stk
r�}zt	|d���WYdd}~XnXdS)Nr�attempts)
�ranger�time�sleep�min�random�uniformr�RETRY_MAX_DELAY�setattr)r=r>Zldelay�_�exZfinal_ex)�backoff�check_retry�count�delayrA�stater)r*rBvs



z'retry.<locals>.decorator.<locals>.innerr))rArB)rSrTrUrVrW)rAr*�	decoratoruszretry.<locals>.decorator)r�RETRY_DELAY�RETRY_COUNT�
RETRY_BACKOFF)rTrUrVrSrXr))rSrTrUrVrWr*�retryjsr\c
Cs�tjj|�sdSg}tj|�}|dk	r2tj||�}xD|D]<}tjj||�}||krh|jtj|�j	|f�|j
dd�q8WxF||d�D]6\}}	tjj|	�s�tjj|	�r�tj
|	�q�tj|	�q�WdS)NT)�reverse)rrr�listdir�fnmatch�filter�join�appendr�st_mtime�sort�isfile�islink�remove�shutil�rmtree)
Z	directory�exclude_path�keep_n�patternr2r;�item�	full_pathrQ�entryr)r)r*�clean_directory�s

rpcCsNttjjtjd�dd�ttjjtjd�dd�tjjtj�rJtjtj�dS)N�modulesr)rk�patches)	rprrrar�PATCH_CACHEr�CACHE_KEY_DUMP_PATH�unlinkr)r)r)r*�clear_all_cache�srvc
Cs^tjj|�}tjj|�s"tj|�t|d��(}tj||�|j�tj	|j
��WdQRXdS)N�wb)rrrrrr!rh�copyfileobjrrr)�response�dstZ
parent_dirr(r)r)r*�save_to_file�s
r{cCstj|�}|r|jd�p|S)Nr)�
VERSION_RE�match�group)�versionr}r)r)r*�strip_version_timestamp�s
r�cCs0|jd�\}}}|s$|jd�\}}}tj|d�S)N�T� z%Y-%m-%d)�	partitionr�strptime)Zstr_rawZstr_date�seprQr)r)r*�parse_response_date�sr�cGs0ddlm}djdd�td|j�f|�D��S)Nr)�ipv6_support�/css|]}|jd�VqdS)r�N)�strip)�.0�itr)r)r*�	<genexpr>�sz'get_patch_server_url.<locals>.<genexpr>)rr�rar`�get_patch_server)�partsr�r)r)r*�get_patch_server_url�sr�c	Cs0tjj|�sdSt|��}|j�j�SQRXdS)N)rrrr!�readr�)�filenamer(r)r)r*�try_to_read�s
r�cCs
ttj�S)N)r�rrtr)r)r)r*�
get_cache_key�sr�c	Cs.tjj|�s|St||��
}|j�SQRXdS)N)rrrr!r�)r%r�defaultr(r)r)r*�
_read_file�sr�cCst|d|�}|S)N�r)r�)r%r�r?r)r)r*�	read_file�sr�cCst|d|�}|S)N�rb)r�)r%r�r?r)r)r*�
read_file_bin�sr�cCsBi}|j�}x0|D](}|r|jd�\}}}|r|j�||<qW|S)N�:)�
splitlinesr�r�)r2r?Z
data_lines�line�key�	delimiter�valuer)r)r*�data_as_dict�s
r��cvecCs0t�}x$|D]}|j|�}|r|j|�qW|S)a
    Extract unique CVEs from a list of patches.

    Args:
        patches: List of patch dictionaries
        cve_field: Field name to extract CVE from (default 'cve' for userspace, 'kpatch-cve' for kernel)

    Returns:
        Set of unique CVE strings
    )�set�get�add)rr�	cve_fieldZunique_cves�patchr�r)r)r*�extract_unique_cves�s

r�cCstttj���S)N)�str�intrJr)r)r)r*�
timestamp_strsr�cGst|�dS)za workaround to fix T201N)�print)�valuesr)r)r*�
print_wrappersr�cs���fdd�}|S)Ncs tj������fdd��}|S)Ncsny
�||�S�k
rh}zB�rZdd�|D�dd�|j�D�}�dj�jdj|�|���Sd}~XnXdS)NcSsg|]}t|��qSr))r�)r��ar)r)r*�
<listcomp>&szBcatch_errors.<locals>.decorator.<locals>.inner.<locals>.<listcomp>cSsg|]\}}dj||��qS)z{0}={1})�format)r��k�vr)r)r*r�&sz{0}({1}) failed: {2}z, )r;r��__name__ra)r=r>�e�arg_list)�default_return�errorsrA�loggerr)r*rBs
 z.catch_errors.<locals>.decorator.<locals>.inner)rCrD)rArB)r�r�r�)rAr*rXszcatch_errors.<locals>.decoratorr))r�r�r�rXr))r�r�r�r*�catch_errorssr�)Fr	r
)r,)r5)r5)NNN)N)N)r�)+�
__future__rr_rCrrM�rerhrrJrrr�compiler|Z
CACHE_ENTRIESr-r.r/r6r+r4r7r8rGr\rprvr{r�r�r�r�r�r�r�r�r�r�r�r�rr�r)r)r)r*�<module>sJ






$