403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /usr/lib64/python3.9/site-packages/mercurial/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /usr/lib64/python3.9/site-packages/mercurial/__pycache__/util.cpython-39.opt-1.pyc
a

�+�b�|�@s�	dZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZddlmZmZmZm Z ddlmZddl!m"Z"dd	l#m$Z$m%Z%m&Z&m'Z'mZm(Z(dd
l)m*Z*m+Z+m,Z,m-Z-ej.�rDddl/m0Z0m1Z1m2Z2m3Z3e'�4d�Z5e'�4d
�Z6e5j7Z7e5j8Z8ej9Z9ej:Z:ej;Z;ej<Z<ej=Z=ej>Z>e>Z?ej@Z@e(jAZAe(jBZBe(jCZCejDZEejF�r�ddl#mGZnddl#mHZe&jIZIejJZJejKZKejLZLejMZMejNZNejOZOejPZPejQZQejRZRejSZSejTZTejUZUejVZVejWZWe6jXZXejYZYejZZZej[Z[ej\Z\ej]Z]ej^Z^ej_Z_ej`Z`ejaZaejbZbejcZcejdZdejeZeejfZfejgZgejhZhejiZiejjZjejkZkejlZlejmZmejnZnee6dejo�ZoejpZpejqZqejrarejsZsejtZtdd�Zue*jvZve*jwZwe*jxZxz
e6jyZyWnez�yYn0e{�Z|dd�Z}e~e$j��d��Z�e��rje��dde�d�e��dde�d�e��dde�d�e��r�ej��r�e��dde�d�e��dde�d�e��dde�d�d�dd �Z�e	j�e+j�e	j�d!�Z�gd"�Z�e�D]Z��q�Gd#d$�d$e{�Z�Gd%d&�d&e{�Z�ze�Z�Wne��yd�d'd(�Z�Yn0d)Z�Gd*d+�d+e{�Z�d�d,d-�Z�Gd.d/�d/e{�Z�Gd0d1�d1e��Z�hd2�Z�Gd3d4�d4e{�Z�Gd5d6�d6e{�Z�Gd7d8�d8e��Z��dd;d<�Z�Gd=d>�d>e��Z��dd?d@�Z�dAdB�Z��ddDdE�Z�dFdG�Z�GdHdI�dIe{�Z�GdJdK�dKej��Z�GdLdM�dMe�e��Z�GdNdO�dOe�e��Z�GdPdQ�dQe{�Z�ej��ddRdS��Z�ej��ddTdU��Z�GdVdW�dWe{�Z�GdXdY�dYe{�Z�dZd[�Z�Gd\d]�d]e{�Z�d^d_�Z��ddbdc�Z�ddde�Z�dfdg�Z�dhdi�Z�ej��r�djdk�Z�dldm�Z��ddndo�Z�hdp�Z��ddqdr�Z��ddsdt�Z�hdu�Z�dvZ�dwdx�Z�eedyd�Z�ejF�r6e�Z�e��sHej�Z�nej�Z�e��sHejZ�dzd{�Z�d|d}�Z�d~d�Z�d�d��Z�d�dk�a�zddl�Z�da�WneŐy�d:a�Yn0Gd�d��d�e{�Z�eƃZiZ�d�d��Z�d�d��Z�d�d��Z�d�d��Zːd	d�d��Z�Gd�d��d�e{�Z�Gd�d��d�e{�Zΐd
d�d��Z�d�d��ZАdd�d��Z�d�d��Z�d�d��Z�d�d��Z�Gd�d��d�e{�ZՐdd�d��Z�Gd�d��d�e{�Z�d�d��Z�d�d��Z�e�d�d�eId��fd�d�eId��fdd�eId��fd�d�eId��fd�d�eId��fdd�eId��fd�d`eId��fd�d`eId��fdd`eId��fddeId��f�
Z�Gd�d��d�e{�Z�e��d��Z�d�d��Z�d�d��Z�d�d��Z�ej�d�k�r>e�Z�e�Z�e�Z�nej�Z�ej�Z�ej�Z�e��d�k�rtej�d�k�rtd�dńZ�nd�dńZ�d�dȄZ�d�dʄZ�d
d�d̄Z�e�dd�eId΃fd�deIdσfd�deIdЃfddeIdуfd�d�eIdӃfd�d�eIdԃfdd�eIdՃfd�d�eId׃fd�d�eId؃fdd�eIdكfd�d�eIdۃfd�d�eId܃fdd�eId݃f�
Z�ej�Gd�d߄d�e{��Z�ej�d�d��Z�de�_�d�d�Z�d�Z�d�d�Z�Gd�d�d�e{�Z�dd�d�Z�d�de,j�e,j�dd�fd�d�Z�e�Z��dd�d�Z�d�d�Z�d�d��Z�d�d��Z�ej�d�d���Z�d�d��Z�dS(z�Mercurial utility functions and platform specific implementations.

This contains helper routines that are independent of the SCM core and
hide platform-specific details from the core.
�)�absolute_import�print_functionN�)�hex)�attr)�delattr�getattr�open�setattr)�tracing)�encoding�error�i18n�policy�pycompat�urllibcompat)�compression�hashutil�procutil�
stringutil)�Iterator�List�Optional�Tuple�base85�osutil)�windows)�posix�	statfilescCs&tjr
dSt�|�|d@t_adS)z%updates the umask. used by chg serverNi�)r�	iswindows�os�umask�platform)�val�r$�4/usr/lib64/python3.9/site-packages/mercurial/util.py�setumask�s
r&cCsd}|D]}||O}q|S�Nrr$)�	container�bits�bitr$r$r%�bitsfrom�s
r+sHGEMITWARNINGS�default�Z	mercurialZhgextZhgext3rd�ignorez
bad escapezinvalid escape sequencezthe imp module is deprecatedcCs6tr2|d|7}t�t�|�t|d�tj��dS)zxIssue an python native deprecation warning

    This is a noop outside of tests, use 'ui.deprecwarn' when possible.
    sF
(compatibility will be dropped after Mercurial-%s, update your code.)rN)	�_dowarn�warnings�warnr�sysstr�DeprecationWarning�sys�stderr�flush)�msg�version�
stacklevelr$r$r%�nouideprecwarn�s�r:)�md5�sha1�sha512)r=r<r;c@s>eZdZdZddd�Zdd�Zdd�Zd	d
�Zedd��Z	d
S)�digestera�helper to compute digests.

    This helper can be used to compute one or more digests given their name.

    >>> d = digester([b'md5', b'sha1'])
    >>> d.update(b'foo')
    >>> [k for k in sorted(d)]
    ['md5', 'sha1']
    >>> d[b'md5']
    'acbd18db4cc2f85cedef654fccc4a4d8'
    >>> d[b'sha1']
    '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
    >>> digester.preferred([b'md5', b'sha1'])
    'sha1'
    �cCsLi|_|D].}|tvr(t�td�|��t|�|j|<q
|rH|�|�dS�Nsunknown digest type: %s)�_hashes�DIGESTSr
�Abort�_�update)�self�digests�s�kr$r$r%�__init__�szdigester.__init__cCs|j��D]}|�|�q
dS�N)rA�valuesrE)rF�data�hr$r$r%rEszdigester.updatecCs,|tvrt�td�t��t|j|���Sr@)rBr
rCrDrIrrA�digest)rF�keyr$r$r%�__getitem__
szdigester.__getitem__cCs
t|j�SrK)�iterrA�rFr$r$r%�__iter__szdigester.__iter__cCstD]}||vr|SqdS)z@returns the strongest digest type in both supported and DIGESTS.N)�DIGESTS_BY_STRENGTH)Z	supportedrIr$r$r%�	preferreds
zdigester.preferredN)r?)
�__name__�
__module__�__qualname__�__doc__rJrErQrT�staticmethodrVr$r$r$r%r>�s
	r>c@s*eZdZdZdd�Zd
dd�Zdd�Zd	S)�
digestcheckerz�file handle wrapper that additionally checks content against a given
    size and digests.

        d = digestchecker(fh, size, {'md5': '...'})

    When multiple digests are given, all of them are validated.
    cCs0||_||_d|_t|�|_t|j���|_dSr')�_fh�_size�_got�dict�_digestsr>�keys�	_digester)rF�fh�sizerGr$r$r%rJ%s

zdigestchecker.__init__���cCs.|j�|�}|j�|�|jt|�7_|SrK)r]�readrcrEr_�len)rF�lengthZcontentr$r$r%rg,szdigestchecker.readcCsj|j|jkr&t�td�|j|jf��|j��D]4\}}||j|kr0t�td�|||j|f��q0dS)Ns"size mismatch: expected %d, got %ds %s mismatch: expected %s, got %s)r^r_r
rCrDra�itemsrc�rFrI�vr$r$r%�validate2s
����zdigestchecker.validateN)rf)rWrXrYrZrJrgrmr$r$r$r%r\s
r\cCs,|durt|�|||�St|�|d�SrK)�
memoryview)Z	sliceable�offsetrir$r$r%�bufferEsrpics|eZdZdZ�fdd�Zdd�Zedd��Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zefdd�Z�ZS)�bufferedinputpipeaWa manually buffered input pipe

    Python will not let us use buffered IO and lazy reading with 'polling' at
    the same time. We cannot probe the buffer state and select will not detect
    that data are ready to read if they are already buffered.

    This class let us work around that by implementing its own buffering
    (allowing efficient readline) while offering a way to know if the buffer is
    empty from the output (allowing collaboration of the buffer with polling).

    This class lives in the 'util' module because it makes use of the 'os'
    module from the python stdlib.
    cst|t�rt}tt|��|�SrK)�
isinstance�fileobjectproxy�observedbufferedinputpipe�superrq�__new__)�clsrd��	__class__r$r%rv]s
zbufferedinputpipe.__new__cCs||_g|_d|_d|_dS)NFr)�_input�_buffer�_eof�_lenbuf)rF�inputr$r$r%rJeszbufferedinputpipe.__init__cCs
t|j�S)z�True is any data is currently buffered

        This will be used externally a pre-step for polling IO. If there is
        already data then no polling should be set in place.)�boolr{rSr$r$r%�	hasbufferkszbufferedinputpipe.hasbuffercCs|jjSrK)rz�closedrSr$r$r%r�sszbufferedinputpipe.closedcCs
|j��SrK)rz�filenorSr$r$r%r�wszbufferedinputpipe.filenocCs
|j��SrK)rz�closerSr$r$r%r�zszbufferedinputpipe.closecCs$|js|j|kr|��q|�|�SrK)r|r}�_fillbuffer�_frombuffer�rFrer$r$r%rg}s
zbufferedinputpipe.readcCs2|js |jdkr |�t|t��|�t|j|��Sr')r|r}r��max�
_chunksizer��minr�r$r$r%�unbufferedread�sz bufferedinputpipe.unbufferedreadcOs�t|j�dkr.d�|j�g|_t|jd�|_d}|jrH|jd�d�}|jsv|dkrv|��|jrH|jd�d�}qH|d}|dkr�|j}n&t|j�dkr�||jt|jd�7}|�|�S)Nrr?rrf�
)rhr{�joinr}�findr|r�r�)rF�args�kwargsZlfirer$r$r%�readline�s zbufferedinputpipe.readlinecCsz|dks|jsdS|jd}t|j�dkr6d�|j�}|d|�}|t|�d�}|rj|g|_t|�|_ng|_d|_|S)zYreturn at most 'size' data from the buffer

        The data are removed from the buffer.rr?rN)r{rhr�r})rFre�bufrMr$r$r%r��s
zbufferedinputpipe._frombuffercCs@t�|j��|�}|sd|_n|jt|�7_|j�|�|S)zread data to the bufferT)	r rgrzr�r|r}rhr{�append)rFrerMr$r$r%r��szbufferedinputpipe._fillbuffer)rWrXrYrZrvrJ�propertyr�r�r�r�rgr�r�r�r�r��
__classcell__r$r$rxr%rqNs

rqcsr|dkrdS|durd}t�d�fdd���}ztj||tjd�WStylt�|�jdkrfYdS�Yn0dS)Nrr?r�cs�SrKr$r$��fpr$r%�<lambda>�r?zmmapread.<locals>.<lambda>)�access)r�mmapZACCESS_READ�
ValueErrorr �fstat�st_size)r�re�fdr$r�r%�mmapread�sr�c@s�eZdZdZdZdd�Zdd�Zdd�ZeZd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7S)8rsz�A proxy around file objects that tells a watcher when events occur.

    This type is intended to only be used for testing purposes. Think hard
    before using it in important code.
    ��_orig�	_observercCs t�|d|�t�|d|�dS�Nr�r���object�__setattr__)rFrd�observerr$r$r%rJ�szfileobjectproxy.__init__cCs.hd�}||vrt�||�Stt�|d�|�S)N>�seek�readallr��tell�readintorgr��write�read1�readabler��isatty�truncater��detach�seekable�writable�
writelinesr6�	readlinesr��r��__getattribute__r)rF�nameZoursr$r$r%r��s z fileobjectproxy.__getattribute__cCstt�|d��S�Nr��rr�r�rSr$r$r%�__nonzero__szfileobjectproxy.__nonzero__cCstt�|d�|�Sr��rr�r��rFr�r$r$r%�__delattr__	szfileobjectproxy.__delattr__cCstt�|d�||�Sr��r
r�r��rFr��valuer$r$r%r�szfileobjectproxy.__setattr__cCst�|d���Sr�)r�r�rTrSr$r$r%rTszfileobjectproxy.__iter__cOsVt�|d�}t||�|i|��}t�|d�}t||d�}|rR||g|�Ri|��|Sr�r��rFr�r�r�Zorig�resr��fnr$r$r%�
_observedcallszfileobjectproxy._observedcallcOst�|d�dg|�Ri|��S)Nr�r��r�r��rFr�r�r$r$r%r� s
���zfileobjectproxy.closecOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�%s
���zfileobjectproxy.filenocOst�|d�dg|�Ri|��S)Nr�r6r�r�r$r$r%r6*s
���zfileobjectproxy.flushcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�/s
���zfileobjectproxy.isattycOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�4s
���zfileobjectproxy.readablecOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�9s
���zfileobjectproxy.readlinecOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�>s
���zfileobjectproxy.readlinescOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�Cs
���zfileobjectproxy.seekcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�Hs
���zfileobjectproxy.seekablecOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�Ms
���zfileobjectproxy.tellcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�Rs
���zfileobjectproxy.truncatecOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�Ws
���zfileobjectproxy.writablecOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�\s
���zfileobjectproxy.writelinescOst�|d�dg|�Ri|��S)Nr�rgr�r�r$r$r%rgas
���zfileobjectproxy.readcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�fs
���zfileobjectproxy.readallcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�ks
���zfileobjectproxy.readintocOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�ps
���zfileobjectproxy.writecOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�us
���zfileobjectproxy.detachcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�zs
���zfileobjectproxy.read1N) rWrXrYrZ�	__slots__rJr�r��__bool__r�r�rTr�r�r�r6r�r�r�r�r�r�r�r�r�r�rgr�r�r�r�r�r$r$r$r%rs�s:&rscs8eZdZdZ�fdd�Z�fdd�Z�fdd�Z�ZS)rta�A variation of bufferedinputpipe that is aware of fileobjectproxy.

    ``bufferedinputpipe`` makes low-level calls to ``os.read()`` that
    bypass ``fileobjectproxy``. Because of this, we need to make
    ``bufferedinputpipe`` aware of these operations.

    This variation of ``bufferedinputpipe`` can notify observers about
    ``os.read()`` events. It also re-publishes other events, such as
    ``read()`` and ``readline()``.
    cs0tt|���}t|jjdd�}|r,||t�|S)NZosread)rurtr�rrzr�r�)rFr�r�rxr$r%r��s

z%observedbufferedinputpipe._fillbuffercs2tt|��|�}t|jjdd�}|r.|||�|S)N�bufferedread)rurtrgrrzr�)rFrer�r�rxr$r%rg�s

zobservedbufferedinputpipe.readcs6tt|�j|i|��}t|jjdd�}|r2||�|S)N�bufferedreadline)rurtr�rrzr�)rFr�r�r�r�rxr$r%r��s
z"observedbufferedinputpipe.readline)rWrXrYrZr�rgr�r�r$r$rxr%rt�s	rt>�	recv_into�recvfrom�sendall�recv�
setsockopt�setblocking�
recvfrom_into�
settimeout�
gettimeout�send�makefile�sendtoc@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	e	Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'S)(�socketproxyz�A proxy around a socket that tells a watcher when events occur.

    This is like ``fileobjectproxy`` except for sockets.

    This type is intended to only be used for testing purposes. Think hard
    before using it in important code.
    r�cCs t�|d|�t�|d|�dSr�r�)rFZsockr�r$r$r%rJ�szsocketproxy.__init__cCs&|tvrt�||�Stt�|d�|�Sr�)�PROXIED_SOCKET_METHODSr�r�rr�r$r$r%r��szsocketproxy.__getattribute__cCstt�|d�|�Sr�r�r�r$r$r%r��szsocketproxy.__delattr__cCstt�|d�||�Sr�r�r�r$r$r%r��szsocketproxy.__setattr__cCstt�|d��Sr�r�rSr$r$r%r��szsocketproxy.__nonzero__cOsVt�|d�}t||�|i|��}t�|d�}t||d�}|rR||g|�Ri|��|Sr�r�r�r$r$r%r��szsocketproxy._observedcallc	OsLt�|d�dg|�Ri|��}t�|d�}t|j||j|j|j|j|jd�S)Nr�r�r���reads�writes�logdata�logdataapis)	r�r��makeloggingfileobjectrdr�r�r�r�r�)rFr�r�r�r�r$r$r%r��s"
����zsocketproxy.makefilecOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r��s
���zsocketproxy.recvcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�s
���zsocketproxy.recvfromcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�s
���zsocketproxy.recvfrom_intocOst�|d�dg|�Ri|��S)Nr�Z	recv_infor�r�r$r$r%r�s
���zsocketproxy.recv_intocOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�s
���zsocketproxy.sendcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�s
���zsocketproxy.sendallcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�s
���zsocketproxy.sendtocOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r� s
���zsocketproxy.setblockingcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�%s
���zsocketproxy.settimeoutcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�*s
���zsocketproxy.gettimeoutcOst�|d�dg|�Ri|��S)Nr�r�r�r�r$r$r%r�/s
���zsocketproxy.setsockoptN)rWrXrYrZr�rJr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r$r$r$r%r��s*r�c@seZdZdd�Zdd�ZdS)�baseproxyobservercCs||_||_||_||_dSrK)rdr�r�r�)rFrdr�r�r�r$r$r%rJ6szbaseproxyobserver.__init__cCs�|js&|jr"|j�d�|j��dSd|vrv|jrL|j�dt�|��n|j�d|jt�|�f�|j��dS|jr�|j�d�|�d�}|D] }|j�d|jt�|�f�q�|j��dS)Nr�s: %s
s%s>     %s
s:
T)	r�r�rdr�r6r�	escapestrr��
splitlines)rFrM�lines�liner$r$r%�
_writedata<s*
�

�zbaseproxyobserver._writedataN)rWrXrYrJr�r$r$r$r%r�5sr�cs^eZdZdZd�fdd�	Zddd�Zdd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Z�ZS)�fileobjectobserverzLogs file object activity.TFcs&tt|��||||�||_||_dSrK)rur�rJr�r�)rFrdr�r�r�r�r�rxr$r%rJ]szfileobjectobserver.__init__rfcCsZ|js
dS|durd}|dkr*|dkr*dS|jrL|j�d|j|t|�f�|�|�dS)Nr?rfs%s> read(%d) -> %d�r�r�rdr�r�rhr��rFr�rer$r$r%rgdszfileobjectobserver.readcCs8|js
dS|jr*|j�d|jt|�f�|�|�dS)Ns%s> readline() -> %dr�)rFr��limitr$r$r%r�ws
zfileobjectobserver.readlinecCsd|js
dS|jr,|j�d|jt|�|f�|dur@|d|�nd}t|t�rV|��}|�	|�dS)Ns%s> readinto(%d) -> %rrr?)
r�r�rdr�r�rhrrrn�tobytesr�)rFr��destrMr$r$r%r��s�
zfileobjectobserver.readintocCsN|js
dS|dur|rt|�}|jr@|j�d|jt|�|f�|�|�dS)Ns%s> write(%d) -> %r)r�rhr�rdr�r�r�)rFr�rMr$r$r%r��szfileobjectobserver.writecCs$|js
dS|j�d|j|f�dS)Ns%s> flush() -> %r
)r�rdr�r��rFr�r$r$r%r6�szfileobjectobserver.flushcCs:|js
dS|jr,|j�d|j|t|�f�|�|�dS)Ns%s> bufferedread(%d) -> %dr�r�r$r$r%r��s�zfileobjectobserver.bufferedreadcCs8|js
dS|jr*|j�d|jt|�f�|�|�dS)Ns%s> bufferedreadline() -> %dr�r�r$r$r%r��s�z#fileobjectobserver.bufferedreadline)TTFT)rf)rf)
rWrXrYrZrJrgr�r�r�r6r�r�r�r$r$rxr%r�Zs�

	r�TFcCst||||||d�}t||�S)z.Turn a file object into a logging file object.r�)r�rs)�loghrdr�r�r�r�r�r�r$r$r%r��s�r�cs�eZdZdZd �fdd�	Zd!dd�Zd"d
d�Zd#dd
�Zd$dd�Zd%dd�Z	d&dd�Z
d'dd�Zd(dd�Zdd�Z
dd�Zdd�Zdd�Z�ZS))�socketobserverzLogs socket activity.TFcs,tt|��||||�||_||_||_dSrK)rur�rJr�r��states)rFrdr�r�r�r�r�r�rxr$r%rJ�s
zsocketobserver.__init__NcCs&|js
dS|j�d|j||f�dS)Ns%s> makefile(%r, %r)
�r�rdr�r�)rFr��mode�bufsizer$r$r%r��szsocketobserver.makefilercCs<|js
dS|jr.|j�d|j||t|�f�|�|�dS)Ns%s> recv(%d, %d) -> %dr��rFr�re�flagsr$r$r%r��s�zsocketobserver.recvc	CsD|js
dS|jr2|j�d|j||t|d�f�|�|d�dS)Ns%s> recvfrom(%d, %d) -> %drr�r�r$r$r%r��s��zsocketobserver.recvfromcCsH|js
dS|jr.|j�d|j|||df�|�|d|d��dS)Ns%s> recvfrom_into(%d, %d) -> %dr�r�r�rdr�r�r��rFr�r�rer�r$r$r%r��s��zsocketobserver.recvfrom_intocCs@|js
dS|jr*|j�d|j|||f�|�|d|��dS)Ns%s> recv_into(%d, %d) -> %drr�r�r$r$r%r�s�zsocketobserver.recv_intocCs:|js
dS|j�d|jt|�|t|�f�|�|�dS)Ns%s> send(%d, %d) -> %d)r�rdr�r�rhr��rFr�rMr�r$r$r%r�s�zsocketobserver.sendcCs:|js
dS|jr,|j�d|jt|�|f�|�|�dS)Ns%s> sendall(%d, %d)�r�r�rdr�r�rhr�r�r$r$r%r�s�zsocketobserver.sendallcCsL|js
dS|r|}nd}|jr>|j�d|jt|�|||f�|�|�dS)Nrs%s> sendto(%d, %d, %r) -> %dr�)rFr�rMZflagsoraddressZaddressr�r$r$r%r�(s��zsocketobserver.sendtocCs$|js
dS|j�d|j|f�dS)Ns%s> setblocking(%r)
r�)rFr��flagr$r$r%r�9szsocketobserver.setblockingcCs$|js
dS|j�d|j|f�dS)Ns%s> settimeout(%r)
r�)rFr�r�r$r$r%r�?szsocketobserver.settimeoutcCs$|js
dS|j�d|j|f�dS)Ns%s> gettimeout() -> %f
r�r�r$r$r%r�Eszsocketobserver.gettimeoutcCs*|js
dS|j�d|j||||f�dS)Ns!%s> setsockopt(%r, %r, %r) -> %r
r�)rFr��levelZoptnamer�r$r$r%r�Ks��zsocketobserver.setsockopt)TTTFT)NN)r)r)r)rr)r)r)N)rWrXrYrZrJr�r�r�r�r�r�r�r�r�r�r�r�r�r$r$rxr%r��s&�






	

r�c		Cs t|||||||d�}t||�S)z$Turn a socket into a logging socket.)r�r�r�r�r�)r�r�)	r�rdr�r�r�r�r�r�r�r$r$r%�makeloggingsocketUs�	r�cCs.zddlm}|jWSty(YdS0dS)z(Return version information if available.r��__version__sunknownN)r-r�r8�ImportErrorr�r$r$r%r8ms
r8�c	Cs|s
t�}t�d|�}|s&d|}}n(|�d�r>|��\}}n|�d�d}}g}|�d�D]0}z|�t|��Wq\ty�Yq�Yq\0q\t	|�dkr�|�d�q�|dkr�|d|dfS|dkr�|d|d|dfS|d	k�r�|d|d|d|fSt
�d
|��dS)azParses a Mercurial version string into an N-tuple.

    The version string to be parsed is specified with the ``v`` argument.
    If it isn't defined, the current Mercurial version string will be parsed.

    ``n`` can be 2, 3, or 4. Here is how some version strings map to
    returned values:

    >>> v = b'3.6.1+190-df9b73d2d444'
    >>> versiontuple(v, 2)
    (3, 6)
    >>> versiontuple(v, 3)
    (3, 6, 1)
    >>> versiontuple(v, 4)
    (3, 6, 1, '190-df9b73d2d444')

    >>> versiontuple(b'3.6.1+190-df9b73d2d444+20151118')
    (3, 6, 1, '190-df9b73d2d444+20151118')

    >>> v = b'3.6'
    >>> versiontuple(v, 2)
    (3, 6)
    >>> versiontuple(v, 3)
    (3, 6, None)
    >>> versiontuple(v, 4)
    (3, 6, None, None)

    >>> v = b'3.9-rc'
    >>> versiontuple(v, 2)
    (3, 9)
    >>> versiontuple(v, 3)
    (3, 9, None)
    >>> versiontuple(v, 4)
    (3, 9, None, 'rc')

    >>> v = b'3.9-rc+2-02a8fea4289b'
    >>> versiontuple(v, 2)
    (3, 9)
    >>> versiontuple(v, 3)
    (3, 9, None)
    >>> versiontuple(v, 4)
    (3, 9, None, 'rc+2-02a8fea4289b')

    >>> versiontuple(b'4.6rc0')
    (4, 6, None, 'rc0')
    >>> versiontuple(b'4.6rc0+12-425d55e54f98')
    (4, 6, None, 'rc0+12-425d55e54f98')
    >>> versiontuple(b'.1.2.3')
    (None, None, None, '.1.2.3')
    >>> versiontuple(b'12.34..5')
    (12, 34, None, '..5')
    >>> versiontuple(b'1.2.3.4.5.6')
    (1, 2, 3, '.4.5.6')
    s(\d+(?:\.\d+){,2})[+-]?(.*)r?�rN�.�rr�s invalid version part request: %d)r8�remod�match�group�groups�splitr��intr�rhr
�ProgrammingError)rl�n�mZvpartsZextraZvints�ir$r$r%�versiontuplews.7

rcsT�jjdkr"g���fdd�}|Si��jjdkrB��fdd�}n��fdd�}|S)z"cache the result of function callsrcs t��dkr������dSr')rhr�r$)�func�	listcacher$r%�f�szcachefunc.<locals>.frcs|�vr�|��|<�|SrKr$��arg��cacher
r$r%r�scs|�vr�|��|<�|SrKr$�r�rr$r%r�s)�__code__�co_argcount�r
rr$)rr
rr%�	cachefunc�src@s eZdZdZdd�Zdd�ZdS)�cowz^helper class to make copy-on-write easier

    Call preparewrite before doing any writes.
    cCs(t|dd�r$|jd8_|�|�S|S)z;call this before writes, return self or a copied new object�_copiedrr)rrryrSr$r$r%�preparewrite�s
zcow.preparewritecCst|dd�d|_|S)zalways do a cheap copyrrr)rrrSr$r$r%�copy�szcow.copyN)rWrXrYrZrrr$r$r$r%r�srcs6eZdZdZ�fdd�Zejr&dd�Zdd�Z�Z	S)�sortdicta[a simple sorted dictionary

    >>> d1 = sortdict([(b'a', 0), (b'b', 1)])
    >>> d2 = d1.copy()
    >>> d2
    sortdict([('a', 0), ('b', 1)])
    >>> d2.update([(b'a', 2)])
    >>> list(d2.keys()) # should still be in last-set order
    ['b', 'a']
    >>> d1.insert(1, b'a.5', 0.5)
    >>> d1
    sortdict([('a', 0), ('a.5', 0.5), ('b', 1)])
    cs$||vr||=tt|��||�dSrK)rur�__setitem__)rFrPr�rxr$r%rszsortdict.__setitem__cKsDt|t�rt�|�}|D]\}}|||<q|D]}||||<q.dSrK)rrr`rZ	iteritems)rF�srcrrIrlr$r$r%rEs


zsortdict.updatecCsHtt|����D]2\}\}}||kr,|||<||kr||=|||<qdSrK)�	enumerate�listrj)rFZpositionrPr�rrIrlr$r$r%�insertszsortdict.insert)
rWrXrYrZrr�ispypyrEr"r�r$r$rxr%rs
rc@seZdZdZdS)�cowdicta�copy-on-write dict

    Be sure to call d = d.preparewrite() before writing to d.

    >>> a = cowdict()
    >>> a is a.preparewrite()
    True
    >>> b = a.copy()
    >>> b is a
    True
    >>> c = b.copy()
    >>> c is a
    True
    >>> a = a.preparewrite()
    >>> b is a
    False
    >>> a is a.preparewrite()
    True
    >>> c = c.preparewrite()
    >>> b is c
    False
    >>> b is b.preparewrite()
    True
    N�rWrXrYrZr$r$r$r%r$(sr$c@seZdZdZdS)�cowsortdictzZcopy-on-write sortdict

    Be sure to call d = d.preparewrite() before writing to d.
    Nr%r$r$r$r%r&Csr&c@sBeZdZdZejZejdd��Zejdd��Z	dd�Z
dd	�Zd
S)�
transactionalzBBase class for making a transactional type into a context manager.cCsdS)z$Successfully closes the transaction.Nr$rSr$r$r%r�Osztransactional.closecCsdS)zoMarks the end of the transaction.

        If the transaction has not been closed, it will be aborted.
        Nr$rSr$r$r%�releaseSsztransactional.releasecCs|SrKr$rSr$r$r%�	__enter__Zsztransactional.__enter__cCs,z|dur|��W|��n
|��0dSrK)r�r()rF�exc_typeZexc_valZexc_tbr$r$r%�__exit__]s
ztransactional.__exit__N)rWrXrYrZ�abc�ABCMetaZ
__metaclass__�abstractmethodr�r(r)r+r$r$r$r%r'Js

r'ccs\|sdVdSz>zdV|��Wntjy@|���Yn0W|��n
|��0dS)z�A context manager that closes the transaction on InterventionRequired

    If no transaction was provided, this simply runs the body and returns
    N)r�r
ZInterventionRequiredr()�trr$r$r%�acceptinterventiones
r0ccs
|VdSrKr$)�enter_resultr$r$r%�nullcontextmanagerxsr2c@s$eZdZdZdZdd�Zdd�ZdS)�
_lrucachenodez�A node in a doubly linked list.

    Holds a reference to nodes on either side as well as a key-value
    pair for the dictionary entry.
    )�next�prevrPr��costcCs"||_||_t|_d|_d|_dSr')r4r5�_notsetrPr�r6rSr$r$r%rJ�s
z_lrucachenode.__init__cCst|_d|_d|_dS)zMark the node as emptied.Nr)r7rPr�r6rSr$r$r%�	markempty�sz_lrucachenode.markemptyN)rWrXrYrZr�rJr8r$r$r$r%r3}sr3c@s�eZdZdZd&dd�Zdd�Zdd�Zd	d
�Zdd�Zd'd
d�Z	dd�Z
dd�Zefdd�Z
d(dd�Zefdd�Zdd�Zd)dd�Zdd�Zd d!�Zd"d#�Zd$d%�ZdS)*�lrucachedictaDict that caches most recent accesses and sets.

    The dict consists of an actual backing dict - indexed by original
    key - and a doubly linked circular list defining the order of entries in
    the cache.

    The head node is the newest entry in the cache. If the cache is full,
    we recycle head.prev and make it the new head. Cache accesses result in
    the node being moved to before the existing head and being marked as the
    new head node.

    Items in the cache can be inserted with an optional "cost" value. This is
    simply an integer that is specified by the caller. The cache can be queried
    for the total cost of all items presently in the cache.

    The cache can also define a maximum cost. If a cache insertion would
    cause the total cost of the cache to go beyond the maximum cost limit,
    nodes will be evicted to make room for the new code. This can be used
    to e.g. set a max memory limit and associate an estimated bytes size
    cost to each item in the cache. By default, no maximum cost is enforced.
    rcCs*i|_t�|_d|_||_d|_||_dS)Nrr)�_cacher3�_headr^�capacity�	totalcost�maxcost)rFr�r>r$r$r%rJ�szlrucachedict.__init__cCs
t|j�SrK)rhr:rSr$r$r%�__len__�szlrucachedict.__len__cCs
||jvSrK)r:�rFrIr$r$r%�__contains__�szlrucachedict.__contains__ccs,|j}tt|j��D]}|jV|j}qdSrK)r;�rangerhr:rPr4)rFr	rr$r$r%rT�szlrucachedict.__iter__cCs|j|}|�|�|jSrK)r:�_movetoheadr�)rFrI�noder$r$r%rQ�s

zlrucachedict.__getitem__cCs�|j�|�}|durZ|j|j8_||_||_|j|7_|�|�|jrV|��dS|j|j	krp|�
�}n|jj}|j
tur�|j|j8_|j|j
=||_
||_||_|j|7_||j|<||_|jr�|��dS)z8Insert a new item in the cache with optional cost value.N)r:�getr=r6r�rCr>�_enforcecostlimitr^r<�_addcapacityr;r5rPr7)rFrIrlr6rDr$r$r%r"�s0




zlrucachedict.insertcCs|�||�dSrK)r"rkr$r$r%r�szlrucachedict.__setitem__cCs|�|�dSrK)�popr@r$r$r%�__delitem__�szlrucachedict.__delitem__cCsfz|j�|�}Wn ty0|tur(�|YS0|j}|j|j8_|��|�|�|j	|_
|SrK)r:rH�KeyErrorr7r�r=r6r8rCr4r;)rFrIr,rDr�r$r$r%rH�s

zlrucachedict.popNcCs(z|�|�WSty"|YS0dSrK)rQrJ)rFrIr,r$r$r%rE
szlrucachedict.getcCs8z|j|}|jWSty2|tur*�|YS0dS)z�Get the specified item without moving it to the head

        Unlike get(), this doesn't mutate the internal state. But be aware
        that it doesn't mean peek() is thread safe.
        N)r:r�rJr7)rFrIr,rDr$r$r%�peeks
zlrucachedict.peekcCs>|j}|jtur0|j|j8_|��|j}q|j��dSrK)	r;rPr7r=r6r8r4r:�clear)rFr	r$r$r%rLs
zlrucachedict.clearcCsx|p|j}|p|j}t||d�}|jj}|jturD||jurD|j}q(tt|j	��D] }|j
|j|j|jd�|j}qR|S)a8Create a new cache as a copy of the current one.

        By default, the new cache has the same capacity as the existing one.
        But, the cache capacity can be changed as part of performing the
        copy.

        Items in the copy have an insertion/access order matching this
        instance.
        )r>)r6)
r<r>r9r;r5rPr7rBrhr:r"r�r6)rFr<r>�resultr	rr$r$r%r(s

zlrucachedict.copycCs\|js
dS|jj}|jtur$|j}q|j|j}}|j|j=|j|j8_|��||fS)zuRemove the oldest item from the cache.

        Returns the (key, value) describing the removed cache entry.
        N)	r:r;r5rPr7r�r=r6r8)rFr	rPr�r$r$r%�	popoldestGs

zlrucachedict.popoldestcCsF|j}|j|j_|j|j_|j|_|jj|_||j_||j_||_dS)aqMark a node as the newest, making it the new head.

        When a node is accessed, it becomes the freshest entry in the LRU
        list, which is denoted by self._head.

        Visually, let's make ``N`` the new head node (* denotes head):

            previous/oldest <-> head <-> next/next newest

            ----<->--- A* ---<->-----
            |                       |
            E <-> D <-> N <-> C <-> B

        To:

            ----<->--- N* ---<->-----
            |                       |
            E <-> D <-> C <-> B <-> A

        This requires the following moves:

           C.next = D  (node.prev.next = node.next)
           D.prev = C  (node.next.prev = node.prev)
           E.next = N  (head.prev.next = node)
           N.prev = E  (node.prev = head.prev)
           N.next = A  (node.next = head)
           A.prev = N  (head.prev = node)
        N)r;r4r5)rFrD�headr$r$r%rCcs


zlrucachedict._movetoheadcCs:|j}t�}||j_|j|_||_||_|jd7_|S)zhAdd a node to the circular linked list.

        The new node is inserted before the head node.
        r)r;r3r5r4r^)rFrOrDr$r$r%rG�szlrucachedict._addcapacitycCs�t|�dks|j|jkrdSt|jd�}|jj}|jturD|j}q2t|�dkr�|j|kr�|j|j=|j|j	8_|�
�|j}qDdS)Nrg�?)rhr=r>rr;r5rPr7r:r6r8)rFZ
targetcostr	r$r$r%rF�s

zlrucachedict._enforcecostlimit)r)r)N)Nr)rWrXrYrZrJr?rArTrQr"rrIr7rHrErKrLrrNrCrGrFr$r$r$r%r9�s$
	
'
	
/r9cs>i�t����jjdkr*���fdd�}n���fdd�}|S)z+cache most recent results of function callsrcsH|�vr,t��dkr����=�|��|<n
��|���|��|S�N��rh�popleft�remover�r�rr
�orderr$r%r�s


zlrucachefunc.<locals>.fcsH|�vr,t��dkr����=�|��|<n
��|���|��|SrPrRrrUr$r%r�s


)�collections�dequerrrr$rUr%�lrucachefunc�s
rYc@s&eZdZdd�Zddd�Zdd�ZdS)	�
propertycachecCs||_|j|_dSrK)r
rWr�)rFr
r$r$r%rJ�szpropertycache.__init__NcCs|�|�}|�||�|SrK)r
�
cachevalue)rF�obj�typerMr$r$r%�__get__�s
zpropertycache.__get__cCs||j|j<dSrK)�__dict__r�)rFr\r�r$r$r%r[�szpropertycache.cachevalue)N)rWrXrYrJr^r[r$r$r$r%rZ�s
rZcCs t�|�}||jvr|j|=dS)z2clear a cached property value, if one has been setN)rr2r_)r\Zpropr$r$r%�clearcachedproperty�s

r`��ccs�dd�}g}d}|D]j}|�|�|t|�7}||kr||krj|d>}d||�>}||kr^|}||krj|}d�|�Vd}g}q|r�d�|�VdS)zrreturn no less than min bytes per chunk while data remains,
    doubling min after each chunk until it reaches maxcSs*|sdSd}|r"|dL}|d7}q|dS)Nrrr$)�xrr$r$r%�log2�s
zincreasingchunks.<locals>.log2rrr?N)r�rhr�)�sourcer�r�rdr�Zblen�chunkZnminr$r$r%�increasingchunks�s&	
rgcCsdS)NTr$�r�r$r$r%�alwayssricCsdS�NFr$rhr$r$r%�neversrkcs�fdd�}|S)a
disable garbage collector

    Python's garbage collector triggers a GC each time a certain number of
    container objects (the number being defined by gc.get_threshold()) are
    allocated even when marked not to be tracked by the collector. Tracking has
    no effect on when GCs are triggered, only on what objects the GC looks
    into. As a workaround, disable GC while building complex (huge)
    containers.

    This garbage collector issue have been fixed in 2.7. But it still affect
    CPython's performance.
    csBt��}t��z�|i|��W|r,t��Sn|r<t��0dSrK)�gc�	isenabled�disable�enable)r�r�Z	gcenabled�r
r$r%�wrapper-s��znogc.<locals>.wrapperr$�r
rqr$rpr%�nogcs	rscCs|SrKr$�rcr$r$r%r�;r?r�cCs�|st|�Stj�|�r\tj�|�dtj�|�dkrJtj�|t|��Sd�t|�|f�}t|�|�d�}}|�	�|�	�|r�|r�|d|dkr�|�
�|�
�q�|�	�tj�dgt
|�|�p�dS)aareturn the relative path from one place to another.
    root should use os.sep to separate directories
    n1 should use os.sep to separate directories
    n2 should use "/" to separate directories
    returns an os.sep-separated path.

    If n1 is a relative path, it's assumed it's
    relative to root.
    n2 should always be relative to root.
    r�/rf�..r)�	localpathr �path�isabs�
splitdriver��pconvert�	splitpathr�reverserHr�osseprh)�rootZn1Zn2�a�br$r$r%�pathto>s 
r�cs��fdd�}|S)z5wrap a function with code to check for calling errorscsJz�|i|��WStyDtt�t��d���kr>tj��Yn0dS)Nr�)�	TypeErrorrh�	traceback�
extract_tbr4�exc_infor
ZSignatureError)r�r���depthr
r$r%�check]szchecksignature.<locals>.checkr$)r
r�r�r$r�r%�checksignatureZsr�>
sext2stmpfssNTFSsext4sufssext3sxfsshfssreiserfssjfsszfssapfssbtrfsc
Csd}tj�|�r*|r"|o t�|�}t|�|rx|rxzttj�|��}	Wnty\d}	Yn0|	t	vrx|durt|�d}|r�z&t
||�|dur�d}
t�|
��WdSt
tfy�}z&|jtjkr�|dur�|�WYd}~n
d}~00tj�|��r t�t�|�|�|du�rd}
t�|
��n�z�t�||�|�rBt�||�nTt�||�|�r�|j�r�t�|�}|�|��r�|jtjdd@}
t�||
|
f�|du�r�t|dd��}|�|�Wd�n1�s�0YWn8tj�y}zt�t� |���WYd}~n
d}~00dS)	afcopy a file, preserving mode and optionally other stat info like
    atime/mtime

    checkambig argument is used with filestat, and is useful only if
    destination file is guarded by any lock (e.g. repo.lock or
    repo.wlock).

    copystat and checkambig should be exclusive.

    nb_bytes: if set only copy the first `nb_bytes` of the source file.
    NFz7the `nb_bytes` argument is incompatible with `hardlink`z"cannot use `nb_bytes` on a symlinkr��zr+)r�)!r rx�lexists�filestat�frompath�unlink�	getfstype�dirname�OSError�_hardlinkfswhitelist�oslinkr
r�IOError�errno�EEXIST�islink�symlink�readlink�shutil�copyfile�copystat�copymode�stat�isambig�ST_MTIME�utimer	r��ErrorrCrZforcebytestr)rr��hardlinkr��
checkambigZnb_bytesZno_hardlink_cbZcheck_fs_hardlink�oldstatZfstyper
�exc�newstat�advancedr�instr$r$r%r�zs\




�
.r�c
s`d}��fdd�}tj�|�r��durFt�|�jt�tj�|��jk�|�t�|�t|�D]>\}}tj�||�}tj�||�}	t	||	���\�}
||
7}q^n��dur�t�tj�|��jt�tj�|��jk�|���r6zt
||�WnHttf�y2}z*|j
t
jk�rd�t�||�WYd}~n
d}~00nt�||�|d7}��rX����|fS)z2Copy a directory tree using hardlinks if possible.rcs�r�rtd�ntd��_dS)Nslinkingscopying)rDZtopicr$�r��progressr$r%�settopic�szcopyfiles.<locals>.settopicNFr)r rx�isdirr��st_devr��mkdir�listdirr��	copyfilesr�r�r�r�r�r�rZ	increment)r�dstr�r�Znumr�r��kind�srcname�dstnamer	r�r$r�r%r��s>�
��$r�>snulscom4scom7scom6sauxslpt4scom2slpt3sprnscom5scom9slpt6sconscom8slpt5scom1slpt2slpt1slpt8slpt7slpt9scom3s:*?"<>|cCs�|�d�rtd�Sd|vr"td�S|�dd��d�D]�}|s>q4t|�D]F}|tvrftd�|St|�dkrFtd�t�|�SqF|�d	�d
}|r�|�	�t
vr�td�|S|dd�}|d
vr4|dvr4td�|Sq4dS)aUCheck that the base-relative path is a valid filename on Windows.
    Returns None if the path is ok, or a UI string describing the problem.

    >>> checkwinfilename(b"just/a/normal/path")
    >>> checkwinfilename(b"foo/bar/con.xml")
    "filename contains 'con', which is reserved on Windows"
    >>> checkwinfilename(b"foo/con.xml/bar")
    "filename contains 'con', which is reserved on Windows"
    >>> checkwinfilename(b"foo/bar/xml.con")
    >>> checkwinfilename(b"foo/bar/AUX/bla.txt")
    "filename contains 'AUX', which is reserved on Windows"
    >>> checkwinfilename(b"foo/bar/bla:.txt")
    "filename contains ':', which is reserved on Windows"
    >>> checkwinfilename(b"foo/bar/b\07la.txt")
    "filename contains '\\x07', which is invalid on Windows"
    >>> checkwinfilename(b"foo/bar/bla ")
    "filename ends with ' ', which is not allowed on Windows"
    >>> checkwinfilename(b"../bar")
    >>> checkwinfilename(b"foo\\")
    "filename ends with '\\', which is invalid on Windows"
    >>> checkwinfilename(b"foo\\/bar")
    "directory name ends with '\\', which is invalid on Windows"
    �\s3filename ends with '\', which is invalid on Windowss\/s9directory name ends with '\', which is invalid on Windowsrus4filename contains '%s', which is reserved on Windows�s3filename contains '%s', which is invalid on WindowsrrrfNs. rvs8filename ends with '%s', which is not allowed on Windows)�endswithrD�replacer�_filenamebytestr�_winreservedchars�ordrr��lower�_winreservednames)rxr	�c�base�tr$r$r%�checkwinfilenamesF
���
�������r��perf_counterc
Cs�zt�||�WSty@}z|jtjkr,�WYd}~nd}~0tyPYn0tjtjBtjBt	tdd�B}t�
||�}t�||�t�|�dS)z�Create a lock file atomically if possible

    This may leave a stale lock file if symlink isn't supported and signal
    interrupt is enabled.
    NZO_BINARYr)
r r�r�r�r��AttributeError�O_CREAT�O_WRONLY�O_EXCLrr	r�r�)�info�pathname�whyr�Zldr$r$r%�makelock]sr�c
Cs�z
t|�WStyB}z |jtjtjfvr.�WYd}~nd}~0tyRYn0t|d��}|��Wd�S1s|0YdS�N�rb)r�r�r��EINVALZENOSYSr��	posixfilerg)r�r�r�r$r$r%�readlockqs
r�cCs4zt�|���WSty.t�|j�YS0dS)z1stat file object that may not have fileno method.N)r r�r�r�r�r�r�r$r$r%r�~sr�cCs�t�|�}tj�|�\}}|��}||kr>|��}||kr>dStj�||�}zt�|�}||krfWdSWdSty~YdS0dS)z�
    Return true if the given path is on a case-sensitive filesystem

    Requires a path (like /foo/.hg) ending with a foldable final
    directory component.
    TFN)r �lstatrxr�upperr�r�r�)rx�s1�dr��b2Zp2�s2r$r$r%�fscasesensitive�s

r�cCs|SrKr$rtr$r$r%r��r?c@s*eZdZdd�Zd	dd�Zedd��ZdS)
�_recCsrd}d}ztt�||��aWnPty2daYn<tylt�|�}t�|�}tt�||��atjaYn0dS)Ns\[([^\[]+)\]s[ui]F)	r�re2r�_re2r�r�rr2�
_re2_input)rFZ
check_patternZcheck_inputr$r$r%�	_checkre2�s

z
_re._checkre2rcCs�tdur|��trt|tjtjB@dkrt|tj@r<d|}|tj@rNd|}zt�t|��WStjyrYn0t�||�S)z�Compile a regular expression, using re2 if possible

        For best performance, use only re2-compatible regexp features. The
        only flags from the re module that are re2-compatible are
        IGNORECASE and MULTILINE.Nrs(?i)s(?m))	r�r�r�
IGNORECASE�	MULTILINEr��compiler�r
)rF�patr�r$r$r%r��s

z_re.compilecCs$tdur|��trtjStjSdS)z�Return the version of escape corresponding to self.compile.

        This is imperfect because whether re2 or re is used for a particular
        function depends on the flags, etc, but it's the best we can do.
        N)r�r�r��escaperrSr$r$r%r��s
z
_re.escapeN)r)rWrXrYr�r�rZr�r$r$r$r%r��s
r�cCs�dd�}tj}tjr|tj}|�dd�t�d||f�}tj�|�}g}|�	|�D]x\}}|rn|�
|�qV|tvr�||�t|<t|}	|	�|�}
|
s�||�t|<}	|	�|�}
|�
|
p�|�tj�
||�}qVd�
|�S)a4Get name in the case stored in the filesystem

    The name should be relative to root, and be normcase-ed for efficiency.

    Note that this function is unnecessary, and should not be
    called, for case-sensitive filesystems (simply because it's expensive).

    The root should be normcase-ed, too.
    cSsdd�t�|�D�S)NcSsi|]}t|�|�qSr$)�normcase)�.0r	r$r$r%�
<dictcomp>�r?z9fspath.<locals>._makefspathcacheentry.<locals>.<dictcomp>)r r�)�dirr$r$r%�_makefspathcacheentry�sz%fspath.<locals>._makefspathcacheentryr�s\\s([^%s]+)|([%s]+)r?)rr~�osaltsepr�rr�r rx�normpath�findallr��_fspathcacherEr�)r�rr��seps�patternr�rM�part�sep�contents�foundr$r$r%�fspath�s,



r�cCs�d\}}}�zfz�tjdtj�|�dtj�|�d�\}}t�|�d|dd�}t||�t|�}t	|�dkWW|dur�|��||fD].}z|dur�t�
|�Wq�ty�Yq�0q�St�yYW|dur�|��||fD]2}z|du�rt�
|�Wq�t�yYq�0q�d	S0W|du�r4|��||fD]4}z|du�rVt�
|�Wnt�ylYn0�q<nR|du�r�|��||fD]4}z|du�r�t�
|�Wnt�y�Yn0�q�0dS)
z5check whether hardlink count reporting works properly)NNN�.%s-s1~��prefix�suffixr�s%s2~N���rF)r�mkstempr rx�basenamer�r�r�r��nlinksr�r�)Ztestfile�f1�f2r�r�rr$r$r%�
checknlink	s`

�


�
�

�

r�cCs"t|�tj�ptjo|�tj��S)z)Check path ends with os.sep or os.altsep.)rr�rr~r��rxr$r$r%�endswithsep6	s

�r�cCs|�tj�S)z�Split path by os.sep.
    Note that this function does not use os.altsep because this is
    an alternative of simple "xxx.split(os.sep)".
    It is recommended to use os.path.normpath() before using this
    function if need.)rrr~r�r$r$r%r|@	sr|cCstj�|�\}}tjd|d|d�\}}t�|�t||||�|rH|Sz�zt|d�}WnVty�}	z>|	j	t	j
kr�|WYd}	~	WSt|	dd�s�||	_�WYd}	~	n
d}	~	00t|d�}
t
|�D]}|
�|�q�|��|
��Wn2zt�|�Wnt�yYn0�Yn0|S)aCreate a temporary file with the same contents from name

    The permission bits are copied from the original file.

    If the temporary file is going to be truncated immediately, you
    can use emptyok=True as an optimization.

    Returns the name of the temporary file.
    r��~r�r�N�filename�wb)r rxrrr�r�r�r�r�r��ENOENTrr�
filechunkiterr�r�r�)r��emptyok�
createmode�enforcewritabler�r�r�ZtempZifpr�Zofprfr$r$r%�
mktempcopyJ	s6


rc@sVeZdZdZdd�Zedd��Zedd��Zej	Z	dd	�Z
d
d�Zdd
�Zdd�Z
dS)r�z�help to exactly detect change of a file

    'stat' attribute is result of 'os.stat()' if specified 'path'
    exists. Otherwise, it is None. This can avoid preparative
    'exists()' examination on client side of this class.
    cCs
||_dSrK)r�)rFr�r$r$r%rJ}	szfilestat.__init__c
CsNzt�|�}Wn6tyD}z|jtjkr,�d}WYd}~n
d}~00||�SrK)r r�r�r�r)rwrxr��errr$r$r%r��	szfilestat.frompathcCst�|���}||�SrK)r r�r�)rwr�r�r$r$r%�fromfp�	szfilestat.fromfpcCs�zB|jj|jjko@|jtj|jtjko@|jtj|jtjkWStyTYn0z|jduoj|jduWSty�YdS0dSrj)r�r��ST_CTIMEr�r��rF�oldr$r$r%�__eq__�	s��zfilestat.__eq__cCs4z|jtj|jtjkWSty.YdS0dS)aExamine whether new (= self) stat is ambiguous against old one

        "S[N]" below means stat of a file at N-th change:

        - S[n-1].ctime  < S[n].ctime: can detect change of a file
        - S[n-1].ctime == S[n].ctime
          - S[n-1].ctime  < S[n].mtime: means natural advancing (*1)
          - S[n-1].ctime == S[n].mtime: is ambiguous (*2)
          - S[n-1].ctime  > S[n].mtime: never occurs naturally (don't care)
        - S[n-1].ctime  > S[n].ctime: never occurs naturally (don't care)

        Case (*2) above means that a file was changed twice or more at
        same time in sec (= S[n-1].ctime), and comparison of timestamp
        is ambiguous.

        Base idea to avoid such ambiguity is "advance mtime 1 sec, if
        timestamp is ambiguous".

        But advancing mtime only in case (*2) doesn't work as
        expected, because naturally advanced S[n].mtime in case (*1)
        might be equal to manually advanced S[n-1 or earlier].mtime.

        Therefore, all "S[n-1].ctime == S[n].ctime" cases should be
        treated as ambiguous regardless of mtime, to avoid overlooking
        by confliction between such mtime.

        Advancing mtime "if isambig(oldstat)" ensures "S[n-1].mtime !=
        S[n].mtime", even if size of a file isn't changed.
        FN)r�rr�rr$r$r%r��	szfilestat.isambigc
Csn|jtjdd@}zt�|||f�Wn@tyh}z(|jtjkrRWYd}~dS�WYd}~n
d}~00dS)aLChange file stat of specified path to avoid ambiguity

        'old' should be previous filestat of 'path'.

        This skips avoiding ambiguity, if a process doesn't have
        appropriate privileges for 'path'. This returns False in this
        case.

        Otherwise, this returns True, as "ambiguity is avoided".
        rr�NFT)r�r�r r�r�r��EPERM)rFrxr
r�r�r$r$r%�
avoidambig�	szfilestat.avoidambigcCs
||kSrKr$)rF�otherr$r$r%�__ne__�	szfilestat.__ne__N)rWrXrYrZrJ�classmethodr�r
r��__hash__rr�rrr$r$r$r%r�u	s
	
#r�c@sBeZdZdZddd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dS)�atomictempfileawritable file object that atomically updates a file

    All writes will go to a temporary copy of the original file. Call
    close() when you are done writing, and atomictempfile will rename
    the temporary copy to the original name, making the changes
    visible. If the object is destroyed without being closed, all your
    writes are discarded.

    checkambig argument of constructor is used with filestat, and is
    useful only if target file is guarded by any lock (e.g. repo.lock
    or repo.wlock).
    �w+bNFcCsj||_t|d|v|d|vd�|_t|j|�|_||_|jj|_|jj|_|jj|_|jj	|_	|jj
|_
dS)N�w)rrr)�_atomictempfile__namer�	_tempnamer��_fp�_checkambigrgr�r�r�r�)rFr�r�rr�r$r$r%rJ�	s�



zatomictempfile.__init__cCs�|jjs�|j��t|j�}|jo*t�|�}|r||jr|t	|j
|�t�|�}|�|�r�|jtjdd@}t
�|||f�nt	|j
|�dS)Nrr�)rr�r�rwrrr�r�r��renamerr�r�r r�)rFrr�r�r�r$r$r%r�
s




zatomictempfile.closecCs:|jjs6zt�|j�Wnty*Yn0|j��dSrK)rr�r r�rr�r�rSr$r$r%�discard
szatomictempfile.discardcCst|d�r|��dS)Nr)�safehasattrrrSr$r$r%�__del__
s
zatomictempfile.__del__cCs|SrKr$rSr$r$r%r)
szatomictempfile.__enter__cCs|dur|��n|��dSrK)rr�)rF�exctypeZexcvaluer�r$r$r%r+
s
zatomictempfile.__exit__)rNF)
rWrXrYrZrJr�rrr)r+r$r$r$r%r�	s
rcCsF|rt|�nt|�|rBzttj�|��Wnty@Yn0dS)z.unlink and remove the directory if it is emptyN)�	tryunlinkr��
removedirsr rxr�r�)rZ
ignoremissing�rmdirr$r$r%�
unlinkpath%
s
r$c
CsDzt|�Wn2ty>}z|jtjkr*�WYd}~n
d}~00dS)z1Attempt to remove a file, ignoring ENOENT errors.N)r�r�r�r)r�er$r$r%r!4
s
r!c
Cs�zt||�Wn�ty�}z�|jtjkr8WYd}~dS|jtjksH|sJ�tj�t|��}||krd�t	|||�zt||�WnJty�}z2|jtjkr�WYd}~WYd}~dS�WYd}~n
d}~00WYd}~n
d}~00|dur�t�
||�dS)z�recursive directory creation with parent mode inheritance

    Newly created directories are marked as "not to be indexed by
    the content indexing service", if ``notindexed`` is specified
    for "write" mode access.
    N)�makedirr�r�r�rr rxr��abspath�makedirs�chmod)r�r�Z
notindexedr	�parentr$r$r%r(>
s&.r(cCs6t|d��}|��Wd�S1s(0YdSr�)r	rg)rxr�r$r$r%�readfile\
sr+cCs8t|d��}|�|�Wd�n1s*0YdS)Nr�r	r��rx�textr�r$r$r%�	writefileb
sr/cCs8t|d��}|�|�Wd�n1s*0YdS)Nsabr,r-r$r$r%�
appendfileh
sr0c@s"eZdZdZdd�Zddd�ZdS)�chunkbufferzoAllow arbitrary sized chunks of data to be efficiently read from an
    iterator over chunks of arbitrary size.cCs&dd�}||�|_t��|_d|_dS)z?in_iter is the iterator that's iterating over the input chunks.cssN|D]D}t|�dkrBd}|t|�krH|d}|||�V|}qq|VqdS)N�r��rh)�chunksrf�pos�endr$r$r%�splitbigu
sz&chunkbuffer.__init__.<locals>.splitbigrN)rRrWrX�_queue�_chunkoffset)rFZin_iterr8r$r$r%rJr
s

zchunkbuffer.__init__Nc
Cs|durd�|j�S|}g}|j}|dk�r|sjd}|jD]&}|�|�|t|�8}|dkr:qbq:|sj�q|d}t|�}|j}|dkr�||kr�||8}|��|�|�q"||}	||	kr�||	8}|��|�||d��d|_q"|�||||��|j|7_||	8}q"d�|�S)z�Read L bytes of data from the iterator of chunks of data.
        Returns less than L bytes if the iterator runs dry.

        If size parameter is omitted, read everythingNr?rr3)r�rRr9r�rhr:rS)
rF�l�leftr�Zqueue�targetrfZchunklroZchunkremainingr$r$r%rg�
sB




zchunkbuffer.read)N)rWrXrYrZrJrgr$r$r$r%r1n
sr1�ccsH|dur|}n
t||�}|o$|�|�}|s,qD|r<|t|�8}|VqdS)aYCreate a generator that produces the data in the file size
    (default 131072) bytes at a time, up to optional limit (default is
    to read all data).  Chunks may be less than size bytes if the
    chunk is the last chunk in the file, or the file is a socket or
    some other type of file that sometimes reads less data than is
    requested.N)r�rgrh)rrer��nbytesrHr$r$r%r�
s

rc@s*eZdZdZdd�Zd
dd�Zdd�Zd	S)�cappedreadera�A file object proxy that allows reading up to N bytes.

    Given a source file object, instances of this type allow reading up to
    N bytes from that source file object. Attempts to read past the allowed
    limit are treated as EOF.

    It is assumed that I/O is not performed on the original file object
    in addition to I/O that is performed by this instance. If there is,
    state tracking will get out of sync and unexpected results will ensue.
    cCs||_||_dS)z,Allow reading up to <limit> bytes from <fh>.N)r]�_left)rFrdr�r$r$r%rJ�
szcappedreader.__init__rfcCsB|js
dS|dkr|j}|j�t||j��}|jt|�8_|S)Nr?r)rAr]rgr�rh)rFr	rMr$r$r%rg�
szcappedreader.readcCs2|�t|��}|durdS||dt|��<t|�Sr')rgrh)rFr�r�r$r$r%r��
s
zcappedreader.readintoN)rf)rWrXrYrZrJrgr�r$r$r$r%r@�
s

r@cs�fdd�}|S)z@return a function that renders a readable count of some quantitycsD�D].\}}}t|�||kr||t|�Sq�dd|S)Nrfr�)�abs�float)�countZ
multiplierZdivisor�format��	unittabler$r%�goszunitcountfn.<locals>.gor$)rGrHr$rFr%�unitcountfn�
srIcCs<||dkrt�td���|dkr0t�td���|d|fS)a�Check that linerange <fromline>:<toline> makes sense and return a
    0-based range.

    >>> processlinerange(10, 20)
    (9, 20)
    >>> processlinerange(2, 1)
    Traceback (most recent call last):
        ...
    ParseError: line range must be positive
    >>> processlinerange(0, 5)
    Traceback (most recent call last):
        ...
    ParseError: fromline must be strictly positive
    rsline range must be positivers"fromline must be strictly positive)r
�
ParseErrorrD)ZfromlineZtoliner$r$r%�processlinerange
s
rK�d�@s%.0f GB�
s%.1f GBs%.2f GBr2s%.0f MBs%.1f MBs%.2f MBs%.0f KBs%.1f KBs%.2f KBs
%.0f bytesc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�transformingwriterz3Writable file wrapper to transform data by functioncCs||_||_dSrK)r�_encode)rFr��encoder$r$r%rJ2sztransformingwriter.__init__cCs|j��dSrK)rr�rSr$r$r%r�6sztransformingwriter.closecCs|j��dSrK)rr6rSr$r$r%r69sztransformingwriter.flushcCs|j�|�|��SrK)rr�rP)rFrMr$r$r%r�<sztransformingwriter.writeN)rWrXrYrZrJr�r6r�r$r$r$r%rO/s
rOs\r*\ncCst�d|�S)Nr���_eolre�sub�rHr$r$r%�tolfFsrVcCst�d|�S)N�
rRrUr$r$r%�tocrlfKsrXcCs
t|t�SrK)rOrXr�r$r$r%�_crlfwriterPsrYrWsCPython)rrcCs>d}t|�tur&t�t�|���j�}|r.|St|j	d�SdS)NTr?)
r]�filer��S_ISREGr r�r��st_moderRr�)r�Zfastpathr$r$r%�iterfilezsr]cCs|SrKr$r�r$r$r%r]�sccs"|D]}|��D]
}|VqqdSrK)r�)�iteratorrfr�r$r$r%�	iterlines�sr_cCstj�tj�|��SrK)r rx�
expanduser�
expandvarsr�r$r$r%�
expandpath�srbcsx�p
dd��d�����}|rP|d|7}t|�dkrD|dd�}n|}|�|<t�d||f�}|���fdd�|�S)a�Return the result of interpolating items in the mapping into string s.

    prefix is a single character string, or a two character string with
    a backslash as the first character if the prefix needs to be escaped in
    a regular expression.

    fn is an optional function that will be applied to the replacement text
    just before replacement.

    escape_prefix is an optional flag that allows using doubled prefix for
    its escaping.
    cSs|SrKr$rUr$r$r%r��r?zinterpolate.<locals>.<lambda>�|rNs%s(%s)cs��|��dd��S)Nr)rrt�r��mappingr$r%r��r?)r�rbrhrr�rT)r�rerHr�Z
escape_prefix�patternsZprefix_char�rr$rdr%�interpolate�s
rhg@�@s%.0f ss%.1f ss%.2f ss%.3f sg����MbP?s%.1f mss%.2f mss%.3f msg���ư>s%.1f uss%.2f uss%.3f usg��&�.>s%.1f nss%.2f nss%.3f nsc@sPeZdZdZeje�dd��d�Zejdd�Zejdd�Z	dd�Z
e�e
�Z
d	S)
�timedcmstatszFStats information produced by the timedcm context manager on entering.cCst�SrK)�timerr$r$r$r%r��r?ztimedcmstats.<lambda>)r,rrcCs|jrt|j�SdS)Ns	<unknown>)�elapsed�	timecountrSr$r$r%�	__bytes__�sztimedcmstats.__bytes__N)rWrXrYrZrZibZFactory�startrkr�rmrZ	strmethod�__str__r$r$r$r%ri�sric	gs�tjd7_ttjd�}zXtj|g|�R��|VWd�n1sJ0YWt�|j|_tjd8_nt�|j|_tjd8_0dS)z�A context manager that produces timing information for a given context.

    On entering a timedcmstats instance is produced.

    This context manager is reentrant.

    r)r�N)�timedcm�_nestedrir�logrjrnrk)Z	whencefmtZ
whenceargsZtiming_statsr$r$r%rp�s
&�rpcs�fdd�}|S)z�Report the execution time of a function call to stderr.

    During development, use as a decorator when you need to measure
    the cost of a function, e.g. as follows:

    @util.timed
    def foo(a, b, c):
        pass
    csntt��j���}�|i|��}Wd�n1s40Ytj}|�dd|jdt��j�|f�|S)Ns	%s%s: %s
� r�)rpr�bytestrrWrr5r�r�)r�r�Z
time_statsrMr5rpr$r%rq�s,
���ztimed.<locals>.wrapperr$rrr$rpr%�timed�sru))�mr2)�kra)�grM)skbra)smbr2)sgbrM)�brcCs||����}zFtD]6\}}|�|�rtt|dt|���|�WSqt|�WStyvt�	t
d�|��Yn0dS)z�Convert a space specifier to a byte count.

    >>> sizetoint(b'30')
    30
    >>> sizetoint(b'2.2kb')
    2252
    >>> sizetoint(b'6M')
    6291456
    Nscouldn't parse size: %s)�stripr��
_sizeunitsr�rrCrhr�r
rJrD)rHr�rI�ur$r$r%�	sizetoints
&
r}c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�hooksz�A collection of hook functions that can be used to extend a
    function's behavior. Hooks are called in lexicographic order,
    based on the names of their sources.cCs
g|_dSrK)�_hooksrSr$r$r%rJ-szhooks.__init__cCs|j�||f�dSrK)rr�)rFre�hookr$r$r%�add0sz	hooks.addcGs8|jjdd�d�g}|jD]\}}|�||��q|S)NcSs|dSr'r$rtr$r$r%r�4r?z hooks.__call__.<locals>.<lambda>)rP)r�sortr�)rFr��resultsrer�r$r$r%�__call__3s
zhooks.__call__N)rWrXrYrZrJr�r�r$r$r$r%r~(sr~� %-*s in %s
�%s:%dc#s|�fdd�t��d|d�D�|d�}|rxtdd�|D��}|D].\}}|durf|||fVqH||||fVqHdS)a�Yields lines for a nicely formatted stacktrace.
    Skips the 'skip' last entries, then return the last 'depth' entries.
    Each file+linenumber is formatted according to fileline.
    Each line is formatted according to line.
    If line is None, it yields:
      length of longest filepath+line number,
      filepath+linenumber,
      function

    Not be used in production code but very convenient while developing.
    cs0g|](\}}}}�t�|�|ft�|�f�qSr$)rZsysbytes)r�r�Zlnr
Z_text��fileliner$r%�
<listcomp>Gs
�z"getstackframes.<locals>.<listcomp>Nrcss|]}t|d�VqdS)rNr4)r��entryr$r$r%�	<genexpr>Lr?z!getstackframes.<locals>.<genexpr>)r��
extract_stackr�)�skipr�r�r��entriesZfnmaxZfnlnr
r$r�r%�getstackframes;s
��r�s
stacktracer?cCsR|r|��|�d||��f�t|d|d�D]}|�||�q2|��dS)aWWrites a message to f (stderr) with a nicely formatted stacktrace.
    Skips the 'skip' entries closest to the call, then show 'depth' entries.
    By default it will flush stdout first.
    It can be used everywhere and intentionally does not require an ui object.
    Not be used in production code but very convenient while developing.
    s	%s%s at:
r)r�N)r6r��rstripr�)r7r�rZotherfr�r�r�r$r$r%�debugstacktraceTsr�cCsh|durt�}d||f}||vr.||vr.|St�d�D]*}d|||f}||vr8||vr8|Sq8dS)a�
    Generate a name that it is safe to rename f to in the given context.

    f:      filename to rename
    tag:    a string tag that will be included in the new name
    ctx:    a context, in which the new name must not exist
    others: a set of other filenames that the new name must not be in

    Returns a file name of the form oldname~tag[~number] which does not exist
    in the provided context and is not in the set of other names.
    Ns%s~%srs%s~%s~%s)�set�	itertoolsrD)r�tag�ctxZothersr�r	r$r$r%�safenamensr�cCs4|�|�}t|�|kr0t�td�t|�|f��|S)z=read n bytes from stream.read and abort if less was availables5stream ended unexpectedly (got %d bytes, expected %d))rgrhr
rCrD)�streamr	rHr$r$r%�readexactly�s

��r�cCsn|dkrt�d|��|d@}|dL}g}|rT|�t�d|B��|d@}|dL}q*|�t�|��d�|�S)aiEncode an unsigned integer value to a varint.

    A varint is a variable length integer of 1 or more bytes. Each byte
    except the last has the most significant bit set. The lower 7 bits of
    each byte store the 2's complement representation, least significant group
    first.

    >>> uvarintencode(0)
    '\x00'
    >>> uvarintencode(1)
    '\x01'
    >>> uvarintencode(127)
    '\x7f'
    >>> uvarintencode(1337)
    '\xb9\n'
    >>> uvarintencode(65536)
    '\x80\x80\x04'
    >>> uvarintencode(-1)
    Traceback (most recent call last):
        ...
    ProgrammingError: negative value for uvarint: -1
    rsnegative value for uvarint: %d���r?)r
rr�rZbytechrr�)r�r)�bytesr$r$r%�
uvarintencode�s
r�cCs@d}d}tt|d��}||d@|>O}|d@s2|S|d7}qdS)a�Decode an unsigned variable length integer from a stream.

    The passed argument is anything that has a ``.read(N)`` method.

    >>> try:
    ...     from StringIO import StringIO as BytesIO
    ... except ImportError:
    ...     from io import BytesIO
    >>> uvarintdecodestream(BytesIO(b'\x00'))
    0
    >>> uvarintdecodestream(BytesIO(b'\x01'))
    1
    >>> uvarintdecodestream(BytesIO(b'\x7f'))
    127
    >>> uvarintdecodestream(BytesIO(b'\xb9\n'))
    1337
    >>> uvarintdecodestream(BytesIO(b'\x80\x80\x04'))
    65536
    >>> uvarintdecodestream(BytesIO(b'\x80'))
    Traceback (most recent call last):
        ...
    Abort: stream ended unexpectedly (got 0 bytes, expected 1)
    rrr�r�r�N)r�r�)rdrM�shiftZbyter$r$r%�uvarintdecodestream�sr�c
cstt�tjd�}|dkrjz@zt�tjd�Wntjy>Yn0dVWt�tj|�qpt�tj|�0ndVdS)N�Cr-)�locale�	setlocale�LC_CTYPEr�)�oldlocr$r$r%�
with_lc_ctype�s"r�cs�tj�d�rpddlm�m�ddlm}m}m	}m
}G��fdd�d|�}|�}||�|_|j�
||��|jSz*t�tjd�}t�tjd�}||WSty�Ynty�Yn0d	S)
z�Provide an estimate for the available system memory in Bytes.

    If no estimate can be provided on the platform, returns None.
    swinr)�c_long�c_ulonglong)�	Structure�byref�sizeof�windllc
sFeZdZd�fd�fd�fd�fd�fd�fd�fd�fd	�fg	Zd
S)z'_estimatememory.<locals>.MEMORYSTATUSEX�dwLengthZdwMemoryLoadZullTotalPhys�ullAvailPhysZullTotalPageFileZullAvailPageFileZullTotalVirtualZullAvailVirtualZullExtendedVirtualN)rWrXrYZ_fields_r$�ZDWORDZ	DWORDLONGr$r%�MEMORYSTATUSEX
s�r��SC_PAGE_SIZE�
SC_PHYS_PAGESN)rZsysplatform�
startswithZctypesr�r�Zctypes.wintypesr�r�r�r�r�Zkernel32ZGlobalMemoryStatusExr�r �sysconf�
sysconf_namesr�rJ)r�r�r�r�r�rcZpagesizeZpagesr$r�r%�_estimatememory�s 


r�)r)rN)N)TTFT)TTTFT)Nr�)N)N)rarb)r)FFFNNT)NN)FNF)FT)NF)r>N)NF)rr�r�r)N(rZZ
__future__rrr,rW�
contextlibr�rlZhashlibr�r�r�r r"Z
pyplatform�rerr�r�r4�timer�r0rDrZ
thirdpartyrrrrr	r
Zhgdemandimportrr-rr
rrrZutilsrrrr�
TYPE_CHECKING�typingrrrrZ	importmodrrZ	b85decodeZ	b85encodeZ	cookielibZhttplib�picklerZsocketserverZbytesioZstringioZ	xmlrpclibZ
httpserverZurlerrZurlreqrtr�rrrrDr'ZbindunixsocketZ	cachestatZ	checkexecZ	checklinkr�ZexpandglobsZgetfsmountpointr�Zget_passwordZgroupmembersZ	groupnameZisexecZisownerr�rwZ	lookupregr&r�r�r�ZnormcasespecZnormcasefallbackZ
openhardlinksr�Zparsepatchoutputr{Zpollr�r�rr"Z
samedevice�samefile�samestatZsetflagsrrZ
statisexecZ
statislinkr!r��usernamer&ZcompenginesZ
SERVERROLEZ
CLIENTROLEZrecvfdsr�r�r7r+r�environrEr/�filterwarningsr3Zispy3r:Zmd5Zsha1Zsha512rBrUrIr>r\rp�	NameErrorr�rqr�rsrtr�r�r�r�r�r�r�r8rrr�OrderedDictrr`r$r&r'�contextmanagerr0r2r3r9rYrZr`rgrirkrsr#r�r�r�r�r�r�r�r�rjZcheckosfilenameZclockr�r�r�r�r�r�r�r�r�r�r�r�r�r|rr�rr$r!r(r+r/r0r1rr@rIrKZ	bytecountrOr�rSrVrXrYZ	oslinesepZtonativeeolZ
fromnativeeolZnativeeolwriter�identityZpython_implementation�version_infor]r_rbrhrlrHrirprqrur{r}r~r�r5�stdoutr�r�r�r�r�r�r�r�r$r$r$r%�<module>
sZ 



���
�0%n
3*{%e�
�

W'.!�
P->

7-"

+jF
S'�


�
�
%-


Youez - 2016 - github.com/yon3zu
LinuXploit