Current File : //usr/lib64/python3.6/site-packages/borg/__pycache__/remote.cpython-36.pyc
3

y��b���@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZddlmZddlmZddlTddlmZmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lm Z ddlm!Z!ddlm"Z"ddlm#Z#ddl$m%Z%m&Z&ddlm'Z'ddl(m)Z)ddl*m+Z+m,Z,ddl-m.Z.e%e/�Z$dZ0e+e�Z1dP\Z2Z3Z4Z5dZ6dZ7dd�Z8Gdd �d e�Z9Gd!d"�d"e9�Z:Gd#d$�d$e�Z;Gd%d&�d&e�Z<Gd'd(�d(e�Z=Gd)d*�d*e�Z>dQdRfffdSdTdUdVdWffdXdYfdZd;�Z?d<d=�Z@Gd>d?�d?�ZAGd@dA�dA�ZBdBdC�ZCGdDdE�dE�ZDdFdG�ZEGdHdI�dI�ZFGdJdK�dKeF�ZGdLddddLdM�dNdO�ZHdS)[�N)�Popen�PIPE�)�__version__)�LZ4)�*)�Error�IntegrityError)�
bin_to_hex)�get_base_dir)�get_limited_unpacker)�hostname_is_unique)�replace_placeholders)�sysinfo)�format_file_size)�safe_unlink)�prepare_subprocess_env)�
create_logger�
setup_logging)�msgpack)�
Repository)�
parse_version�format_version)�xxh64��i�m�a�r�dg�������?cCsNt|�}}x<|rHtj||�}||8}|s,P||d�}tj|d�qW|S)z;os.write wrapper so we do not lose data for partial writes.Ng��&�.>)�len�os�write�time�sleep)�fd�dataZamountZ	remaining�count�r(�/usr/lib64/python3.6/remote.py�os_write1sr*c@seZdZdZdS)�ConnectionClosedz Connection closed by remote hostN)�__name__�
__module__�__qualname__�__doc__r(r(r(r)r+Dsr+c@seZdZdZdS)�ConnectionClosedWithHintz$Connection closed by remote host. {}N)r,r-r.r/r(r(r(r)r0Hsr0c@seZdZdZdS)�PathNotAllowedzRepository path not allowed: {}N)r,r-r.r/r(r(r(r)r1Lsr1c@seZdZdZdS)�InvalidRPCMethodzRPC method {} is not validN)r,r-r.r/r(r(r(r)r2Psr2c@seZdZdZdS)�!UnexpectedRPCDataFormatFromClientz4Borg {}: Got unexpected RPC data format from client.N)r,r-r.r/r(r(r(r)r3Tsr3cs eZdZdZ�fdd�Z�ZS)�!UnexpectedRPCDataFormatFromServerz.Got unexpected RPC data format from server:
{}csfy|j�dd�}Wn@tk
rT|dd�}dd�|D�}tjdj|�d�}YnXt�j|�dS)N�cSsg|]}d|�qS)z%02Xr()�.0Zbyter(r(r)�
<listcomp>`sz>UnexpectedRPCDataFormatFromServer.__init__.<locals>.<listcomp>� ���0)�decode�UnicodeDecodeError�textwrapZfill�join�super�__init__)�selfr&)�	__class__r(r)rA[sz*UnexpectedRPCDataFormatFromServer.__init__)r,r-r.r/rA�
__classcell__r(r()rCr)r4Xsr4�repair�
save_space�limit�marker�idr&�keydata�client_data�path�create�	lock_wait�lock�	exclusive�append_only�next_unreserved�start_nonce)�check�commit�rollback�destroy�__len__�list�put�get�delete�save_key�load_key�
break_lock�	negotiate�open�get_free_nonce�commit_nonce_reservationcs�fdd��D�S)Ncsi|]}�||j��qSr()r<)r6�k)�dr(r)�
<dictcomp>�szdecode_keys.<locals>.<dictcomp>r()rer()rer)�decode_keys�srgc@sReZdZd&Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	d'd"d#�Z
d$d%�Zd S)(�RepositoryServerrXrTrUr\rWr[rY�scanr`rarZrVr]r^r_rbrc�inject_exceptioncCs,d|_||_||_||_||_td�|_dS)Nz1.0.8)�
repository�restrict_to_paths�restrict_to_repositoriesrQ�
storage_quotar�client_version)rBrlrmrQrnr(r(r)rA�szRepositoryServer.__init__csny�fdd�tt|�D�Stk
rh|dkrPt��dkrPt|dd�}n��fdd�t|�D�SXdS)z5Translate from positional protocol to named protocol.csi|]\}}�||�qSr(r()r6�pos�name)�argvr(r)rf�sz8RepositoryServer.positional_to_named.<locals>.<dictcomp>ra�Ncsi|]\}}�||�qSr(r()r6rprq)rrr(r)rf�s)�	enumerate�	compatMap�
IndexErrorr )rB�methodrr�mappingr()rrr)�positional_to_named�sz$RepositoryServer.positional_to_namedcs$ttj|�j����fdd��D�S)zWRemove unknown named parameters from call, because client did (implicitly) say it's ok.csi|]}|�kr�||�qSr(r()r6rq)�known�kwargsr(r)rf�sz0RepositoryServer.filter_args.<locals>.<dictcomp>)�set�inspect�	signature�
parameters)rB�fr{r()rzr{r)�filter_args�szRepositoryServer.filter_argsc"Cstjj�}tjj�}tjj�}tj|tj�}tj|tj|tjB�tj|tj�}tj|tj|tj@�tj|tj�}tj|tj|tj@�t	d�}�xvt
j
|gggd�\}}}|�r�tj|t�}	|	s�|j
dk	r�|j
j�nt|djt�j��dS|j|	��x�|D�]�}
t|
t��r@d}|
t}|
tj�}
t|
t�}n^t|
t��r�t|
�dk�r�d}|
\}}}
}|
j�}
|j|
|�}n|j
dk	�r�|j
j�tt��yb|
|jk�r�t |
��yt!||
�}Wn"t"k
�r�t!|j
|
�}YnX|j#||�}|f|�}W�n�t$k
�r�}�z�|�rt%j&|j'|�}t%j(tj)��}d}t|t*��rX|j+�g}|j%}t|t,j-t,j.t/f��rpnt0j1dj2|��y2t3j4t|d|j'j5d	|j6d
|d|d|d
t7�i�}WnNt8k
�rt3j4t|d|j'j5d	dd�|j6D�d
|d|d|d
t7�i�}YnXt||�n�t|t,j-t,j.t/f��r&ndt|t*��rP|j%�r@t0j9nt0j:}|j+�}nt0j9}d|j'j5}dt%j;�t7�f}t0j<|�t0j=||�d}t|t3j4d||j'j5|f��WYdd}~Xn:X|�r�t|t3j4t|t>|i��nt|t3j4d|d|f���qW|r�|j
j�dSq�WdS)NZserver�
z<Borg {}: Got connection close before repository was opened.
TrsF�
sexception_classsexception_argssexception_fullsexception_shortsexception_tracessysinfocSs$g|]}t|tttf�r|nd�qS)N)�
isinstance�str�bytes�int)r6�xr(r(r)r7sz*RepositoryServer.serve.<locals>.<listcomp>z%s Exception in RPC callz%s
%sz3Remote Exception (see remote log for the traceback)r)?�sys�stdin�fileno�stdout�fcntl�F_GETFL�F_SETFLr!�
O_NONBLOCKr�select�read�BUFSIZErk�closer*�formatr�encode�feedr��dict�MSGID�MSGr<rg�ARGS�tupler ryr3�rpc_methodsr2�getattr�AttributeErrorr��
BaseException�	traceback�format_exception_onlyrC�format_exception�exc_infor�get_messager�DoesNotExist�
AlreadyExistsr1�logging�debugr?r�packbr,�argsr�	TypeError�ERROR�DEBUG�
format_exc�error�log�RESULT)rB�stdin_fd�	stdout_fd�	stderr_fdZfl�unpacker�r�wZesr&�unpacked�
dictFormat�msgidrwr��_r��res�eZex_shortZex_fullZex_trace�msgZtb_log_level�tb�excr(r(r)�serve�s�








.
zRepositoryServer.servecCsZ|tkrtSt|t�rL|d|_tjtjd�j�}tdd|d�t	j
d�nt|_dtiS)Nsclient_version�T)Zis_serve�json�levelz2Initialized logging system for JSON-based protocol�server_version)�RPC_PROTOCOL_VERSIONr�r�ror�ZgetLevelName�	getLoggerr�r�loggerr��BORG_VERSION)rBrKr�r(r(r)r`6s

zRepositoryServer.negotiatecCs�t|t�rtj|�}|jd�r8tjjt�|dd��}nr|jd�r\tjjt�|dd��}nN|jd�r|tjj|dd��}n.|jd�r�tjj|�}n|jd�r�|dd�}tjj	|�S)	Nz/~/r:z~/rz/~r�~z/./)
r�r�r!�fsdecode�
startswithrLr?r�
expanduser�realpath)rBrLr(r(r)�
_resolve_pathGs






zRepositoryServer._resolve_pathFNTc

Cs�tjd|�|j|�}tjd|�tjj|d�}|jrpx8|jD]&}	tjjtjj|	�d�}
|j|
�r>Pq>Wt	|��|j
r�x6|j
D]$}tjjtjj|�d�}||kr~Pq~Wt	|��|r�|jp�|}t||||||j
||d�|_|jj�|jjS)NzResolving repository path %rzResolved repository path to %rr�)rNrOrQrnrP�make_parent_dirs)r�r�r�r!rLr?rlr�r�r1rmrQrrnrk�	__enter__rI)
rBrLrMrNrOrPrQr�Z
path_with_sepZrestrict_to_pathZrestrict_to_path_with_sepZrestrict_to_repositoryZrestrict_to_repository_with_sepr(r(r)raWs0




zRepositoryServer.opencCs�|j�}d}d}|dkr$tj|��n�|dkr8tj|��np|dkrLtj|��n\|dkr^t|��nJ|dkrptd��n8|d	kr�tj||��n"|d
kr�t|��n|dkr�dddS)
Nztest stringztest string2r�r��CheckNeededr	r1Zfoo�ObjectNotFoundr2Zdivider)	r<rr�r�r�r	r1r�r2)rBZkind�s1�s2r(r(r)rjzs&


z!RepositoryServer.inject_exception)rXrTrUr\rWr[rYrir`rarZrVr]r^r_rbrcrj)FNTNFF)r,r-r.r�rAryr�r�r`r�rarjr(r(r(r)rh�s6q
"rhc@seZdZdd�Zdd�ZdS)�SleepingBandwidthLimitercCs0|r&t|t�|_tj�|_|j|_nd|_dS)N)r��RATELIMIT_PERIOD�	ratelimitr#�	monotonic�ratelimit_last�ratelimit_quota)rBrGr(r(r)rA�s


z!SleepingBandwidthLimiter.__init__cCs�|jr�tj�}|jt|krN|j|j7_|jd|jkrHd|j|_||_|jdkr�|jt|}tj|�|j|j7_tj�|_t|�|jkr�|d|j�}tj	||�}|jr�|j|8_|S)Nrr)
r�r#r�r�r�r�r$r r!r")rBr%�to_sendZnowZtosleep�writtenr(r(r)r"�s$


zSleepingBandwidthLimiter.writeN)r,r-r.rAr"r(r(r(r)r��sr�cs��fdd�}|S)a~Check version requirements and use self.call to do the remote method call.

    <since> specifies the version in which borg introduced this method,
    calling this method when connected to an older version will fail without transmiting
    anything to the server.

    Further kwargs can be used to encode version specific restrictions.
    If a previous hardcoded behaviour is parameterized in a version, this allows calls that
    use the previously hardcoded behaviour to pass through and generates an error if another
    behaviour is requested by the client.

    e.g. when 'append_only' was introduced in 1.0.7 the previous behaviour was what now is append_only=False.
    Thus @api(..., append_only={'since': parse_version('1.0.7'), 'previously': False}) allows calls
    with append_only=False for all version but rejects calls using append_only=True on versions older than 1.0.7.
    cstj�����fdd��}|S)Nc
s tj��}|j|f|�|�}i}i}xh|jj�D]Z\}}|dkrBq0||jkrt|dkrd|j|||<q�|j|||<q0|j|jk	r0|j||<q0W|j�kr�|j	�j
t����xb�j�D]V\}}	|	d|jkr�q�d|	kr�|||	dkr�q�|j	dj�j
|||�t|	d���q�W|j
�j
|f|�S)NrB�wait�since�
previouslyz
{0} {1}={2!s})r}r~Zbindr�itemsZ	arguments�default�emptyr��RPCServerOutdatedr,rr��call)
rBr�r{ZsigZ
bound_argsZnamedZextrarqZparamZrestriction)r��kwargs_decoratorr�r(r)�do_rpc�s.


z&api.<locals>.decorator.<locals>.do_rpc)�	functools�wraps)r�r�)r�r�)r�r)�	decorator�szapi.<locals>.decoratorr()r�r�r�r()r�r�r)�api�s!r�c@s0eZdZgZGdd�de�ZGdd�de�ZdZdMdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
edd��Zdd�Zdd�Zdd�Zdd�ZdNdd�Zeed�ed�dd �ed!�dd �d"�dOd#d$��Zeed�d%�dPd&d'��Zeed�d%�dQd(d)��Zeed�d%�d*d+��Zeed�d%�d,d-��Zeed�d%�d.d/��Zeed�d%�dRd0d1��Zeed2�d%�dSd3d4��Zd5d6�ZdTd7d8�Z eed�d%�dUd9d:��Z!eed�d%�dVd;d<��Z"eed�d%�d=d>��Z#eed�d%�d?d@��Z$eed�d%�dAdB��Z%eed�d%�dCdD��Z&eed�d%�dEdF��Z'dGdH�Z(dWdIdJ�Z)dKdL�Z*dS)X�RemoteRepositoryc@sLeZdZdd�Zdd�Zedd��Zedd��Zed	d
��Zedd��Z	d
S)zRemoteRepository.RPCErrorcCs
||_dS)N)r�)rBr�r(r(r)rA�sz"RemoteRepository.RPCError.__init__cCs(d|jkrdj|jd�j�S|jSdS)Nsexception_short�
)r�r?r<�exception_class)rBr(r(r)r��s
z%RemoteRepository.RPCError.get_messagecCs|jjdd�S)Nsexception_traceT)r�r[)rBr(r(r)r��sz#RemoteRepository.RPCError.tracebackcCs|jdj�S)Nsexception_class)r�r<)rBr(r(r)r��sz)RemoteRepository.RPCError.exception_classcCs.d|jkrdj|jd�j�S|j�dSdS)Nsexception_fullr�z4
Remote Exception (see remote log for the traceback))r�r?r<r�)rBr(r(r)�exception_full�s
z(RemoteRepository.RPCError.exception_fullcCs d|jkr|jdj�SdSdS)Nssysinfor�)r�r<)rBr(r(r)rs
z!RemoteRepository.RPCError.sysinfoN)
r,r-r.rAr��propertyr�r�r�rr(r(r(r)�RPCError�sr�c@s(eZdZdZedd��Zedd��ZdS)z"RemoteRepository.RPCServerOutdatedz2Borg server is too old for {}. Required version {}cCs
|jdS)Nr)r�)rBr(r(r)rw
sz)RemoteRepository.RPCServerOutdated.methodcCs
|jdS)Nr)r�)rBr(r(r)�required_versionsz3RemoteRepository.RPCServerOutdated.required_versionN)r,r-r.r/r�rwr�r(r(r(r)r�sr�FNTc	s�|�_�_g�_d�_d�_d�_d�_d�_i�_t	��_
i�_i�_d�_
t|rf|jrf|jdnd��_td��_td��_d�_|�_|jdk}	t|	d�}
�j||	�}|	sˆj|�|}tjd|�t|dttt|
d	��_�jjj ��_!�jj"j ��_#�jj$j ��_%t&j&�j!t&j't&j&�j!t&j(�t)j*B�t&j&�j#t&j't&j&�j#t&j(�t)j*B�t&j&�j%t&j't&j&�j%t&j(�t)j*B��j#�j%g�_+�j!�j#�j%g�_,�yy�j-d
ddt.ii�}Wn t/k
�r�t0d
�d�YnX|t1k�r�d�_2n4t3|t4��rd|k�rd�_2|d�_nt5d|���������fdd�}
�j2�rF|
�nhy
|
�Wn\�j6k
�r�}z<|j7dk�rt�d}t8j$j9|�td��_dt:d<|
�WYdd}~XnXWn t5k
�r��j;��YnXdS)Nr�iZclientz1.0.8Z
__testsuite__)�systemzSSH command line: %s)�bufsizer�r��stderr�envr`rKsclient_versionzIs borg working on the server?Fsserver_versionTz8Server insisted on using unsupported protocol version %sc	s"�j�jj������d��_dS)N)rLrMrNrOrPrQr�)ra�locationrLrIr()rQrMrPrOrNr�rBr(r)�do_openIsz*RemoteRepository.__init__.<locals>.do_openr�aoPlease note:
If you see a TypeError complaining about the number of positional arguments
given to open(), you can ignore it if it comes from a borg version < 1.0.7.
This TypeError is a cosmetic side effect of the compatibility code borg
clients >= 1.0.7 have to support older borg servers.
This problem will go away as soon as the server has been upgraded to 1.0.7+.
z1.0.6rLrMrNrOra)rLrMrNrO)<r�Z	_location�preload_idsr��rx_bytes�tx_bytesr��stderr_received�chunkid_to_msgidsr|�ignore_responses�	responses�async_responses�
shutdown_timer�Zremote_ratelimitr�rr�rr��p�_args�hostr�borg_cmd�ssh_cmdr�r�rrr�r�r�r�r�r�r�r�r�r�r!r��r_fds�x_fdsr�r�r+r0r�r�r�r��	Exceptionr�r�r�r"rur�)rBr�rMrPrNrOrQr�r��testingr�r�versionr��errr�r()rQrMrPrOrNr�rBr)rAsx


$$$


zRemoteRepository.__init__cCs>t|j�r tjdt|j�f�|jr:|j�ds:td��dS)Nz2still %d cached responses left in RemoteRepositoryFz&cleanup happened in Repository.__del__)r rr�r�rr��AssertionError)rBr(r(r)�__del__is

zRemoteRepository.__del__cCsd|jj|jj�fS)Nz<%s %s>)rCr,r�Zcanonical_path)rBr(r(r)�__repr__pszRemoteRepository.__repr__cCs|S)Nr()rBr(r(r)r�sszRemoteRepository.__enter__cCsPz"|dk	r tj�d|_|j�Wdtjdt|j�t|j�|j	�|j
�XdS)N�zDRemoteRepository: %s bytes sent, %s bytes received, %d messages sent)r#r�rrVr�r�rr�r�r�r�)rB�exc_type�exc_val�exc_tbr(r(r)�__exit__vszRemoteRepository.__exit__cCs
t|j�S)N)r
rI)rBr(r(r)�id_str�szRemoteRepository.id_strcCsXg}|dk	r�|jd|j�tj�}|jtj�r<|jd�n^|jtj�rT|jd�nF|jtj�rbn8|jtj�rz|jd�n |jtj	�r�|jd�nt
d��x4|jD]*}d|kr�d	|}d
|kr�|jd|�q�Wd|kr�|jr�|jd
|j�g}t
��s|jd�|�r&|tjdddg||jS|j�p:tjjdd�}t|�}||dg|SdS)z return a borg serve command lineNz--umask=%03oz--debugz--infoz--errorz
--criticalz log level missing, fix this code�.zborg.debug.rkz--debug-topic=%srnz--storage-quota=%szBORG_HOSTNAME_IS_UNIQUE=noz-mz
borg.archiverr�ZBORG_REMOTE_PATH�borg)�append�umaskr�r�ZisEnabledForr��INFOZWARNINGr��CRITICAL�
ValueErrorZdebug_topicsrnr
r��
executable�extra_test_args�remote_pathr!�environr[r)rBr�rZoptsZroot_loggerZtopicZenv_varsr!r(r(r)r�s<

zRemoteRepository.borg_cmdcCsj|jjptjjdd�}tj|�}|jr8|dt|j�g7}|j	rV|j
d|j	|jf�n|j
d|j�|S)zEreturn a ssh command line that can be prefixed to a borg command lineZBORG_RSHZsshz-pz%s@%sz%s)r�rshr!r"r[�shlex�splitZportr��userrr)rBr�r#r�r(r(r)r�s
zRemoteRepository.ssh_cmdcs�fdd�t|D�S)Ncsg|]}�|�qSr(r()r6rq)r{r(r)r7�sz8RemoteRepository.named_to_positional.<locals>.<listcomp>)ru)rBrwr{r()r{r)�named_to_positional�sz$RemoteRepository.named_to_positionalcKs"x|j||gf|�D]}|SWdS)N)�	call_many)rB�cmdr��kw�respr(r(r)r��szRemoteRepository.callc#s�|r|dkrdS�fdd�}�fdd�}t|�}g}�x>|sD|�rv�jrttj��jkrttjdt|�t�j��dSxj|r�yJ�jj	|d�}	|j	d�d|	kr�||	�n|	t
V|r�|r�dSWqvtk
r�PYqvXqvW|dk�rNxby�jj�\}
}	Wn,tk
�r*|�r"�j
�r"PndSYq�Xd|	k�r@||	�q�|	t
Vq�W�j�sr|�sd�j�r|t|�tk�r|�jg}ng}tj�j|�jd	�\}}
}|�r�td
���x�|D�]�}|�jk�r�tj|t�}|�s�t���jt|�7_�jj|�xȈjD]�}	t|	t��r|	t }
nPt|	t!��rbt|	�dk�rb|	\}}
}}|�rTt |
d|i}	nt |
t
|i}	nt"|��|
�j
k�r��j
j#|
�d|	k�r�|	�j|
<n|	t
dk	�r�|	�j|
<n
|	�j|
<�qWn�|�j$k�r�tj|d�}|�s�t���jt|�7_�j%�r�j%|}d
�_%|j&dd�}|�r@|dj'd��r@|j	��_%x|D]}t(|j)d���qFW�q�W|
r:�x��j�r|�s��j�rt|�tk�r|�rr|�r�|dk�s�t*d��|dd�j+k�rr|j,||j	d�d��n�|j	d�}|dk�r|d�j+k�r|j,||d��n\�j-d	7_-|j,�j-��j.�rTt/j0t �j-t1|t2|i��_nt/j0d	�j-|�j3||�f��_�j�rl�j�rl�jj	d�}d|i}�j-d	7_-�j+j4|g�j,�j-��j.�r�t/j0t �j-t1dt2|i��_nt/j0d	�j-d�j3d|�f��_�qlW�jr:y4�j5j6�j�j�}�j7|7_7�j|d��_Wq:t8k
�rr}z|j9t9j:k�rb�WYdd}~Xq:Xq:W�j
t;|�O_
dS)Nrcs&�j|jd�}�j|s"�j|=|S)Nr)r��pop)Zchunkidr�)rBr(r)�pop_preload_msgid�s
z5RemoteRepository.call_many.<locals>.pop_preload_msgidcs||dj�}d|k}|jd�}|dkr8tj�jj���n@|dkrRtj�jj���n&|dkrltj�jj���n|dkr�|r�td��nt|dj���n�|d	kr�|r�tj	d��ntj	|dj���n�|d
kr�|r�t
d��nt
|dj���n�|dk�rtj|dj���nr|d
k�rB|�r(tjd�jj��ntj|dj��jj��n6|dk�rn|�r\t
d��nt
|dj���n
�j|��dS)Nsexception_classsexception_argsr�r�r�r	z(not available)r�AtticRepositoryr1z	(unknown)�ParentPathDoesNotExistr�r2)r<r[rr�r�Z	processedr�r�r	r.r1r/r�r2r�)r�r�Z
old_serverr�)rBr(r)�handle_error�s@






z0RemoteRepository.call_many.<locals>.handle_errorzPshutdown_time reached, shutting down with %d waiting_for and %d async_responses.rsexception_classrzFD exception occurredrsi�r�T)�keepends�
r�zutf-8r[z&is_preload is only supported for 'get'rI���)r2r�)<rYrr#r�r�r�r rrr,r��KeyError�popitemrr�r��MAX_INFLIGHTr�r�r	r
rr�r!r�r�r+r�r�r�r�r�r�r�r4�remover�r��
splitlines�endswith�handle_remote_liner<rr�rr�r�rr�r�r�r'�
setdefaultr�r"r��OSError�errnoZEAGAINr|)rBr)�callsr��is_preloaded�
async_waitr-r0Zwaiting_forr�r�Zw_fdsr�r�r�r%r&r�r�r��lines�liner�Zchunk_idr�r�r()rBr)r(�s�)






$





*
$zRemoteRepository.call_manyz1.0.0z1.0.7)r�r�z1.1.9)r�rQr�cCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBrLrMrNrOrPrQr�r(r(r)ra�szRemoteRepository.open)r�cCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBrErFr(r(r)rT�szRemoteRepository.checkcCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBrFr(r(r)rU�szRemoteRepository.commitcCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBr(r(r)rV�szRemoteRepository.rollbackcCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBr(r(r)rW�szRemoteRepository.destroycCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBr(r(r)rX�szRemoteRepository.__len__cCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBrGrHr(r(r)rY�szRemoteRepository.listz1.1.0b3cCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBrGrHr(r(r)ri�szRemoteRepository.scancCsx|j|g�D]}|SWdS)N)�get_many)rBrIr+r(r(r)r[�szRemoteRepository.getccs.x(|jddd�|D�|d�D]
}|VqWdS)Nr[cSsg|]}d|i�qS)rIr()r6rIr(r(r)r7�sz-RemoteRepository.get_many.<locals>.<listcomp>)r?)r()rB�idsr?r+r(r(r)rC�s zRemoteRepository.get_manycCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBrIr&r�r(r(r)rZ�szRemoteRepository.putcCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBrIr�r(r(r)r\�szRemoteRepository.deletecCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBrJr(r(r)r]�szRemoteRepository.save_keycCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBr(r(r)r^�szRemoteRepository.load_keycCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBr(r(r)rb�szRemoteRepository.get_free_noncecCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBrRrSr(r(r)rc�sz)RemoteRepository.commit_nonce_reservationcCsdS)z;actual remoting is done via self.call in the @api decoratorNr()rBr(r(r)r_�szRemoteRepository.break_lockcCs2|jr.|jjj�|jjj�|jj�d|_dS)N)rr�r�r�r�)rBr(r(r)r��s

zRemoteRepository.closecCs"x|jdgd|d�D]}|SWdS)NrT)r>r�r@)r()rBr�r+r(r(r)�async_response�szRemoteRepository.async_responsecCs|j|7_dS)N)r�)rBrDr(r(r)�preload�szRemoteRepository.preload)FFNTFFN)TFT)FNTFFF)FF)F)NN)NN)F)T)T)T)+r,r-r.r rr�rr�r�rArrr�rr�rrrr'r�r(r�rrarTrUrVrWrXrYrir[rCrZr\r]r^rbrcr_r�rErFr(r(r(r)r��s^"
S
1
7

r�cCs|jd�st�|jd��rbtj|�}|ddkrFtjd|d|�d	S|ddkr�tt|d
tj	�}t
|t�srt�tj|d�}d|d
|d
<tjd�jr�||j
�kr�tjjtj|�d�n|j|d|d
�n�|djd��rtjd�}|j
�tjk�rtjd�j�r>d
|k�r&d|d
|d
<tjjtj|�d�n"d
|k�rtjjd|d
d�n�|jd��r�|jdd�\}}}tt|tj	�}|jd��r�tj||j��n&|jdd�\}}tj|�j||j��n8tjd�j�r�tjd�jd|j��ntjjd|�d	S)zv
    Handle a remote log line.

    This function is remarkably complex because it handles multiple wire formats.
    �
r��{�type�progress_message�progress_percent�log_messagez3Dropped remote log message with unknown type %r: %sNZ	levelnamerqzRemote: �messagerz%sZ	progress_zborg.output.progressz$LOG r8rzRemote:rr�)rGr�)rJrKrL)r9rr�r��loadsr�Zwarningr�r�rr�r�r�ZgetEffectiveLevelr�r�r"�dumpsr�rr%�rstrip�strip)rBr�r�Z
target_loggerZprogress_loggerr�Zlognamer(r(r)r:�sB



r:c@sLeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zddd�Z	dd�Z
dS)�RepositoryNoCacheaRA not caching Repository wrapper, passes through to repository.

    Just to have same API (including the context manager) as RepositoryCache.

    *transform* is a callable taking two arguments, key and raw repository data.
    The return value is returned from get()/get_many(). By default, the raw
    repository data is returned.
    NcCs||_|pdd�|_dS)NcSs|S)Nr()�keyr&r(r(r)�<lambda>,sz,RepositoryNoCache.__init__.<locals>.<lambda>)rk�	transform)rBrkrUr(r(r)rA*szRepositoryNoCache.__init__cCsdS)Nr()rBr(r(r)r�.szRepositoryNoCache.closecCs|S)Nr()rBr(r(r)r�1szRepositoryNoCache.__enter__cCs|j�dS)N)r�)rBrrrr(r(r)r4szRepositoryNoCache.__exit__cCst|j|gdd��S)NF)�cache)�nextrC)rBrSr(r(r)r[7szRepositoryNoCache.getTccs2x,t||jj|��D]\}}|j||�VqWdS)N)�ziprkrCrU)rB�keysrVrSr&r(r(r)rC:szRepositoryNoCache.get_manycCsdS)Nr()rBr(r(r)�log_instrumentation>sz%RepositoryNoCache.log_instrumentation)N)T)r,r-r.r/rAr�r�rr[rCrZr(r(r(r)rR!s

rRcs\eZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
ddd�Z�ZS)�RepositoryCacheaf
    A caching Repository wrapper.

    Caches Repository GET operations locally.

    *pack* and *unpack* complement *transform* of the base class.
    *pack* receives the output of *transform* and should return bytes,
    which are stored in the cache. *unpack* receives these bytes and
    should return the initial data (as returned by *transform*).
    Ncsvt�j||�|pdd�|_|p&dd�|_t�|_tjdd�|_|j	�d|_
d|_d|_d|_
d|_d|_d|_dS)NcSs|S)Nr()r&r(r(r)rTPsz*RepositoryCache.__init__.<locals>.<lambda>cSs|S)Nr()r&r(r(r)rTQszborg-cache-)�prefixrg)r@rA�pack�unpackr|rV�tempfileZmkdtemp�basedir�query_size_limit�size�hits�misses�slow_misses�slow_lat�	evictions�enospc)rBrkr]r^rU)rCr(r)rANszRepositoryCache.__init__cCs0tj|j�}|j|j}tt|dd��|_dS)Ng�?r�l)r!�statvfsr`�f_bavail�f_frsizer��min�
size_limit)rBZstat_fsZavailable_spacer(r(r)ra^sz RepositoryCache.query_size_limitcCstjj|jt|��S)N)r!rLr?r`r
)rBrSr(r(r)�key_filenamecszRepositoryCache.key_filenamecCsr|j�td|j�}xV|j|krl|jrl|jj�}|j|�}|jtj|�j	8_tj
|�|jd7_qWdS)Ng�������?r)rar�rnrbrVr,ror!�stat�st_size�unlinkrg)rBZtarget_sizerS�filer(r(r)�backofffs


zRepositoryCache.backoffc	Cs�|j||�}|s|S|j|�}|j|�}y$t|d��}|j|�WdQRXWnjtk
r�}zNyt|�Wntk
r~YnX|jtj	kr�|j
d7_
|j�n�WYdd}~Xn4X|jt
|�7_|jj|�|j|jkr�|j�|S)N�wbr)rUr]rorar"r<r�FileNotFoundErrorr=ZENOSPCrhrtrbr rV�addrn)	rBrSr&rV�transformedZpackedrsr%Zos_errorr(r(r)�	add_entryps,


zRepositoryCache.add_entrycCs>tjdt|j�t|j�t|j�|j|j|j	|j
|j|j�
dS)NzyRepositoryCache: current items %d, size %s / %s, %d hits, %d misses, %d slow misses (+%.1fs), %d evictions, %d ENOSPC hit)
r�r�r rVrrbrnrcrdrerfrgrh)rBr(r(r)rZ�sz#RepositoryCache.log_instrumentationcCs"|j�|jj�tj|j�dS)N)rZrV�clear�shutilZrmtreer`)rBr(r(r)r��s
zRepositoryCache.closeTc
#s�fdd�|D�}t|�jj|��}x�|D]�}|�jkrx�j|�}t|d��$}�jd7_�j|j��VWdQRXq*x�|D]4\}}	||kr~�j	||	|�}
�j
d7_
|
VPq~Wtj�}�jj
|�}	�jtj�|7_�j	||	|�}
�jd7_|
Vq*Wx|D]}�qWdS)Ncsg|]}|�jkr|�qSr()rV)r6rS)rBr(r)r7�sz,RepositoryCache.get_many.<locals>.<listcomp>�rbr)rXrkrCrVrorarcr^r�ryrdr#Zperf_counterr[rfre)
rBrYrVZunknown_keysZrepository_iteratorrSrsr%Zkey_r&rxZt0r�r()rBr)rC�s,




zRepositoryCache.get_many)NNN)T)
r,r-r.r/rArarortryrZr�rCrDr(r()rCr)r[Bs

r[F)�decrypted_cacher]r^rU�force_cachecs�|r|s|s|rtd��n@|rZ|�tjd��t����fdd�}��fdd�}�fdd�}t|t�sh|rvt||||�St||�Sd	S)
a�
    Return a Repository(No)Cache for *repository*.

    If *decrypted_cache* is a key object, then get and get_many will return a tuple
    (csize, plaintext) instead of the actual data in the repository. The cache will
    store decrypted data, which increases CPU efficiency (by avoiding repeatedly decrypting
    and more importantly MAC and ID checking cached objects).
    Internally, objects are compressed with LZ4.
    z:decrypted_cache and pack/unpack/transform are incompatiblez=I8scs&|\}}�j|�}�j|t|��|S)N)�compressr]r)r&�csize�	decrypted�
compressed)�cache_struct�
compressorr(r)r]�s
zcache_if_remote.<locals>.packcsPt|�}�j|d�j��\}}|�jd�}|t|�krBtd��|�j|�fS)Nz)detected corrupted data in metadata cache)�
memoryviewr^rbrr	Z
decompress)r&r�Zchecksumr�)r�r�r(r)r^�szcache_if_remote.<locals>.unpackcst|�}�j||�}||fS)N)r Zdecrypt)Zid_r&r�r�)rSr(r)rU�sz"cache_if_remote.<locals>.transformN)r�struct�Structrr�r�r[rR)rkr}r]r^rUr~r()r�r�rSr)�cache_if_remote�s


r�)rrrr)rErF)rF)rGrH)rIr&)rI)rI)rJ)rK)rLrMrNrOrPrQ)rRrS)Ir=r�r�r}r�r�r!r�r$r{r�r�r_r>r#r��
subprocessrrr�rrrZ	constantsZhelpersrr	r
rrr
rrrrrr�rrrrkrr
rrZalgorithms.checksumsrr,r�r�r�r�r�r�r6r�r*r+r0r1r2r3r4rurgrhr�r�r�r:rRr[r�r(r(r(r)�<module>s�#4xJ!q