HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib64/python3.9/site-packages/borg/helpers/__pycache__/parseformat.cpython-39.opt-1.pyc
a

HZ�h�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZddlmZmZddlmZddlmZddlmZe�Zd	d
lmZd	dlmZd	dlmZmZmZmZm Z dd
l!m"Z#ddl!m$Z%ddl&Tddl'm(Z(dd�Z)didd�Z*djdd�Z+dkdd�Z,dd�Z-dldd�Z.d d!�Z/d"d#�Z0d$d%�Z1d&d'�Z2d(d)�Z3Gd*d+�d+�Z4Gd,d-�d-e�Z5Gd.d/�d/e5�Z6d0d1�Z7ifd2d3�Z8e8Z9e8Z:e8Z;d4d5�Z<dmd7d8�Z=Gd9d:�d:e>�Z?d;d<�Z@dnd?d@�ZAdodAdB�ZBdpdCdD�ZCdEdF�ZDdGdH�ZEGdIdJ�dJ�ZFdqdKdL�ZGdMdN�ZHGdOdP�dP�ZIGdQdR�dReI�ZJGdSdT�dTeI�ZKdUdV�ZLdrdXdY�ZMdZd[�ZNd\d]�ZOGd^d_�d_ejP�ZQddd`�dadb�ZRdcdd�ZSdedf�ZTdgdh�ZUdS)s�N)�hexlify)�Counter�OrderedDict)�datetime�timezone)�partial)�	Formatter�)�
create_logger�)�Error)�get_keys_dir)�OutputTimestamp�format_time�to_localtime�safe_timestamp�safe_s)�__version__)�__version_tuple__)�*)�is_win32cCst|��d�S)N�ascii)r�decode)Zbinary�r�>/usr/lib64/python3.9/site-packages/borg/helpers/parseformat.py�
bin_to_hexsr�utf-8�surrogateescapecCs|durdS|�||�S)z8decode bytes to str, with round-tripping "invalid" bytesN)r��sZcoding�errorsrrr�safe_decode!sr!cCs|durdS|�||�S)z8encode str to bytes, with round-tripping "invalid" bytesN)�encoderrrr�safe_encode(sr#�replacecCs|�d|��d�S)z1Replace surrogates generated by fsdecode with '?'r�r"r)rr rrr�remove_surrogates/sr&cCs|�dd��d�S)z?Evaluate literal escape sequences in a string (eg `\n` -> `
`).r�backslashreplacezunicode-escaper%)rrrr�eval_escapes4sr(cCs2|D](}t|�|�t�r||�||�||<q|S�N)�
isinstance�get�bytesr)�d�keys�encodingr �keyrrr�decode_dict9sr1cCs"t|�}|dkrt�d|��|S)z#argparse type for positive integersrz"A positive integer is required: %s)�int�argparse�ArgumentTypeError)�valueZ	int_valuerrr�positive_int_validator@sr6cCs�dddddd�}|�t|����r8|dd�}|d}n8d	d
�t|��dd�d
�D�}t�d|d�d|����zt|�||}Wnty�d}Yn0|dkr�t�d|��|S)zDConvert a string representing a valid interval to a number of hours.r��i�i8")�Hr-�w�m�yN���cSsg|]\}}|�qSrr)�.0�k�vrrr�
<listcomp>Q�zinterval.<locals>.<listcomp>cSs|dS�Nrr)�trrr�<lambda>QrBzinterval.<locals>.<lambda>)r0zUnexpected interval time unit "z": expected one of rzCUnexpected interval number "%s": expected an integer greater than 0)	�endswith�tupler.�sorted�itemsr3r4r2�
ValueError)rZ
multiplier�number�suffixZrangesZhoursrrr�intervalHs"
�
�rMc
Cs�|���d�}t|�}|dkr(t�d��|d��}|tkr�d|krPdkr�nn^t|d�}|dkrtt|d�nd}|dkr�t�d��|tks�|tkr�t�d	t��|||fS|d
kr�|dkr�t	S|t
kr�|dks�|dk�rtd
d�||dd�D�\}}}}	||k�r|k�s&nt�d��|dk�r:t�d��|dk�rNt�d��|	ddk�rft�d��t
||||	fSt�d��dS)N�,rzno chunker params givenr	�r�@z)block_size must not be less than 64 Bytesz=block_size and header_size must not exceed MAX_DATA_SIZE [%d]�default��css|]}t|�VqdSr))r2)r>�prrr�	<genexpr>xrBz ChunkerParams.<locals>.<genexpr>z.required: chunk_min <= chunk_mask <= chunk_max�zLmin. chunk size exponent must not be less than 6 (2^6 = 64B min. chunk size)�zOmax. chunk size exponent must not be more than 23 (2^23 = 8MiB max. chunk size)z*window_size must be an uneven (odd) numberzinvalid chunker params)�strip�split�lenr3r4�lowerZCH_FIXEDr2Z
MAX_DATA_SIZEZCHUNKER_PARAMSZ
CH_BUZHASH)
r�params�countZalgoZ
block_size�header_sizeZ	chunk_minZ	chunk_maxZ
chunk_maskZwindow_sizerrr�
ChunkerParamsas6
 

"





r_cs�tddddddd��d}t|���d	��}|t��ksNt�d
d	�t������fdd�|D�}d
�t|��}||vr�t�dd	�|���|S)N�cr;r�i�rr-)�ctime�mtime�size�inodeZrechunkZdisabled)ZcisZims�cs�msZcr�mrr-rrNz0cache mode must be a comma-separated list of: %scsh|]}�|�qSrr)r>�entry�ZENTRIES_MAPrr�	<setcomp>�rBz!FilesCacheMode.<locals>.<setcomp>�z#cache mode short must be one of: %s)�dict�setrXrYr3r4�joinrH)rZVALID_MODES�entriesZ
short_entries�moderrkr�FilesCacheMode�s�rscsD���D]6\}}t�|�}t�d|�d|�d��fdd�|�}q|S)z�
    Apply format.format_map(mapping) while preserving unknown keys

    Does not support attribute access, indexing and ![rsa] conversions
    z(?<!\{)((\{z\})|(\{z:[^\}]*\}))cs|�d����SrC)�group�
format_map)�match��mappingrrrE�rBz partial_format.<locals>.<lambda>)rI�re�escape�sub)�formatrxr0r5rrwr�partial_format�s

�r}c@seZdZdd�Zdd�ZdS)�DatetimeWrappercCs
||_dSr))�dt)�selfrrrr�__init__�szDatetimeWrapper.__init__cCs|dkrt}|j�|�S�Nrm)ZISO_FORMAT_NO_USECSr�
__format__�r��format_specrrrr��szDatetimeWrapper.__format__N)�__name__�
__module__�__qualname__r�r�rrrrr~�sr~c@seZdZdZdS)�PlaceholderErrorz)Formatting Error: "{}".format({}): {}({})N�r�r�r��__doc__rrrrr��sr�c@seZdZdZdS)�InvalidPlaceholderz&Invalid placeholder "{}" in string: {}Nr�rrrrr��sr�c
Cs�t��|�D](\}}}}|sq|s*||vrt||��qz|�|�WSty|}z"t|||jjt|���WYd}~n
d}~00dSr))	r�parser�ru�	Exceptionr��	__class__r��str)r|�data�_r0�
conversion�errr�format_line�sr�cCs�ddlm}m}m}t�tj�}t�	�|d�
t|�d���|t
|�d��t
|�|�tt���tdtdd�dtdd�dtdd	�d
�|�}t||�S)z/Replace placeholders in text with their values.r	)�fqdn�hostname�
getosusername�.Nz%drz%d.%dz%d.%d.%drO)�pidr�zreverse-fqdnr��now�utcnow�user�uuid4ZborgversionZ	borgmajorZ	borgminorZ	borgpatch)�platformr�r�r�rr�r�utc�os�getpidrp�reversedrYr~�
astimezoner��uuidr��borg_version�borg_version_tupler�)�text�	overridesr�r�r�Zcurrent_timer�rrr�replace_placeholders�s$
�
�r�cCsFddlm}|�d�D]}||vrt�d|��q|�dd��dd�S)	Nr)�AI_HUMAN_SORT_KEYSrNzInvalid sort key: %s�	timestamp�ts�archive�name)�manifestr�rYr3r4r$)r�r��tokenrrr�
SortBySpec�s
r�FcCs|rtnt}||dd||d�S)z2Format file size into a human friendly format
    �B� )rL�sep�	precision�sign)�sizeof_fmt_iec�sizeof_fmt_decimal)r@r�r��iec�fnrrr�format_file_size�sr�c@seZdZddd�Zdd�ZdS)�FileSizeFcCst�||�}||_|Sr))r2�__new__r�)�clsr5r��objrrrr��szFileSize.__new__cCstt|�|jd��|�S)N�r�)r�r2r�r�r�rrrr��szFileSize.__format__N)F)r�r�r�r�r�rrrrr��s
r�cCst|st|�S|d}d}z4||d|d|d|dd�|}|dd�}Wntybd	}Yn0tt|�|�S)
z,Return int from file size (1234, 55G, 1.7T).r=��r	rOrSrR)�K�M�G�T�PNr)r2�KeyError�float)rrL�powerZfactorrrr�parse_file_size�s"��
r�r�rmc
Csp|r|dkrdnd}d}d}|dd�D]*}	tt||��|krBq\|t|�}|}q(|d}	|�|||||	|�S)Nr�+rmz{0:{1}.{2}f}{3}{4}{5}r=)�abs�roundr�r|)
�numrL�unitsr�r�r�r��fmtZprecZunitrrr�
sizeof_fmtsr�c	Cst|||||gd�dd�S)N)	rmZKiZMiZGiZTiZPiZEiZZiZYii�rLr�r�r�r�r��r��r�rLr�r�r�rrrr�s�r�c	Cst|||||gd�dd�S)N)	rmr?r�r�r�r��E�Z�Yr�r�r�r�rrrr�s�r�cCs d|jtt|j��t|j�fS)Nz
%-36s %s [%s])r�rrr�r�id)r�rrr�format_archive#s
�r�cCst�d|�}dd�|D�S)Nz *, *cSsg|]}|dkr|�qS)rmr)r>�itemrrrrA-rBz*parse_stringified_list.<locals>.<listcomp>)ryrY)r�lrrr�parse_stringified_list+sr�c@seZdZdZdZZZZZZ	dZ
dZdZdZ
dZdZe�d	e
ed
e
eej�Ze�deeej�Ze�de
ed
eeej�Ze�deej�Ze�deej�Zdifdd�Zifdd�Zdd�Zdd�Zdd�Zdd�Zedd��Zdd �Z d!d"�Z!d#d$�Z"dS)%�Locationz8Object representing a repository / archive location
    Nz%
        (?:(?P<user>[^@:/]+)@)?
    z�
        (?!(:|//|ssh://))                                   # not starting with ":" or // or ssh://
        (?P<path>([^:]|(:(?!:)))+)                          # any chars, but no "::"
        z�
        (?P<path>(([^/]*)/([^:]|(:(?!:)))+))                # start opt. servername, then /, then any chars, but no "::"
        zq
        (?P<path>(/([^:]|(:(?!:)))+))                       # start with /, then any chars, but no "::"
        z�
        (?:
            ::                                              # "::" as separator
            (?P<archive>[^/]+)                              # archive name must not contain "/"
        )?$z�
        (?P<host>(
            (?!\[)[^:/]+(?<!\])     # hostname or v4 addr, not containing : or / (does not match v6 addr: no brackets!)
            |
            \[[0-9a-fA-F:.]+\])     # ipv6 address in brackets
        )
    zR
        (?P<proto>ssh)://                                       # ssh://
        z�                 # user@  (optional), host name or address
        (?::(?P<port>\d+))?                                     # :port (optional)
        zS
        (?P<proto>file)://                                      # file://
        z
        (
            z�             # user@  (optional), host name or address
            :                                                   # : (required!)
        )?                                                      # user@host: part is optional
        a                                # the repo part is fetched from BORG_REPO
        (?:::$)                                             # just "::" is ok (when a pos. arg is required, no archive)
        |                                                   # or
        a^
        (?:file://)?                                        # optional file protocol
        (?P<path>
            (?:[a-zA-Z]:)?                                  # Drive letter followed by a colon (optional)
            (?:[^:]+)                                       # Anything which does not contain a :, at least one character
        )
        rmcCs|�||�std|j��dS)NzInvalid location format: "%s")r�rJ�	processed)r�r�r�rrrr��szLocation.__init__cCs�||_t||�|_}|�|�}|r(dS|j�|�}|s<dStj�d�}|durTdSt||�}|�|�}|�	d�|_
|j
s~|n||j|_|j
s�|n|�d|j
��|_|S)NTFZ	BORG_REPOr��::)�rawr�r��_parse�env_rervr��environr+rtr�)r�r�r�Zvalidr;Zrepo_rawZreporrrr��s"


zLocation.parsecCsRdd�}trB|j�|�}|r>d|_|�d�|_|�d�|_dSdS|j�|�}|r�|�d�|_|�d	�|_|�d
�|_	|�d�r�t
|�d��p�d|_||�d��|_|�d�|_dS|j�|�}|r�|�d�|_||�d��|_|�d�|_dS|j
�|�}|�rN|�d	�|_|�d
�|_	||�d��|_|�d�|_|j	�rDd�pFd|_dSdS)
NcSs&|�d�}tj�|�}|r"d|S|S)N�/./z/.)�
startswithr��path�normpath)rT�relativerrr�normpath_special�s
z)Location._parse.<locals>.normpath_special�filer�r�TF�protor��host�portZssh)r�win_file_rervr�rtr�r��ssh_rer��_hostr2r��file_re�scp_re)r�r�r�r;rrrr��sBzLocation._parsecCs>d|jd|jd|jd|jd|jd|jg}d�|�S)Nzproto=%rzuser=%rzhost=%rzport=%rzpath=%rz
archive=%rz, )r�r�r�r�r�r�rp)r�rIrrr�__str__�s�zLocation.__str__cCs`t�dd|j��d�}|jdkr8t�dd|j�d|}t|�dkrP|dd�}tj�t	�|�S)Nz[^\w]r�r��__�d)
ryr{r�rXr�r�rZr�rpr
)r�r�rrr�to_key_filename�s
zLocation.to_key_filenamecCsd|S)NzLocation(%s)r�r�rrr�__repr__�szLocation.__repr__cCs |jdur|j�d��d�SdS)N�[�])r��lstrip�rstripr�rrrr��s
z
Location.hostcCs�|jdkr|jS|jr.|j�d�r.d|j}n$|jrL|j�d�sLd|j}n|j}d�|jrh|j�d�nd|j|jr�d|j��nd|�SdS)	Nr��~�/r�zssh://{}{}{}{}�@rm�:)r�r�r�r|r�r�r�)r�r�rrr�canonical_path�s
�zLocation.canonical_pathcCs"t|jt|�d��t|�d�d�S)N)r�r�)r�)r�r�r~r�)r�r�rrr�with_timestamp�s�zLocation.with_timestampcCs8t|j�}d|_|j�d�d|_|j�d�d|_|S)Nr�r)r�r�r�rYr�)r��locrrr�omit_archive�s

zLocation.omit_archive)#r�r�r�r�r�r�r�r�r�r�Zoptional_user_reZscp_path_reZfile_path_reZabs_path_reZoptional_archive_reZhost_rery�compile�VERBOSEr�r�r�r�r�r�r�r�r�r�r��propertyr�rrrrrrrr�0s|		�������������������+
r�cs��fdd�}|S)Nc
s�zt|�}Wn4ty@}zt�t|��d�WYd}~n
d}~00�dur`|js`t�d|��n�dur||jr|t�d|���dur�|j�kr��dkr�t�d|��nt�d|��|S)NTz"%s": No archive specifiedFz!"%s": No archive can be specifiedr�z"%s": Repository must be localz"%s": Repository must be remote)r�rJr3r4r�r�r�)r�r�err�r�r�rr�	validators&z%location_validator.<locals>.validatorr)r�r�rrr
r�location_validatorsrcCsdd�}|S)NcSs.t|�}d|vsd|vs|s*t�d|��|S)Nr�r�zInvalid archive name: "%s")r�r3r4)r�rrrrsz(archivename_validator.<locals>.validatorr)rrrr�archivename_validatorsr
c@s@eZdZdddddejejd�Zdd�Zd	d
�Zedd��Z	d
S)�
BaseFormatter�
r��	�
�)ZLFZSPACEZTABZCR�NUL�NEWLINE�NLcCst�dSr))�NotImplementedError�r�r�rrr�
get_item_data/szBaseFormatter.get_item_datacCs|j�|�|��Sr))r|rurrrrr�format_item2szBaseFormatter.format_itemcCsdS)Nz�- NEWLINE: OS dependent line separator
- NL: alias of NEWLINE
- NUL: NUL character for creating print0 / xargs -0 like output, see barchive and bpath keys below
- SPACE
- TAB
- CR
- LFrrrrr�	keys_help5szBaseFormatter.keys_helpN)
r�r�r�r��linesep�
FIXED_KEYSrr�staticmethodrrrrrr#s�rc@s�eZdZddddddddd	d
ddd
d�
ZdZedd��Zedd��Zddd�dd�Zdd�Z	dd�Z
edd��Zdd�Z
d d!�Zd"d#�Zd$d%�Zd&d'�Zd(S))�ArchiveFormatterzUarchive name interpreted as text (might be missing non-text characters, see barchive)zalias of "archive"z;verbatim archive name, can contain any character except NULzXarchive comment interpreted as text (might be missing non-text characters, see bcomment)z>verbatim archive comment, can contain any character except NULz'time (start) of creation of the archivezalias of "start"z%time (end) of creation of the archivez1command line which was used to create the archivezinternal ID of the archivez2hostname of host on which this archive was createdz)username of user who created this archivez(TAM authentication state of this archive)
r�r��barchive�comment�bcomment�start�time�end�command_liner�r��username�tam))r�r�rr r!r�r')r"r#r$r%)r�r&c	Cs`ddlm}|ddtdddtjd��}|dddd�}g}|�|j���|�|�|����|S)Nr)�ArchiveInfo�archivenames i��Ztzinform)	r�r(rrr��extend�	call_keysr.r)r�r(Zfake_archive_info�	formatterr.rrr�available_keysWszArchiveFormatter.available_keyscCs�g}|��}|jD]}|�|�q|jD]P}|D]<}|�|�d|}||jvrb|d|j|7}|�|�q0|�d�q(d�|�S�Nz- z: rmr�r.r�remove�
KEY_GROUPS�KEY_DESCRIPTIONS�appendrp�r��helpr.r0rtr�rrrras



zArchiveFormatter.keys_helpF)�jsonr�cCs�||_||_||_d|_d|_d|_||_||_i}|�|j	�t
||�|_dd�t��
|�D�|_t|jddd�t|jddd�t|jddd�t|jddd�|j|j|jd	�|_t|j�|j@|_|jr�i|_|j|_n||_dS)
NcSsh|]}|d�qS�rr�r>�frrrrlrBz,ArchiveFormatter.__init__.<locals>.<setcomp>r�T)�rsr&r F)r�r&r r!r$r%r')�
repositoryr�r0r�r��_archiver7r��updaterr}r|rr��format_keysr�get_meta�
get_ts_end�get_cmdline�get_tamr,ro�used_call_keys�	item_data�format_item_jsonr)r�r|r<r�r0r7r��static_keysrrrr�ss2�	
zArchiveFormatter.__init__cCstj|�|�tdd�dS)NT)r��	sort_keysr�r7�dumpsr�BorgJsonEncoderrrrrrF�sz!ArchiveFormatter.format_item_jsonc
Cs||j|_|j|_i}|�|j�|�t|j�t|j�|jt|j�|�|j�|�|j�d��|jD]}|j	|�||<qb|S)N)r�r�rr�r#r")
r�r�r>rEr&rrr�rDr,)r�Zarchive_inforEr0rrrr�s

�
zArchiveFormatter.get_item_datacCsH|jdus|jj|jkrBddlm}||j|j|j|j|jd�|_|jS)z!lazy load / update loaded archiveNr	��Archiver�)	r=r�r�rMr<r0r�r�r�)r�rMrrrr��szArchiveFormatter.archivecCs |jj�|d�}|rt|�S|Sr�)r��metadatar+r&)r�r0r;r5rrrr@�szArchiveFormatter.get_metacCs:tt|jj�dg��}|jr$t|�Sd�ttj	|��SdS)N�cmdliner�)
�mapr&r�rNr+r7�listrp�shlex�quote)r�rOrrrrB�szArchiveFormatter.get_cmdlinecCs|�|jj�Sr))rr�Zts_endr�rrrrA�szArchiveFormatter.get_ts_endcCs|jjrdSdS)NZverifiedZnone)r�Ztam_verifiedr�rrrrC�szArchiveFormatter.get_tamcCst|�Sr))r)r�r�rrrr�szArchiveFormatter.format_timeN)r�r�r�r3r2�classmethodr.rr�rFrrr�r@rBrArCrrrrrr@s:�
	

rc@s�eZdZej�dh��ddh�Zdddddd	d
ddd
dd�Zddde	e
e��ddfZdZe
dd��Ze
dd��Ze
dd��Zdd�dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2S)3�
ItemFormatter�xxh64Z	shake_128Z	shake_256z9verbatim POSIX path, can contain any character except NULzJpath interpreted as text (might be missing non-text characters, see bpath)z/link target for links (identical to linktarget)zKprepends {source} with " -> " for soft links and " link to " for hard linkszcompressed sizezdeduplicated sizezdeduplicated compressed sizeznumber of chunks in this filez$number of unique chunks in this filezEXXH64 checksum of this file (note: this is NOT a cryptographic hash!)zPeither "healthy" (file ok) or "broken" (if file has all-zero replacement chunks))�bpathr��source�extra�csize�dsize�dcsize�
num_chunks�
unique_chunksrV�health)�typerr�uid�gidr�rtr�rWrX�
linktarget�flags)rerZr[r\r]r^)rdrc�atime�isomtime�isoctime�isoatime)�	archiveidr)rY)r_)r[r\r^c	CsfGdd�d�}ddlm}|dddddddd�}||d�}g}|�|j���|�|�|����|S)Nc@seZdZdZZdS)z1ItemFormatter.available_keys.<locals>.FakeArchivermN)r�r�r��fprr�rrrr�FakeArchive�srkr	)�Itemrrm)rrr�r�rtrdrarb)r�rlr+r,r.r)r�rkrlZ	fake_itemr-r.rrrr.�s
zItemFormatter.available_keyscCs�g}|��}|jD]}|�|�q|jD]P}|D]<}|�|�d|}||jvrb|d|j|7}|�|�q0|�d�q(d�|�Sr/r0r5rrrr�s



zItemFormatter.keys_helpcs,dd�t��|�D�}t�fdd�|D��S)NcSsh|]}|d�qSr8rr9rrrrlrBz3ItemFormatter.format_needs_cache.<locals>.<setcomp>c3s|]}|�jvVqdSr))�KEYS_REQUIRING_CACHE)r>r0�r�rrrUrBz3ItemFormatter.format_needs_cache.<locals>.<genexpr>)rr��any)r�r|r?rrnr�format_needs_cache�sz ItemFormatter.format_needs_cacheF)�
json_linescCs&ddlm}||_||_||_|j|jd�}|�|j�|jrNi|_	|j
|_n||_	t||�|_
dd�t��|�D�|_|j|jt|jdd��t|jdd��|jt|jd	d��t|jd
�t|jd�t|jd�t|jd
�t|jd�t|jd�d
�|_|jD]}t|j|�|j|<q�t|j�|j@|_dS)Nr	)�StreamingXXH64)r)ricSsh|]}|d�qSr8rr9rrrrlrBz)ItemFormatter.__init__.<locals>.<setcomp>cSs|jSr))re��chunkrrrrErBz(ItemFormatter.__init__.<locals>.<lambda>cSs|jSr))rZrsrrrrErBcSsdSrCrrsrrrrErBrdrcre)rerZr[r\r]r^rfrgrhrdrcre)Zalgorithms.checksumsrrrVr�rqr�rjr>rrErFrr}r|rr�r?�calculate_size�calculate_csizer�sum_unique_chunks_metadata�calculate_num_chunks�format_iso_timerr,�hash_algorithms�	hash_itemrorD)r�r�r|rqrrrG�
hash_functionrrrr�s<�






�
zItemFormatter.__init__cCstj|�|�td�dS)NrnrrIrrrrrF&szItemFormatter.format_item_jsoncCs:i}|�|j�t�|j�}|d}|�dd�}d}|rjt|�}|dkrRd|}nd|dd�}d|}||d	<||d
<|jp�|j|d<|j	p�|j
|d<|j|d
<|j
|d<t|j�|d<|jr�d|v|d<n&|j|d<||d<d|vr�dnd|d<||d<||d<|�dd�|d<|j
D]}|j||�||<�q|S)NrrXrmr�z -> %s�hrz link to %sr`rrr�rtrarbr�Zchunks_healthyZhealthyrWrY�brokenr_rcZbsdflagsrd)r>rE�stat�filemoderrr+r&r�rartrbr�rqrDr,)r�r�rErrZ	item_typerXrYr0rrrr)s<




zItemFormatter.get_item_datacsB|jjj�|�dg�}tdd�|D���t���fdd�|D��S)au
        sum unique chunks metadata, a unique chunk is a chunk which is referenced globally as often as it is in the
        item

        item: The item to sum its unique chunks' metadata
        metadata_func: A function that takes a parameter of type ChunkIndexEntry and returns a number, used to return
                       the metadata needed from the chunk
        �chunkscss|]}|jVqdSr)�r��r>r`rrrrUWrBz;ItemFormatter.sum_unique_chunks_metadata.<locals>.<genexpr>c3s,|]$}�|jj�|jkr�|�VqdSr))r�Zrefcountr��Zchunk_indexZchunks_counter�
metadata_funcrrrUXrB)r��cacher�r+r�sum)r�r�r�r�rr�rrwLs	
z(ItemFormatter.sum_unique_chunks_metadatacCst|�dg��S)Nr�)rZr+rrrrrxZsz"ItemFormatter.calculate_num_chunkscCs|jdd�S)NF��
compressed�Zget_sizerrrrru]szItemFormatter.calculate_sizecCs|jdd�S)NTr�r�rrrrrvaszItemFormatter.calculate_csizecCsdd|vrdS|dkr|��}n||jvr2t�|�}|jj�dd�|jD��D]}|�|�qL|�	�S)Nr�rmrVcSsg|]
}|j�qSrr�r�rrrrAlrBz+ItemFormatter.hash_item.<locals>.<listcomp>)
rVrz�hashlib�newr�ZpipelineZ
fetch_manyr�r>Z	hexdigest)r�r|r��hashr�rrrr{es


zItemFormatter.hash_itemcCstt|�|�p|j��Sr))rrr+rd�r�r0r�rrrrpszItemFormatter.format_timecCs|�||���Sr))rZ	isoformatr�rrrrysszItemFormatter.format_iso_timeN)r�r�r�r�Zalgorithms_guaranteed�union�
differencerzr3rGrHr2rmrTr.rrpr�rFrrwrxrurvr{rryrrrrrU�sJ�
�	


##rUcCsXt�|�rdSt�|�rdSt�|�r*dSt�|�r8dSt�|�rFdSt�|�rTdSdS)N�Ar-�br`rr:�?)r�S_ISREG�S_ISDIR�S_ISBLK�S_ISCHR�S_ISLNK�S_ISFIFO)rrrrr�file_statusws





r�TccsR|D]H}|dur|�|�}|dur,|�|�}|r6|s6q|rF|�d�rFq|VqdS)a�
    clean lines (usually read from a config file):

    1. strip whitespace (left and right), 2. remove empty lines, 3. remove comments.

    note: only "pure comment lines" are supported, no support for "trailing comments".

    :param lines: input line iterator (e.g. list or open text file) that gives unclean input lines
    :param lstrip: lstrip call arguments or False, if lstripping is not desired
    :param rstrip: rstrip call arguments or False, if rstripping is not desired
    :param remove_comments: remove comment lines (lines starting with "#")
    :param remove_empty: remove empty lines
    :return: yields processed lines
    F�#N)r�r�r�)�linesr�r�Zremove_emptyZremove_comments�linerrr�clean_lines�s

r�cCsrddlm}|dk}t|�}|r(t|�}d}g}|D]&}|||�7}||krPq\|�|�q4|rh|��d�|�S)a
    Return a slice of *max_width* cells from *string*.

    Negative *max_width* means from the end of string.

    *max_width* is in units of character cells (or "columns").
    Latin characters are usually one cell wide, many CJK characters are two cells wide.
    r	��swidthrrm)r�r�r�r�r4�reverserp)�stringZ	max_widthr�r�Zcurrent_swidth�result�	characterrrr�swidth_slice�s	r�cCsvddlm}|d�}||�}|dkr4dd||S|||krfd�t||d|�t||d��S|d||S)z�
    shorten a long string by adding ellipsis between it and return it, example:
    this_is_a_very_long_string -------> this_is..._string
    r	r�z...�r�z{}...{})r�r�r|r�)�msg�spacer�Zellipsis_widthZ	msg_widthrrr�ellipsis_truncate�s�r�cseZdZ�fdd�Z�ZS)rKcs�ddlm}ddlm}ddlm}ddlm}m}t	||�sHt	||�r^t
|j�|j�
�d�St	||�rp|��St	||�r�|j|��d�St	||�r�d|��iStt|d	d��r�|��St��|�S)
Nr	)�
Repository)�RemoteRepositoryrL)�
LocalCache�
AdHocCache)r��location)r��statsr��to_json)r<r�Zremoter�r�rMr�r�r�r*rr�Z	_locationr�infor�r��callable�getattrr��superrQ)r��or�r�rMr�r��r�rrrQ�s(�

�
�zBorgJsonEncoder.default)r�r�r�rQ�
__classcell__rrr�rrK�srK)r�rYcCsv|j}|pi}|�t��|j�d|jid��t|jjt	j
d��|dd<|j�d�rf|�
�|dd<|rr||d	<|S)
Nrr)r<�
encryptionr*r<Z
last_modifiedzkey filer�Zkeyfiler�)r0r>rKrQr<ZARG_NAMErZlast_timestampr$rr��NAMEr�Zfind_key)r�r�rYr0r�rrr�basic_json_data�s��r�cCstj|ddtd�S)zDump using BorgJSONEncoder.TrS)rH�indentr�)r7rJrK�r�rrr�	json_dump�sr�cCstt|��dSr))�printr�r�rrr�
json_print�sr�cs0dd�����fdd�����fdd���|�S)NcSs8|�d�s,z|��}|WSty*Yn0dt|�S)N��)r�r�UnicodeDecodeErrorr)r5rrr�decode_bytess
z'prepare_dump_dict.<locals>.decode_bytescs`g}|D]R}t|t�r �|�}n0t|t�s4t|t�r>�|�}nt|t�rP�|�}|�|�q|Sr))r*rnrGrQr,r4)rD�resr5�rr��decode_tuplerrr�s



z'prepare_dump_dict.<locals>.decode_tuplecstt�}|��D]`\}}t|t�r*�|�}n*t|ttf�rB�|�}nt|t�rT�|�}t|t�rf|��}|||<q|Sr))rrIr*rnrGrQr,r)r-r�r0r5r�rrrs





z!prepare_dump_dict.<locals>.decoder)r-rr�r�prepare_dump_dicts
r�)rr)rr)r$)rr)r	FF)r�NNrmr	F)r�rmr	F)r�rmr	F)NN)NNTT)Vr3r�r7r�Zos.pathryrRZsocketrr�Zbinasciir�collectionsrrrr�	functoolsrr�r�loggerr
r rZfsr
r#rrrrrrmrr�rr�Z	constantsZ
platformflagsrrr!r#r&r(r1r6rMr_rsr}r~r�r�r�r�Z
PrefixSpecZGlobSpecZCommentSpecr�r�r2r�r�r�r�r�r�r�r�rr
rrrUr�r�r�r�ZJSONEncoderrKr�r�r�r�rrrr�<module>s�



%





X
	7