Sindbad~EG File Manager

Current Path : /proc/2191876/root/usr/libexec/kcare/python/kcarectl/__pycache__/
Upload File :
Current File : //proc/2191876/root/usr/libexec/kcare/python/kcarectl/__pycache__/utils.cpython-36.pyc

3

��"hF�@s8ddlZddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddlm
Z
ejd�ZdZ
ed�Zed	�Zed�Zd4dd
�Zd5dd�Zd6dd�Zd7dd�Zdd�Zd8dd�Zde
dfdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zed(d)��Zd*d+�Z d9d,d-�Z!d:d.d/�Z"d0d1�Z#d2d3�Z$dS);�N)�datetime�)�	constants)�configz^(\d+[.]\d+[-]\d+)���F�wcCs�|d}tjj|�}|r0tjj|�r0tj|�t||��&}|j|�|j�tj|j	��WdQRXtj|tj
�}ztj|�Wdtj|�Xtj||�dS)Nz.tmp)
�os�path�dirname�exists�makedirs�open�write�flush�fsync�fileno�O_RDONLY�close�rename)�fname�content�
ensure_dir�modeZ	tmp_fnameZdname�fZ	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�encodingrrr�nstr8s

r'�latin1cCst|�tkr|j|�}|S)N)r �utyper$)r%r&rrr�bstrBs
r*cCst|�tkr|j|�}|S)N)r r"r#)r%r&rrr�ustrIs
r+cs4i�tj����fdd��}�|_�j|_�|_|S)NcsH|tt|j���f}y�|Stk
r0YnX�||�}�|<|S)N)�tuple�sorted�items�KeyError)�args�kwargsZ	cache_key�result)�cache�fnrr�innerTszcached.<locals>.inner)�	functools�wrapsr3�clearZorig)r4r5r)r3r4r�cachedPs
r9csF�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)
�range�	Exception�time�sleep�min�random�uniformr�RETRY_MAX_DELAY�setattr)r0r1Zldelay�_�exZfinal_ex)�backoff�check_retry�count�delayr4�staterrr5ps



z'retry.<locals>.decorator.<locals>.innerr)r4r5)rFrGrHrIrJ)r4r�	decoratoroszretry.<locals>.decorator)r�RETRY_DELAY�RETRY_COUNT�
RETRY_BACKOFF)rGrHrIrFrKr)rFrGrHrIrJr�retrydsrOc
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)r
rr
�listdir�fnmatch�filter�join�append�stat�st_mtime�sort�isfile�islink�remove�shutil�rmtree)
Z	directory�exclude_path�keep_n�patternr%r.�item�	full_pathrD�entryrrr�clean_directory�s

rdcCsNttjjtjd�dd�ttjjtjd�dd�tjjtj�rJtjtj�dS)N�modulesr)r_�patches)	rdr
rrTr�PATCH_CACHEr
�CACHE_KEY_DUMP_PATH�unlinkrrrr�clear_all_cache�srjc
Cs^tjj|�}tjj|�s"tj|�t|d��(}tj||�|j�tj	|j
��WdQRXdS)N�wb)r
rrr
rrr\�copyfileobjrrr)�response�dstZ
parent_dirrrrr�save_to_file�s
rocCstj|�}|r|jd�p|S)Nr)�
VERSION_RE�match�group)�versionrqrrr�strip_version_timestamp�s
rtcCs0|jd�\}}}|s$|jd�\}}}tj|d�S)N�T� z%Y-%m-%d)�	partitionr�strptime)Zstr_rawZstr_date�seprDrrr�parse_response_date�srzcGs"djdd�tdtjf|�D��S)N�/css|]}|jd�VqdS)r{N)�strip)�.0�itrrr�	<genexpr>�sz'get_patch_server_url.<locals>.<genexpr>)rTrSr�PATCH_SERVER)�partsrrr�get_patch_server_url�sr�c	Cs0tjj|�sdSt|��}|j�j�SQRXdS)N)r
rr
r�readr|)�filenamerrrr�try_to_read�s
r�cCs
ttj�S)N)r�rrhrrrr�
get_cache_key�sr�c	Cs.tjj|�s|St||��
}|j�SQRXdS)N)r
rr
rr�)rr�defaultrrrr�
_read_file�sr�cCst|d|�}|S)N�r)r�)rr�r2rrr�	read_file�sr�cCst|d|�}|S)N�rb)r�)rr�r2rrr�
read_file_bin�sr�cCsBi}|j�}x0|D](}|r|jd�\}}}|r|j�||<qW|S)N�:)�
splitlinesrwr|)r%r2Z
data_lines�line�key�	delimiter�valuerrr�data_as_dict�s
r�cCstttj���S)N)�str�intr=rrrr�
timestamp_str�sr�)Fr	)r)r()r()NNN)N)N)%r
rRr6�rer\r@r=rrrr�compilerpZ
CACHE_ENTRIESr r!r"r)rr'r*r+r9rOrdrjrortrzr�r�r�r�r�r�r�r�rrrr�<module>sB	






$
	



Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists