HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/osutils.cpython-39.pyc
a

�*�^9Y�
@s�	ddlmZddlZddlZddlZddlZddlZddlZddlZddl	m	Z	e	e
�d�ddlmZm
Z
ddlmZmZddlZddlmZmZeed	d�Zeed
d�Zeedd�ZGdd
�d
ej�Zdd�Zdd�Zdd�Zdd�Zdd�Z da!dd�Z"dZ#dd�Z$dde#dd d!d"d#iZ%d$d%�Z&eej'd&d�Z(e(du�rFd'd&�Z(d(d)�Z)d*d+�Z*d,d-�Z+d.d/�Z,d0d1�Z-d2d3�Z.d4d5�Z/d6d7�Z0d8d9�Z1d:d;�Z2d<d=�Z3d>d?�Z4d@dA�Z5dBdC�Z6dDdE�Z7dFdG�Z8dHdI�Z9ej:dJk�r�ej;Z<nej=Z<e9ej>�Z>e*Z?e+Z@ej'jAZBe,ZCe-ZDe.ZEe/ZFe<Z;ej'jGZGej'jHZHej'jIZIej'jJZJejKZKejLZLdKdL�ZMdZNejOdMk�r�e1Z?e2Z@e3ZBe4ZCe5Z;e6ZPe9e7�Z>zddNlmQZQWneR�y�Yn0eQjKZKeQjLZLeQjMZMdOZNdPdQ�ZSdReSfdSdT�ZTeeUde�ZeUjVZDeUjWZEeUjXZFnejOdUk�r�e8Z;�dFdVdW�ZYdXdY�ZZdZd[�Z[d\d]�Z\d^d_�Z]d`da�Z^dbdc�Z_ddde�Z`�dGdidj�Za�dHdkdl�Zb�dIdmdn�Zce�rtdodp�Zdndqdp�Zddrds�Zedtdu�Zfdvdw�Zgefdxdy�Zhefdzd{�Zid|d}�Zjd~d�Zk�dJd�d��Zlgd��Zmd�d��emD�Zn�dKd�d��ZoiZpdepfd�d��Zq�dLd�d��Zrd�d��Zsd�d��Ztd�d��Zud�d��ZvejwZxexjyd�k�rdzexd�Wnez�ybd�d��ZxYn0d�Z{d�d��Z|d�d��Z}d�d��Z~d�d��ZgZ�d�d��Z�d�d��Z�zdd�l�m�Z�Wn:eR�y�Z�z e�e��dd�l�m�Z�WYdZ�[�n
dZ�[�00d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�ejOd�v�rje�Z�ne�Z�d�dĄZ�d�dƄZ�d�dȄZ�d�dʄZ�d�d̄Z�d�d΄Z�dRZ�ejOdUk�r�d�Z�d�dЄZ�d�d҄Z�d�dԄZ�e��r�e�Z�ne�Z��dMd�dքZ�d�Z�d�a�da�d�dڄZ�d�d܄Z�d�dބZ�dZ�ejOdMk�r e�Z�ne�Z�d�d�Z�d�d�Z�d�d�Z�d�d�Z�e��d�Z�d�d�Z�d�Z�d�d�Z��dNd�d�Z�Gd�d�d�e��Z�da��dOd�d�Z�Gd�d�d�e��Z�ifd�d��Z��dPd�d��Z�d�d��Z�d�d��Z�da�d�d��Z�d��d�Z��d�d�Z��dZ�ej�ej�ej�gZĐdD]&Z�eee�d�Z�e�du�reĠ�eš�q[�de�f�d�d�Zǐd�d�ZȐdQ�d	�d
�Zɐd�d�Zʐd
�d�Zːd�d�Z̐d�d�Z͐d�d�Z�e�a�ejKf�d�d�Z�ejKf�d�d�Zѐd�d�Z�ejOdMk�r�d�d�Z�n�d�d�Z�ejO�Ԑd��r�d�d �Z�nxejOdUk�r*�d!�d �Z�n^�d"ejOv�rF�d#�d �Z�nBejO�d$k�rb�d%�d �Z�n&ejOdMk�r|�d&�d �Z�n�d'�d �Z�da֐dR�d(�d)�Z�G�d*�d+��d+ej؃Z�ejOdMk�rҐdS�d-�d.�Z�ne�Zڐd/�d0�Zܐd1�d2�Zݐd3�d4�Zސd5�d6�Z�ejOdMk�	reUj�Z�ne�Z�g�d7�Z�d8d��e�D�Z�d9�d:�Z�d;�d<�Z�d=�d>�Z�d?�d@�Z�dAZ�G�dB�dC��dCe��Z�da�dD�dE�Z�e�	r�ej�Z�nej�Z�dS(T�)�absolute_importN�)�lazy_importa/
from datetime import datetime
import getpass
import locale
import ntpath
import posixpath
import select
# We need to import both shutil and rmtree as we export the later on posix
# and need the former on windows
import shutil
from shutil import rmtree
import socket
import subprocess
# We need to import both tempfile and mkdtemp as we export the later on posix
# and need the former on windows
import tempfile
from tempfile import mkdtemp
import unicodedata

from breezy import (
    config,
    trace,
    win32utils,
    )
from breezy.i18n import gettext
)�PY3�	text_type)�md5�sha1)�_fs_enc�errors�O_BINARY�O_TEXT�O_NOINHERITc@seZdZdZdd�ZdS)�UnsupportedTimezoneFormatzSUnsupported timezone format "%(timezone)s", options are "utc", "original", "local".cCs
||_dS�N)�timezone)�selfr�r�0/usr/lib/python3/dist-packages/breezy/osutils.py�__init__Ysz"UnsupportedTimezoneFormat.__init__N)�__name__�
__module__�__qualname__Z_fmtrrrrrrTsrc	sdtrtjdd�Sz$t���fdd�tjdd�D�WSty^t�td��t	����Yn0dS)Nrcsg|]}|����qSr)�decode)�.0�a��
user_encodingrr�
<listcomp>b�z$get_unicode_argv.<locals>.<listcomp>zBParameter {0!r} encoding is unsupported by {1} application locale.)
r�sys�argv�get_user_encoding�UnicodeDecodeErrorr
�BzrError�gettext�formatrrrrr�get_unicode_argv]s�r&cCs,t�|�j}t�|�s(|d@}t||�dS)zMake a filename read-only.im�N��os�lstat�st_mode�stat�S_ISLNK�chmod_if_possible��filename�modrrr�
make_readonlyhs
r1cCs,t�|�j}t�|�s(|dB}t||�dS)N�r'r.rrr�
make_writableps
r3c
Csvzt�||�Wn`ttfyp}zDt|d�tjtjfvrZt�	d||f�WYd}~dS�WYd}~n
d}~00dS)N�errnozignore error on chmod of %r: %r)
r(�chmod�IOError�OSError�getattrr4�EPERM�EACCES�trace�mutter)r/�mode�errrr-ws�r-cCsht|�dkrt|�Sdd�}tt|�|d�}|dg}|dd�D]}t|d|�sB|�|�qBt|�S)	z�Return the smallset subset of paths which are outside paths.

    :param paths: A container (and hence not None) of paths.
    :return: A set of paths sufficient to include everything in paths via
        is_inside, drawn from the paths parameter.
    �cSs"t|t�r|�d�S|�d�SdS)N�/�/)�
isinstance�bytes�split��pathrrr�sort_key�s

z(minimum_path_selection.<locals>.sort_key)�keyrrN���)�len�set�sorted�list�	is_inside�append)�pathsrGZsorted_pathsZsearch_pathsrFrrr�minimum_path_selection�s
rQcCs0tdurt�d�at�|�r(d|dS|SdS)ztReturn a quoted filename filename

    This previously used backslash quoting, but that works poorly on
    Windows.Nz([^a-zA-Z0-9.,:/\\_~-])�")�	_QUOTE_RE�re�compile�search��frrr�quotefn�s


rY�	directorycCst�d�}t�|�|S)zReturn the current umaskr)r(�umask)r[rrr�	get_umask�s

r\�file�rA�symlink�@ztree-reference�+cCs$z
t|WStyYdS0dS)Nr^)�_kind_marker_map�KeyError)�kindrrr�kind_marker�s
re�lexistsc
Csvzttdtj�}||�WdStyp}z<|jtjkrFWYd}~dSt�td��	||���WYd}~n
d}~00dS)Nr)TFzlstat/stat of ({0!r}): {1!r})
r8r(r+r7r4�ENOENTr
r#r$r%)rXr+r>rrrrf�s�c

Cs�tj�|�}tj�|�}d|t��t��td�f}t||�}d}z|||�Wn�tj	fyfYn�t
y�}z"|jdtjtj
fvr��WYd}~nTd}~0ty�}z0t|dd�dus�|jtjtj
fvrЂWYd}~nd}~00d}d}	z�z|||�d}	WnXt
tf�yZ}z:|�rD|jdtjfv�rD|��|��k�rDn�WYd}~n
d}~00W|�r�|	�rt||�n
|||�n"|�r�|	�r�||�n
|||�0dS)a/A fancy rename, when you don't have atomic rename.

    :param old: The old path, to rename from
    :param new: The new path, to rename to
    :param rename_func: The potentially non-atomic rename function
    :param unlink_func: A way to delete the target file if the full rename
        succeeds
    ztmp.%s.%.9f.%d.%s�
FNr4T)r(rF�basename�dirname�time�getpid�
rand_chars�pathjoinr
�
NoSuchFiler6r4rg�ENOTDIR�	Exceptionr8r7�lower)
�old�new�rename_func�unlink_func�baserjZtmp_nameZfile_existedr>Zsuccessrrr�fancy_rename�sL

�
�
�
�
rxcCs t�|�st�t�|�}t|�Sr)�	posixpath�isabs�join�getcwd�_posix_normpathrErrr�_posix_abspath-s
r~cCst�|�t���t�Sr)ry�realpath�encoder	rrErrr�_posix_realpath5sr�cCs$t�|�}|�d�r |dd�}|S)Nz//r)ry�normpath�
startswithrErrrr}9s
	
r}cCsNtj�|d�}ts|dur|Sz|�t�WStyHt�|t��Yn0dS)z�Get unicode path from `key` in environment or None if not present

    Note that posix systems use arbitrary byte strings for filesystem objects,
    so a path that raises BadFilenameEncoding here may still be accessible.
    N)	r(�environ�getrrr	r"r
�BadFilenameEncoding)rH�valrrr�_posix_path_from_environHsr�cCsNt�d�}z|�t�WSty,|YStyHt�|t��Yn0dS)z<Get the home directory of the current user as a unicode path�~N)ry�
expanduserrr	�AttributeErrorr"r
r�rErrr�_posix_get_home_dirXs
r�cCsLt��}tr|St�}z|�|�WStyFt�d||f��Yn0dS)z=Get username from environment or password database as unicodez@Encoding of username %r is unsupported by %s application locale.N)ZgetpassZgetuserrr!rr"r
r#)�namerrrr�_posix_getuser_unicodecs�r�cCst�|�\}}|��|S)aIForce drive letters to be consistent.

    win32 is inconsistent whether it returns lower or upper case
    and even if it was consistent the user might type the other
    so we force it to uppercase
    running python.exe under cmd.exe return capital C:\
    running win32 python inside a cygwin shell returns lowercase c:\
    )�ntpath�
splitdrive�upper)rFZdriverrr�_win32_fixdriveps	r�cCstt�|��dd��S�N�\rA)r�r��abspath�replacerErrr�_win32_abspath}sr�cCstt�|��dd��Sr�)r�r�rr�rErrr�_win32_realpath�sr�cGstj|��dd�Sr�)r�r{r���argsrrr�_win32_pathjoin�sr�cCstt�|��dd��Sr�)r�r�r�r�rErrr�_win32_normpath�sr�cCstt��dd��Sr�)r��_getcwdr�rrrr�
_win32_getcwd�sr�cOsttj|i|���dd��Sr�)r�Ztempfile�mkdtempr�)r��kwargsrrr�_win32_mkdtemp�sr�c
Cshzt||tjtjd�WnJtyb}z2|jtjtjtjtj	fvrLt�
|��WYd}~n
d}~00dS)z�We expect to be able to atomically replace 'new' with old.

    On win32, if new exists, it must be moved out of the way first,
    and then deleted.
    )rurvN)rxr(�rename�unlinkr7r4r9r:ZEBUSY�EINVALr))rsrtr>rrr�
_win32_rename�s
r�cCst�dt��S�N�NFC)�unicodedata�	normalizer�rrrr�_mac_getcwd�sr�cs�fdd�}|S)z�Adds extra information to any exceptions that come from rename().

    The exception has an updated message and 'old_filename' and 'new_filename'
    attributes.
    c
sbz�||�WnNty\}z6t|j|jd||f�}||_||_|�WYd}~n
d}~00dS)Nz& [occurred when renaming '%s' to '%s'])r7r4�strerrorZold_filenameZnew_filename)rsrtr>Zdetailed_error�rurr�_rename_wrapper�s
��z/_rename_wrap_exception.<locals>._rename_wrapperr)rur�rr�r�_rename_wrap_exception�sr�)�cCs|Srr)�strrr�	wrap_stat�sr��win32)�_walkdirs_win32r�cCsF|d}|tjtjfvr@t|t�r@|jtjkr@t|�||�n�dS)zyError handler for shutil.rmtree function [for win32]
        Helps to remove files and dirs marked as read-only.
        rN)r(�remove�rmdirrBr7r4r:r3)ZfunctionrF�excinfo�	exceptionrrr�_win32_delete_readonly�s�
�
r�FcCst�|||�S)z<Replacer for shutil.rmtree: could remove readonly dirs/files)�shutil�rmtree)rF�
ignore_errors�onerrorrrrr�sr��darwincCs�ddlm}ttjdd�}|sZttjdd�}|sFt�}|rX|d|�qh|}|rh|d|�n|rh|d|�|dkr�t�}|r�|d	|�zt�|�Wn.t	y�tj
�d
|t�f�t�}Yn0|S)aDFind the best encoding for printing to the screen.

    This attempts to check both sys.stdout and sys.stdin to see
    what encoding they are in, and if that fails it falls back to
    osutils.get_user_encoding().
    The problem is that on Windows, locale.getpreferredencoding()
    is not the same encoding as that used by the console:
    http://mail.python.org/pipermail/python-list/2003-May/162357.html

    On my standard US Windows XP, the preferred encoding is
    cp1252, but the console is cp437

    :param trace: If True trace the selected encoding via mutter().
    r)r<�encodingNz1encoding stdout as osutils.get_user_encoding() %rz(encoding stdout as sys.stdin encoding %rz)encoding stdout as sys.stdout encoding %r�cp0zJcp0 is invalid encoding. encoding stdout as osutils.get_user_encoding() %rzIbrz: warning: unknown terminal encoding %s.
  Using encoding %s instead.
)r;r<r8r�stdout�stdinr!�codecs�lookup�LookupError�stderr�write)r;r<Zoutput_encodingZinput_encodingrrr�get_terminal_encodings>��
��r�cCs^ttjdd�durt}nt}tj�|�\}}|dksD|dksD|dkrL||�St||�|�SdS)Nrr^�.�..)r8r(rFrr�rDrn)rX�F�pr>rrr�
normalizepathIsr�cCs2zt�t�|�tj�WSty,YdS0dS)z%True if f is an accessible directory.FN)r+�S_ISDIRr(r)�ST_MODEr7rWrrr�isdirUsr�cCs2zt�t�|�tj�WSty,YdS0dS)zTrue if f is a regular file.FN)r+�S_ISREGr(r)r�r7rWrrr�isfile]sr�cCs2zt�t�|�tj�WSty,YdS0dS)zTrue if f is a symlink.FN)r+r,r(r)r�r7rWrrr�islinkesr�cCsR||krdS|dvrdSt|t�r6|�d�sH|d7}n|�d�sH|d7}|�|�S)a4True if fname is inside dir.

    The parameters should typically be passed to osutils.normpath first, so
    that . and .. and repeated slashes are eliminated, and the separators
    are canonical for the platform.

    The empty string as a dir name is taken as top-of-tree and matches
    everything.
    T)r^rr@rA)rBrC�endswithr�)�dir�fnamerrrrNms



rNcCs|D]}t||�rdSqdS)z*True if fname is inside any of given dirs.TF�rN�Zdir_listr�rjrrr�
is_inside_any�s
r�cCs(|D]}t||�st||�rdSqdS)z?True if fname is a child or a parent of any of the given files.TFr�r�rrr�is_inside_or_parent_of_any�sr�rI���readc
Cs�d}|dkrj|dkr�t||�}|�|�}|s.q�|durD|t|�|�|�|�t|�}	||	8}||	7}qn>|�|�}|szq�|dur�|t|�|�|�|�|t|�7}qj|S)a�Copy contents of one file to another.

    The read_length can either be -1 to read to end-of-file (EOF) or
    it can specify the maximum number of bytes to read.

    The buff_size represents the maximum size for each read operation
    performed on from_file.

    :param report_activity: Call this as bytes are read, see
        Transport._report_activity
    :param direction: Will be passed to report_activity

    :return: The number of bytes copied.
    rN)�minr�rJr�)
Z	from_fileZto_fileZread_lengthZ	buff_size�report_activity�	directionZlengthZnum_bytes_to_read�blockZactual_bytes_readrrr�pumpfile�s*




r�cCsH|sd}tdt|�|�}t|�}|j}|D]}|||||��q*dS)z�Write bytes to file_handle in many smaller writes.

    :param bytes: The string to write.
    :param file_handle: The file to write to.
    iPrN)�rangerJ�
memoryviewr�)rCZfile_handleZsegment_sizeZoffsets�viewr��offsetrrr�pump_string_file�s	r�ccs$|�|�}t|�dkrq |VqdS�Nr)r�rJ)Z
input_file�readsize�brrr�
file_iterator�s
r�cCs|����Sr)�	hexdigestr��Zhashobjrrr�
_hexdigest�sr�cCs|��Sr)r�r�rrrr��scCs.t�}d}|�|�}|sq&|�|�q
t|�S)zbCalculate the hexdigest of an open file.

    The file cursor should be already at the start.
    �)�shar��updater�)rX�s�BUFSIZEr�rrr�sha_file�s
r�cCsBd}t�}d}|�|�}|sq6|t|�7}|�|�q|t|�fS)z�Calculate the size and hexdigest of an open file.

    The file cursor should be already at the start and
    the caller is responsible for closing the file afterwards.
    rr�)r�r�rJr�r�)rX�sizer�r�r�rrr�
size_sha_file�s
r�c	Cslt�}t�|tjtBtB�}z>t�|d�}|sBt|�Wt�|�S|�	|�qWt�|�nt�|�0dS)z5Calculate the SHA1 of a file by reading the full text�N)
r�r(�open�O_RDONLYrr
r�r��closer�)r�r�rXr�rrr�sha_file_by_names
�r�cCs"|�}|D]}|�|�q
t|�S)z,Return the sha-1 of concatenation of strings)r�r�)Zstrings�_factoryr��stringrrr�sha_stringssr�cCst||��Sr)r�)rXr�rrr�
sha_string$sr�cCs|��}t|�tt|��d�S)N)r�r)r�rJr�r�)rXr�rrr�fingerprint_file)s
�r�cCs2d}|�|�}|�|�}||kr$dS|sdSqdS)z!Returns true if equal in contentsiFTN)r�)rr�r�ZaiZbirrr�
compare_files/s

r�cCs4|durt��}t�|�t�|�}|jd|jS)zEReturn offset of local zone from GMT, either at present or at time t.Ni�Q)rkZdatetimeZ
fromtimestampZutcfromtimestampZdays�seconds)�tr�rrr�local_time_offset;sr)ZMonZTueZWedZThuZFriZSatZSuncCsg|]}|d�qS)z %Y-%m-%d %H:%M:%Sr)rZwdrrrrDrr�originalTcCs>t|||||�\}}}|�dt|d�}t�||�}||S)a�Return a formatted date string.

    :param t: Seconds since the epoch.
    :param offset: Timezone offset in seconds east of utc.
    :param timezone: How to display the time: 'utc', 'original' for the
         timezone specified by offset, or 'local' for the process's current
         timezone.
    :param date_fmt: strftime format.
    :param show_offset: Whether to append the timezone.
    z%a�)�_format_dater��weekdaysrk�strftime�rr�r�date_fmt�show_offset�tt�
offset_str�date_strrrr�format_dateGs

�rcCsn|durd}t�||�}t|d}t�||�}|�|d�}|durfd|d|ddf}|||<||S)z�Return a formatted date string in the original timezone.

    This routine may be faster then format_date.

    :param t: Seconds since the epoch.
    :param offset: Timezone offset in seconds east of utc.
    Nrr�
 %+03d%02d��<)rk�gmtime�_default_format_by_weekday_numrr�)rr��_cacherr	r
rrrr�,format_date_with_offset_in_original_timezone^s	rcCsBt|||||�\}}}t�||�}t|t�s:|�t�d�}||S)a�Return an unicode date string formatted according to the current locale.

    :param t: Seconds since the epoch.
    :param offset: Timezone offset in seconds east of utc.
    :param timezone: How to display the time: 'utc', 'original' for the
         timezone specified by offset, or 'local' for the process's current
         timezone.
    :param date_fmt: strftime format.
    :param show_offset: Whether to append the timezone.
    r�)rrkrrBrrr!rrrr�format_local_datess
�
rcCs�|dkrt�|�}d}nH|dkr<|dur,d}t�||�}n$|dkrXt�|�}t|�}nt|��|durld}|r�d|d|ddf}nd	}|||fS)
NZutcrrZlocalz%a %Y-%m-%d %H:%M:%Srrrr^)rkr�	localtimerr)rr�rr	r
rrrrrr�s"


rcCst�dt�|��S)Nz%Y%m%d%H%M%S)rkrr)Zwhenrrr�compact_date�srcCs�t|�}|dkrd}n
d}|}|}|dkrL|dkr@d||fSd||fSt|d�}|d|8}|dkrrd	}nd
}|dkr�|dkr�d||||fSd||||fSt|d�}|d|8}|dkr�d	}nd
}|dkr�d
||||fSd||||fS)a=Get a nice looking string for a time delta.

    :param delta: The time difference in seconds, can be positive or negative.
        positive indicates time in the past, negative indicates time in the
        future. (usually time.time() - stored_time)
    :return: String formatted to show approximate resolution
    rZagoz
in the future�Zrz%d second %sz
%d seconds %srr^r�z%d minute, %d second%s %sz%d minutes, %d second%s %sz%d hour, %d minute%s %sz%d hours, %d minute%s %s)�int)Zdeltar�rZminutesZplural_secondsZhoursZplural_minutesrrr�format_delta�sF����rcCst�|���tjS)zReturn size of given open file.)r(�fstat�filenor+�ST_SIZErWrrr�filesize�sr�ntcCs2ddl}d}|r.|t|�dd��7}|d8}q|S)Nrr^�r)�random�chrZrandint)�nr"r�rrr�
rand_bytes�s
r%Z$0123456789abcdefghijklmnopqrstuvwxyzcCs@d}t|�D].}ts*|tt|�d7}q|t|d7}q|S)z�Return a random string of num alphanumeric characters

    The result only contains lowercase chars because it may be used on
    case-insensitive filesystems.
    r^�$)r%r�ALNUM�ord)Znumr�Zraw_byterrrrm�srmcCs�t|t�}tjjdkr6|r(t�d|�}qPt�d|�}n|rF|�d�}n
|�d�}|r^d}d}nd}d	}g}|D]4}||kr�t�t	d
�|��qn||vr�qn|�
|�qn|S)zTurn string into list of parts.r�s[\\/]z[\\/]r@rAs..)�.rr�)r�r^�sorry, %r not allowed in path)rBrCr(rF�seprTrDr
r#r$rO)r�Z	use_bytesZpsZ
parent_dirZcurrent_empty_dirZrpsrXrrr�	splitpaths*

r,cCs<|D].}|dks |dus |dkrt�td�|��qt|�S)Nr�r^r*)r
r#r$rn)r�rXrrr�joinpath#sr-cCs0g}tt|��}|r,|�t|��|��q|S)zyReturn the list of parent directories, deepest first.

    For example, parent_directories("a/b/c") -> ["a/b", "a"].
    )r,rjrOr-�pop)r/�parents�partsrrr�parent_directories*s
r1cCs,t|�}|tvr(t�d|�t�|�dS)a�Handle failing to load a binary extension.

    This should be called from the ImportError block guarding the attempt to
    import the native extension.  If this function returns, the pure-Python
    implementation should be loaded instead::

    >>> try:
    >>>     import breezy._fictional_extension_pyx
    >>> except ImportError, e:
    >>>     breezy.osutils.failed_to_load_extension(e)
    >>>     import breezy._fictional_extension_py
    z%failed to load compiled extension: %sN)�str�_extension_load_failuresr;r<rO)r�Z
exception_strrrr�failed_to_load_extension:sr4cCs2tsdSt���d�rdSddlm}|d�dS)NZmissing_extensionsr��warningz_brz: warning: some compiled extensions could not be loaded; see ``brz help missing-extensions``)r3ZconfigZGlobalConfigZsuppress_warningr;r6r5rrr�report_extension_load_failuresUs�r7)�chunks_to_linescCs t|t�rt|g�St|�SdS)z@Split s into lines, but without removing the newline characters.N)rBrCr8�_split_lines�r�rrr�split_linesks

r;csPt|t�rdnd�|���}�fdd�|dd�D�}|drL|�|d�|S)zySplit s into lines, but without removing the newline characters.

    This supports Unicode or plain string objects.
    �
�
csg|]}|��qSrr)r�line��nlrrr}rz _split_lines.<locals>.<listcomp>NrI)rBrCrDrO)r��lines�resultrr?rr9vs
r9cCs
tjdvS)N)r��cygwinr��r�platformrrrr�hardlinks_good�srFc
Csnt�st�||�dSzt�||�WnBttfyh}z&|jtjkrH�t�||�WYd}~n
d}~00dS)z6Hardlink a file, or copy it if it can't be hardlinked.N)	rFr�Zcopyfiler(�linkr7r6r4ZEXDEV)�src�destr>rrr�link_or_copy�srJcCs|zt|�Wnjttfyv}zN|jtjtjfvr`zt|�WnttfyTYn0t|�n�WYd}~n
d}~00dS)zLDelete a file, symlink or directory.

    Will delete even if readonly.
    N)�_delete_file_or_dirr7r6r4r9r:r3)rFr>rrr�
delete_any�s
rLcCs"t|�rt�|�n
t�|�dSr)r�r(r�r�rErrrrK�srKcCsttdd�durdSdSdS)Nr_TF�r8r(rrrr�has_symlinks�srNcCsttdd�durdSdSdS)NrGTFrMrrrr�
has_hardlinks�srOcCst�otjdvS)N)rCr�)rNrrErrrr�host_os_dereferences_symlinks�s�rPcCs"|�t�}t�|�}|�t�}|S)z�Return a string representing the path to which the symbolic link points.

    :param abspath: The link absolute unicode path.

    This his guaranteed to return the symbolic link in unicode in all python
    versions.
    )r�r	r(�readlinkr)r�rG�targetrrrrQ�s


rQcCs0t|t�rd}nd}|D]}||vrdSqdS)z1True if there are any whitespace characters in s.z 	

)� �	r<�
��TFN)rBr2)r�Zws�chrrr�contains_whitespace�s	
rYcCsdD]}||vrdSqdS)z.True if there is any vertical whitespace in s.z

TFNr)r�rXrrr�contains_linebreaks�srZcCs�t|�tkrttd�|f��t|�}g}|}t|�t|�krR||krRt�||��||kr\qxt|�\}}|r.|�|�q.|r�t	t
|��SdSdS)a�Return path relative to base, or raise PathNotChild exception.

    The path may be either an absolute path or a path relative to the
    current working directory.

    os.path.commonprefix (python2.4) has a bad bug that it works just
    on string prefixes, assuming that '/u' is a prefix of '/u2'.  This
    avoids that problem.

    NOTE: `base` should not have a trailing slash otherwise you'll get
    PathNotChild exceptions regardless of `path`.
    z,%r is too short to calculate a relative pathr^N)rJ�MIN_ABS_PATHLENGTH�
ValueErrorr$r�r
ZPathNotChildrDrOrn�reversed)rwrFZrpr��head�tailrrr�relpath�s"�r`c	Cs�t||�}|s|St|�}|}tj}t|�d��}|D]�}|��}z||�}	Wn.ty|t||gt	|��R�}Yq�Yn0|	D]}
||
��kr�t||
�}q6q�t||gt	|��R�}q�q6|t
|�d��d�S)a�Return the canonical path relative to base.

    Like relpath, but on case-insensitive-case-preserving file-systems, this
    will return the relpath as stored on the file-system rather than in the
    case specified in the input string, for all existing portions of the path.

    This will cause O(N) behaviour if called for every path in a tree; if you
    have a number of paths to convert, you should use canonical_relpaths().
    rAN)r`r�r(�listdir�iterrDrrr7rnrMrJ�lstrip)rwrFZrelZabs_baseZcurrent�_listdirZbit_iter�bitZlbitZnext_entriesZlookrrr�_cicp_canonical_relpaths*

rf)r�r�cs�fdd�|D�S)z�Create an iterable to canonicalize a sequence of relative paths.

    The intent is for this implementation to use a cache, vastly speeding
    up multiple transformations in the same directory.
    csg|]}t�|��qSr)�canonical_relpath)rr��rwrrrYrz&canonical_relpaths.<locals>.<listcomp>r)rwrPrrhr�canonical_relpathsRsricCs>t|t�r|Sz|�t�WSty8t�|t��Yn0dS)z�Decode the filename using the filesystem encoding

    If it is unicode, it is returned.
    Otherwise it is decoded from the the filesystem's encoding. If decoding
    fails, a errors.BadFilenameEncoding exception is raised.
    N)rBrrr	r"r
r�)r/rrr�decode_filename\s
rjcCs<t|t�r|Sz|�d�WSty6t�|��Yn0dS)z�Coerce unicode_or_utf8_string into unicode.

    If it is unicode, it is returned.
    Otherwise it is decoded from utf-8. If decoding fails, the exception is
    wrapped in a BzrBadParameterNotUnicode exception.
    �utf8N)rBrrr"r
�BzrBadParameterNotUnicode�Zunicode_or_utf8_stringrrr�safe_unicodeks
rncCsDt|t�r:z|�d�Wnty4t�|��Yn0|S|�d�S)z�Coerce unicode_or_utf8_string to a utf8 string.

    If it is a str, it is returned.
    If it is Unicode, it is encoded into a utf-8 string.
    �utf-8)rBrCrr"r
rlr�rmrrr�	safe_utf8zs
rpcCs"|dus|jtkr|Std��dS)z�Revision ids should now be utf8, but at one point they were unicode.

    :param unicode_or_utf8_string: A possibly Unicode revision_id. (can also be
        utf8 or None).
    :return: None or a utf8 revision id.
    NzjUnicode revision ids are no longer supported. Revision id generators should be creating utf8 revision ids.��	__class__rC�	TypeErrorrmrrr�safe_revision_id�s
�rtcCs"|dus|jtkr|Std��dS)aFFile ids should now be utf8, but at one point they were unicode.

    This is the same as safe_utf8, except it uses the cached encode functions
    to save a little bit of performance.

    :param unicode_or_utf8_string: A possibly Unicode file_id. (can also be
        utf8 or None).
    :return: None or a utf8 file id.
    Nz^Unicode file ids are no longer supported. File id generators should be creating utf8 file ids.rqrmrrr�safe_file_id�s

�rucCstS)zRReturn True if this platform normalizes unicode filenames.

    Only Mac OSX.
    )�_platform_normalizes_filenamesrrrr�normalizes_filenames�srwcCs(t|t�r|�t���}t�d|�dfS)a!Get the unicode normalized path, and if you can access the file.

    On platforms where the system normalizes filenames (Mac OSX),
    you can access a file by any path which will normalize correctly.
    On platforms where the system does not normalize filenames
    (everything else), you have to access a file by its exact path.

    Internally, bzr only supports NFC normalization, since that is
    the standard for XML documents.

    So return the normalized path, and a flag indicating if the file
    can be accessed by that path.
    r�T)rBrCrr�getfilesystemencodingr�r�rErrr�_accessible_normalized_filename�s
rycCs6tj}t|t�r|�t���}t�d|�}|||kfSr�)	ry�__doc__rBrCrrrxr�r�)rFrzZ
normalizedrrr�!_inaccessible_normalized_filename�s

r{csxzddl}|j�Wn,ty&YdSty>dd��Yn0|rV���fdd�}n�}|��|�}|rt��d�|S)atA wrapper for signal.signal that also calls siginterrupt(signum, False)
    on platforms that support that.

    :param restart_syscall: if set, allow syscalls interrupted by a signal to
        automatically restart (by calling `signal.siginterrupt(signum,
        False)`).  May be ignored if the feature is not available on this
        platform or Python version.
    rNcSsdSrr)�signum�flagrrr�siginterrupt�rz(set_signal_handler.<locals>.siginterruptcs��d��|�dS)NFrr���handlerr~r|rr�sig_handler�s
z'set_signal_handler.<locals>.sig_handlerF)�signalr~�ImportErrorr�)r|r�Zrestart_syscallr�r�Zold_handlerrrr�set_signal_handler�s	

r��P�no_datac	Cszttjd�}Wnttfy,d}Yn0|durF|dkrB|SdSttjdd�}|dusb|�sfdStdd�\}}}t	dkr�|a
da	nt	dkr�t
|kr�da	t	dkr�|dur�|dkr�|Szttjd�WSttfy�Yn0t	dk�r|du�r|dk�r|SdS)	aReturn terminal width.

    None is returned if the width can't established precisely.

    The rules are:
    - if BRZ_COLUMNS is set, returns its value
    - if there is no controlling terminal, returns None
    - query the OS, if the queried size has changed since the last query,
      return its value,
    - if COLUMNS is set, returns its value,
    - if the OS has a value (even though it's never changed), return its value.

    From there, we need to query the OS to get the size of the controlling
    terminal.

    On Unices we query the OS by:
    - get termios.TIOCGWINSZ
    - if an error occurs or a negative value is obtained, returns None

    On Windows we query the OS by:
    - win32utils.get_console_size() decides,
    - returns None on error (provided default value)
    ZBRZ_COLUMNSNr�isattyr�Z	unchangedZchangedZCOLUMNS)rr(r�rcr\r8rr��_terminal_size�_terminal_size_state�_first_terminal_size)�widthr��heightZos_sizerrr�terminal_widths<'
�
r�cCstj||d�\}}||fS)N)ZdefaultxZdefaulty)�
win32utilsZget_console_size)r�r�rrr�_win32_terminal_sizees�
r�c	CsvzVddl}ddl}ddl}|�ddddd�}|�d|j|�}|�d|�dd�\}}WnttfylYn0||fS)NrZHHHHrr?)	�struct�fcntl�termiosZpackZioctlZ
TIOCGWINSZZunpackr6r�)r�r�r�r�r�r��xrrr�_ioctl_terminal_sizeksr�c
Cs`tjdkrdSzt|�}Wn4tjyN}zt�d||�WYd}~nd}~00|dvr\dSdS)z�Return if filesystem at path supports executable bit.

    :param path: Path for which to check the file system
    :return: boolean indicating whether executable bit can be stored/relied upon
    r�F� Unable to get fs type for %r: %sN�ZvfatZntfsT)rrE�get_fs_typer
�DependencyNotPresentr;r<�rFZfs_typer>rrr�supports_executable�s
$r�c
Cs\t�s
dSzt|�}Wn4tjyJ}zt�d||�WYd}~nd}~00|dvrXdSdS)zOReturn if the filesystem at path supports the creation of symbolic links.

    Fr�Nr�T)rNr�r
r�r;r<r�rrr�supports_symlinks�s$r�cCs
tjdkS)a�Return True if 'readonly' has POSIX semantics, False otherwise.

    Notably, a win32 readonly file cannot be deleted, unlike POSIX where the
    directory controls creation/deletion, etc.

    And under win32, readonly means that the directory itself cannot be
    deleted.  The contents of a readonly directory can be changed, unlike POSIX
    where files in readonly directories cannot be added, deleted or renamed.
    r�rDrrrr�supports_posix_readonly�s
r�cCsNtj�|�}|dur&|durJtj|=n$ts@t|t�r@|�t��}|tj|<|S)a)Modify the environment, setting or removing the env_variable.

    :param env_variable: The environment variable in question
    :param value: The value to set the environment to. If None, then
        the variable will be removed.
    :return: The original value of the environment variable.
    N)r(r�r�rrBrr�r!)Zenv_variable�valueZorig_valrrr�set_or_unset_env�s

r�z^([A-Za-z]:[/\\])?[^:<>*"?\|]*$cCs*tjdkrdSt�|�dur&t�|��dS)z�Check whether the supplied path is legal.
    This is only required on Windows, so we don't test on other platforms
    right now.
    r�N)rrE�_validWin32PathRE�matchr
ZIllegalPathrErrr�check_legal_path�s
r�icCsJt|dd�}|tjksBtjdkrF|tksB|tjkrFt|dd�tkrFdSdS)aeCheck if this exception represents ENOTDIR.

    Unfortunately, python is very inconsistent about the exception
    here. The cases are:
      1) Linux, Mac OSX all versions seem to set errno == ENOTDIR
      2) Windows, Python2.4, uses errno == ERROR_DIRECTORY (267)
         which is the windows error code.
      3) Windows, Python2.5 uses errno == EINVAL and
         winerror == ERROR_DIRECTORY

    :param e: An Exception object (expected to be OSError with an errno
        attribute, but we should be able to cope with anything)
    :return: True if this represents an ENOTDIR error. False otherwise.
    r4Nr�ZwinerrorTF)r8r4rprrE�_WIN32_ERROR_DIRECTORYr�)r>Zenrrr�_is_error_enotdir�s
����r�c
#stj}t�tj}t}t|�d�dt|�fg}|�r|��\}}}}}|rR|d}nd}|d}	g}
|
j}ztt	t
||���}Wn.ty�}
zt|
�s��WYd}
~
nDd}
~
00|D]4}|	|}||�}||j
�}|||||||f�q�||f|
fV|��fdd�t|
�D��q,dS)aAYield data about all the directories in a tree.

    This yields all the data about the contents of a directory at a time.
    After each directory has been yielded, if the caller has mutated the list
    to exclude some directories, they are then not descended into.

    The data yielded is of the form:
    ((directory-relpath, directory-path-from-top),
    [(relpath, basename, kind, lstat, path-from-top), ...]),
     - directory-relpath is the relative path of the directory being returned
       with respect to top. prefix is prepended to this.
     - directory-path-from-root is the path including top for this directory.
       It is suitable for use with os functions.
     - relpath is the relative path within the subtree being walked.
     - basename is the basename of the path
     - kind is the kind of the file now. If unknown then the file is not
       present within the tree - but it may be recorded as versioned. See
       versioned_kind.
     - lstat is the stat data *if* the file was statted.
     - planned, not implemented:
       path_from_tree_root is the path from the root of the tree.

    :param prefix: Prefix the relpaths that are yielded with 'prefix'. This
        allows one to walk a subtree but get paths that are relative to a tree
        rooted higher up.
    :return: an iterator over the dirs.
    r^NrAc3s|]}|d�kr|VqdS)r?Nr�r�d�Z
_directoryrr�	<genexpr>5rzwalkdirs.<locals>.<genexpr>)r(r)�_directory_kindra�file_kind_from_stat_modernr.rOrL�maprjr7r�r*�extendr])�top�prefix�_lstatrd�_kind_from_mode�pending�relroot�_�	relprefix�	top_slash�dirblockrO�namesr>r�r��	statvaluerdrr�r�walkdirs�s2!

r�c@s"eZdZdZddd�Zdd�ZdS)	�	DirReaderz%An interface for reading directories.r^cCst|j��dS)aConverts top and prefix to a starting dir entry

        :param top: A utf8 path
        :param prefix: An optional utf8 path to prefix output relative paths
            with.
        :return: A tuple starting with prefix, and ending with the native
            encoding of top.
        N)�NotImplementedError�top_prefix_to_starting_dir�rr�r�rrrr�;s	z$DirReader.top_prefix_to_starting_dircCst|j��dS)a1Read a specific dir.

        :param prefix: A utf8 prefix to be preprended to the path basenames.
        :param top: A natively encoded path to read.
        :return: A list of the directories contents. Each item contains:
            (utf8_relpath, utf8_name, kind, lstatvalue, native_abspath)
        N)r��read_dir)rr�r�rrrr�FszDirReader.read_dirN)r^)rrrrzr�r�rrrrr�8s
r�c
#s$tdur�tjdkr>zddlm}|�aWq�ty:Yq�0nLtdvr�zddlm}|�aWn,ty�}zt	|�WYd}~n
d}~00tdur�t
�at�||�gg}tj}t
�|�r |d��\}}}}}|ds�|��t|||��}	||f|	fV�fdd	�t|	�D�}
|
r�|�|
�q�dS)
a�Yield data about all the directories in a tree.

    This yields the same information as walkdirs() only each entry is yielded
    in utf-8. On platforms which have a filesystem encoding of utf8 the paths
    are returned as exact byte-strings.

    :return: yields a tuple of (dir_info, [file_info])
        dir_info is (utf8_relpath, path-from-top)
        file_info is (utf8_relpath, utf8_name, kind, lstat, path-from-top)
        if top is an absolute path, path-from-top is also an absolute path.
        path-from-top might be unicode or utf8, but it is the correct path to
        pass to os functions to affect the file in question. (such as os.lstat)
    Nr�r)�Win32ReadDir)ro�ascii��
UTF8DirReaderrIcsg|]}|d�kr|�qS)r?rr�r�rrr�rz"_walkdirs_utf8.<locals>.<listcomp>)�_selected_dir_readerrrEr�r�r�r	�_readdir_pyxr�r4�UnicodeDirReaderr�r�r�r.rLr]rO)r�r�r�r�r>r�r�r�r�r��nextrr�r�_walkdirs_utf8Ts8


r�c@s0eZdZdZdgZdd�Zddd�Zdd	�Zd
S)r�z9A dir reader for non-utf8 file systems, which transcodes.�_utf8_encodecCst�d�|_dS)Nrk)r��
getencoderr�)rrrrr�szUnicodeDirReader.__init__r^cCst|�dddt|�fS)z)See DirReader.top_prefix_to_starting_dir.N)rprnr�rrrr��sz+UnicodeDirReader.top_prefix_to_starting_dirc	Cs�|j}dd�}dd�}tj}tj}t}|r4|d}	nd}	|d}
g}|j}||�d��D]p}
z||
�}Wn"ty�t�	|	|
t
��Yn0||�d	}|
|}||�}||j�}||	|||||f�qXt|�S)
aRead a single directory from a non-utf8 file system.

        top, and the abspath element in the output are unicode, all other paths
        are utf8. Local disk IO is done via unicode calls to listdir etc.

        This is currently the fallback code path when the filesystem encoding is
        not UTF-8. It may be better to implement an alternative so that we can
        safely handle paths that are not properly decodable in the current
        encoding.

        See DirReader.read_dir for details.
        cSs
|�t�Sr)rr	r:rrr�
_fs_decode�rz-UnicodeDirReader.read_dir.<locals>._fs_decodecSs
|�t�Sr)r�r	r:rrr�
_fs_encode�rz-UnicodeDirReader.read_dir.<locals>._fs_encoder@rrAror)
r�r(r)rar�rOr�r"r
r�r	r*rL)rr�r�r�r�r�r�rdr�r�r�r�rOZname_nativer�Z	name_utf8r�r�rdrrrr��s2

�

zUnicodeDirReader.read_dirN)r^)rrrrz�	__slots__rr�r�rrrrr��s

r�c
Cs~dd�}dd�}tj||d�}|�|�tj�|�sB|d||�t||d�D]*\}}|D]\}}	}
}}||
||�qZqNdS)	acCopy all of the entries in from_path into to_path.

    :param from_path: The base directory to copy.
    :param to_path: The target directory. If it does not exist, it will
        be created.
    :param handlers: A dictionary of functions, which takes a source and
        destinations for files, directories, etc.
        It is keyed on the file kind, such as 'directory', 'symlink', or 'file'
        'file', 'directory', and 'symlink' should always exist.
        If they are missing, they will be replaced with 'os.mkdir()',
        'os.readlink() + os.symlink()', and 'shutil.copy2()', respectively.
    cSst�|�dSr)r(�mkdir)�sourcerIrrr�copy_dir�szcopy_tree.<locals>.copy_dircSst�|�}t�||�dS)zCopy the contents of a symlinkN)r(rQr_)r�rIZlink_torrr�	copy_link�s
zcopy_tree.<locals>.copy_link)r]r_rZrZ)r�N)r�Zcopy2r�r(rF�existsr�)
Z	from_pathZto_path�handlersr�r�Z
real_handlersZdir_info�entriesr`r�rdr�r�rrr�	copy_tree�s�
r�cCs�ttdd�}|durdS|dur8tj�|�}|dkr8d}zt�|�}|||j|j�Wn(ty~t�	d||�t�
�Yn0dS)z�Copy usr/grp ownership from src file/dir to dst file/dir.

    If src is None, the containing directory is used as source. If chown
    fails, the error is ignored and a warning is printed.
    �chownNr^r�zLUnable to copy ownership from "%s" to "%s". You may want to set it manually.)r8r(rFrjr+�st_uid�st_gidr7r;r6Zlog_exception_quietly)ZdstrHr�r�rrr�copy_ownership_from_path�s 
�r�cCst|�|fS)zwGenerate a prefix-order path key for path.

    This can be used to sort paths in the same way that walkdirs does.
    )rjrErrr�path_prefix_keysr�cCs t|�}t|�}||k||kS)zCCompare path_a and path_b to generate the same order walkdirs uses.)r�)Zpath_aZpath_bZkey_aZkey_brrr�compare_paths_prefix_order
sr�cCs�tdurtStjdkr4ttdd�dur4t�tj�}n
t�d�}zt�	|�j}Wn.t
y||dvrttj�
d|�d}Yn0|dkr�tjdkr�d	}|a|S)
a#Find out what the preferred user encoding is.

    This is generally the encoding that is used for command line parameters
    and file contents. This may be different from the terminal encoding
    or the filesystem encoding.

    :return: A string defining the preferred user encoding
    N�posix�CODESETF)r^r�zCbrz: warning: unknown encoding %s. Continuing with ascii encoding.
r�r�ro)�_cached_user_encodingr(r�r8Zlocale�nl_langinfor�Zgetpreferredencodingr�r�r�rr�r�rErrrrr!s$

�

r!cCst�Sr)r�rrrr�get_diff_header_encodingCsr�cCs:tjdkrt��Sddl}tr&|��S|���t��SdS)z�Return the current unicode host name.

    This is meant to be used in place of socket.gethostname() because that
    behaves inconsistently on different platforms.
    r�rN)	rrEr��
get_host_name�socketrZgethostnamerr!)r�rrrr�Gs
r�r�)Z
WSAECONNRESETZWSAECONNABORTEDc
Cs�z|�|�}Wn^tjyl}zD|jd}|tvr@WYd}~dS|tjkrVWYd}~q�WYd}~qd}~00|dur�|t|�d�|SqdS)z�Read up to max_read_size of bytes from sock and notify of progress.

    Translates "Connection reset by peer" into file-like EOF (return an
    empty string rather than raise an error), and repeats the recv if
    interrupted by a signal.
    rNrr�)Zrecvr��errorr��_end_of_stream_errorsr4�EINTRrJ)�sockr�Z
max_read_size�datar>Zenorrr�read_bytes_from_socketds	

r�cCs<d}t|�|kr8t|d|t|��}|dkr.q8||7}q|S)a�Receive an exact number of bytes.

    Regular Socket.recv() may return less than the requested number of bytes,
    depending on what's in the OS buffer.  MSG_WAITALL is not available
    on all platforms, but this should work everywhere.  This will return
    less than the requested amount if the remote end closes.

    This isn't optimized and is intended mostly for use in testing.
    rN)rJr�)r��countr�rtrrr�recv_alls

r�c
Cs�d}t|�}t|�}||kr�z|�|||t��}WnVtjtfy�}z8|jdtvrft	�
d|��|jdtjkrx�WYd}~qd}~00|dkr�t	�
d|f��||7}|dur||d�qdS)a�Send all bytes on a socket.

    Breaks large blocks in smaller chunks to avoid buffering limitations on
    some platforms, and catches EINTR which may be thrown if the send is
    interrupted by a signal.

    This is preferred to socket.sendall(), because it avoids portability bugs
    and provides activity reporting.

    :param report_activity: Call this as bytes are read, see
        Transport._report_activity
    rzError trying to write to socketNzSending to %s returned 0 bytesr�)
rJr��send�MAX_SOCKET_CHUNKr�r�r6r�r�r
ZConnectionResetr4r�)r�rCr�Z
sent_totalZ
byte_countr�Zsentr>rrr�send_all�s(
��r�cCs�t�d�}|\}}t�||dtj�D]t}|\}}}}}	d}
z"t�|||�}
|
�|	�|
WStjy�}z |}|
dur�|
��WYd}~q$d}~00q$|�dS)Nz!getaddrinfo returns an empty listr)r�r�ZgetaddrinfoZSOCK_STREAMZconnectr�)Zaddress�errZhostZport�resZafZsocktype�protoZ	canonnameZsar�r>rrr�connect_socket�s


 r�cCs$tj�|�\}}tttd|��|�S)z�Determine the real path to a file.

    All parent elements are dereferenced.  But the file itself is not
    dereferenced.
    :param path: The original path.  May be absolute or relative.
    :return: the real path *to* the file
    r�)r(rFrDrnr)rF�parentrwrrr�dereference_path�sr�cCs
tjdkS)z7Return True if we can use MAPI to launch a mail client.r�rDrrrr�
supports_mapi�sr�cCs�|dkr|}n>|�d�r>|td�d��dtj�}t||�}nt�d|��tt	j
�}ttdd�rrt
t|dd��}tt||�d��}|��Wd�S1s�0YdS)	a�Load a resource from a package and return it as a string.

    Note: Only packages that start with breezy are currently supported.

    This is designed to be a lightweight implementation of resource
    loading in a way which is API compatible with the same API from
    pkg_resources. See
    http://peak.telecommunity.com/DevCenter/PkgResources#basic-resource-access.
    If and when pkg_resources becomes a standard library, this routine
    can delegate to it.
    �breezyzbreezy.Nr�z!resource package %s not in breezy�frozenr�Zrt)r�rJr�r(r+rnr
r#rjr��__file__r8rr�r�r�)�package�
resource_nameZresource_relpathrwrXrrr�resource_string�s


r�cCsHttur@zddlm}|�jaWnty>ddlmaYn0t|�S)Nrr�)r�)r��file_kind_from_stat_mode_thunkr�r�Zkind_from_moder�Z_readdir_pyr�)r=r�rrrr��sr�c
CsXz
||�WStyR}z0t|dd�tjtjfvr<t�|���WYd}~n
d}~00dS)Nr4)r7r8r4rgrpr
ro)rXr�r>rrr�	file_stat	s

r�cCst||�}t|j�Sr)r�r�r*)rXr�Z
stat_valuerrr�	file_kind	s
r�c
OsZz||i|��WSttfyR}z&|jtjkr<WYd}~q�WYd}~qd}~00qdS)avRun f(*a, **kw), retrying if an EINTR error occurs.

    WARNING: you must be certain that it is safe to retry the call repeatedly
    if EINTR does occur.  This is typically only true for low-level operations
    like os.read.  If in any doubt, don't use this.

    Keep in mind that this is not a complete solution to EINTR.  There is
    probably code in the Python standard library and other dependencies that
    may encounter EINTR if a signal arrives (and there is signal handler for
    that signal).  So this function can reduce the impact for IO that breezy
    directly controls, but it is not a complete solution.
    N)r6r7r4r�)rXr�kwr>rrr�until_no_eintr	sr�cCsddl}|��Sr�)�msvcrtZgetch)r�rrr�getchar5	sr�cCsfddl}ddl}tj��}|�|�}z*|�|�tj�d�}W|�||j	|�n|�||j	|�0|S)Nrr)
�ttyr�rr�rZ	tcgetattrZsetrawr�Z	tcsetattrZ	TCSADRAIN)rr��fdZsettingsrXrrrr�9	s


$Zlinuxc
Cs,zt�d�WStttfy&YdS0dS)N�SC_NPROCESSORS_ONLN)r(�sysconfr\r7r�rrrr�_local_concurrencyF	srcCstjgd�tjd���dS)N)�sysctl�-nzhw.availcpu�r�r��
subprocess�Popen�PIPEZcommunicaterrrrrL	s

��ZbsdcCstjgd�tjd���dS)N)rrzhw.ncpurrrrrrrrP	s

��Zsunos5cCstjddgtjd���dS)NZpsrinfoz-prrrrrrrrT	s

��cCstj�d�S)NZNUMBER_OF_PROCESSORS)r(r�r�rrrrrX	scCsdSrrrrrrr\	scCs�tdur|rtStj�dd�}|durpddl}z|��}Wn4tynz
t�}Wntt	fyhYn0Yn0zt
|�}Wnttfy�d}Yn0|r�|a|S)z�Return how many processes can be run concurrently.

    Rely on platform specific implementations and default to 1 (one) if
    anything goes wrong.
    NZBRZ_CONCURRENCYrr)
�_cached_local_concurrencyr(r�r��multiprocessing�	cpu_countr�rr7r6rrsr\)Z	use_cacheZconcurrencyr
rrr�local_concurrencyd	s&

rc@s"eZdZdZddd�Zdd�ZdS)	�UnicodeOrBytesToBytesWriterz2A stream writer that doesn't decode str arguments.�strictcCstj�|||�||_dSr)r��StreamWriterrr�)rr��streamr
rrrr�	sz$UnicodeOrBytesToBytesWriter.__init__cCs:t|t�r|j�|�n|�||j�\}}|j�|�dSr)rBr2rr�r�r
)r�objectr�r�rrrr��	s
z!UnicodeOrBytesToBytesWriter.writeN)r)rrrrzrr�rrrrr�	s
r�rcCs�d|v}d|v}d|v}d|v}t}|r2|tO}n|tO}|rj|rN|tjO}n
|tjO}|tjtjBO}nJ|r�|r~|tjO}n
|tjO}|tjtjBO}n|r�|tjO}n
|tj	O}t�
t�||�||�S)a
This function is used to override the ``open`` builtin.

        But it uses O_NOINHERIT flag so the file handle is not inherited by
        child processes.  Deleting or renaming a closed file opened with this
        function is not blocking child processes.
        �wrrar�)r
rrr(�O_RDWR�O_WRONLY�O_CREAT�O_TRUNC�O_APPENDr��fdopenr�)r/r=�bufsizeZwritingZ	appendingZupdatingZbinary�flagsrrr�	open_file�	s,



rcCs2d}d||f}||�r.|d7}d||f}q|S)a�Find a non-existing backup file name.

    This will *not* create anything, this only return a 'free' entry.  This
    should be used for checking names in a directory below a locked
    tree/branch/repo to avoid race conditions. This is LBYL (Look Before You
    Leap) and generally discouraged.

    :param base: The base name.

    :param exists: A callable returning True if the path parameter exists.
    rz%s.~%d~r)rwr�Zcounterr�rrr�available_backup_name�	sr c	CsLz0ddl}|�||j�}|�||j||jB�WnttfyFYn0dS)zqSet a Unix file descriptor's FD_CLOEXEC flag.  Do nothing if platform
    support for this is not available.
    rN)r�ZF_GETFDZF_SETFDZ
FD_CLOEXECr�r�)rr�rsrrr�set_fd_cloexec�	sr!cCs�tjdkrbtj�dd��tj�}dd�|D�}tj�|�\}}|dkrh|�	�|vrVdS|}|g}ndg}tj�d�}|dur�|�tj�}|D]:}|D]0}tj�
||�|}t�|tj�r�|Sq�q�tjdkr�t
�|�}||kr�|SdS)a.Finds an executable on the PATH.

    On Windows, this will try to append each extension in the PATHEXT
    environment variable to the name, if it cannot be found with the name
    as given.

    :param name: The base name of the executable.
    :return: The path to the executable found or None.
    r�ZPATHEXTr^cSsg|]}|���qSr)rr)r�extrrrr�	rz+find_executable_on_path.<locals>.<listcomp>N�PATH)rrEr(r�r�rD�pathseprF�splitextrrr{�access�X_OKr�Zget_app_path)r�Zextsrwr"rFr�rXZapp_pathrrr�find_executable_on_path�	s.



r(c
Cs�zt�|d�Wnxty�}z`|jtjkr:WYd}~dS|jtjkrTWYd}~dSt�d||f�WYd}~dSWYd}~nd}~00dSdS)z>True if pid doesn't correspond to live process on this machinerNTFzos.kill(%d, 0) failed: %s)r(�killr7r4ZESRCHr9r;r<)�pidr>rrr�_posix_is_local_pid_dead
s$r+)ZEAGAINr�ZENOTSUPZ
EOPNOTSUPPr:cCs&g|]}tt|d�durtt|��qSr)r8r4)rr�rrrr
s�c
Cstttdttdd��}|durpz||�WnFtyn}z.t�d|f�t|dd�tvrZ�WYd}~n
d}~00dS)z�Flush file contents to disk if possible.

    :param fileno: Integer OS file handle.
    :raises TransportNotPossible: If flushing to disk is not possible.
    �	fdatasync�fsyncNz$ignoring error calling fdatasync: %sr4)r8r(r6r;r<�_fdatasync_ignored)r�fnr>rrrr,#
sr,c
Cs\zt�|�WnHtyV}z0|jtjkr,�t�|�gkrB||��WYd}~n
d}~00dS)z�Make sure a local directory exists and is empty.

    If it does not exist, it is created.  If it exists and is not empty, an
    instance of exception_class is raised.
    N)r(r�r7r4ZEEXISTra)rFZexception_classr>rrr�ensure_empty_directory_exists7
sr0cCs0t|ttjf�rdStjdkr,t�|�r,dSdS)z�True if exception instance is due to a process environment issue

    This includes OSError and IOError, but also other errors that come from
    the operating system or core libraries but are not subclasses of those.
    Tr�F)rB�EnvironmentErrorZselectr�rrEr�Z_is_pywintypes_error)Zevaluerrr�is_environment_errorF
s
r2ccstt|d��V}|D]@}|�d�r q|��}t|�dkr6q|d|d�dd�fVqWd�n1sf0YdS)	z�Read an fstab-style file and extract mountpoint+filesystem information.

    :param path: Path to read from
    :yield: Tuples with mountpoints (as bytestrings) and filesystem names
    �rb�#r�rr?r�r�N)r�r�rDrJr)rFrXr>Zcolsrrr�	read_mtabS
s
r5z	/etc/mtabc@s,eZdZdZdd�Zedd��Zdd�ZdS)	�FilesystemFinderz*Find the filesystem for a particular path.cCsdd�}t||dd�|_dS)NcSst|d�Sr�)rJ)r�rrrrHi
sz&FilesystemFinder.__init__.<locals>.keyT)rH�reverse)rL�_mountpoints)rZmountpointsrHrrrrh
szFilesystemFinder.__init__c
CsLz|tt��WStyF}z t�d|�|g�WYd}~Sd}~00dS)z�Create a FilesystemFinder from an mtab-style file.

        Note that this will silenty ignore mtab if it doesn't exist or can not
        be opened.
        zUnable to read mtab: %sN)r5�	MTAB_PATHr1r;r<)�clsr>rrr�	from_mtabm
s
	zFilesystemFinder.from_mtabcCs&|jD]\}}t||�r|SqdS)z�Find the filesystem used by a particular path.

        :param path: Path to find (bytestring or text type)
        :return: Filesystem name (as text type) or None, if the filesystem is
            unknown.
        N)r8rN)rrFZ
mountpointZ
filesystemrrr�find|
s

zFilesystemFinder.findN)rrrrzr�classmethodr;r<rrrrr6e
s

r6cCs.tdurt��at|t�s$|�t�}t�|�S)z�Return the filesystem type for the partition a path is in.

    :param path: Path to search filesystem type for
    :return: A FS type, as string. E.g. "ext2"
    N)�_FILESYSTEM_FINDERr6r;rBrCr�r	r<rErrrr��
s


r�)F)rIr�Nr�)N)r�)N)rrNT)rrNT)T)r^)r^)N)N)T)rrI)�Z
__future__rr4r(rTr+rrkr�r�globalsZsixishrrZhashlibrrr�r�r^r	r
r8rrr
r#rr&r1r3r-rQrSrYr�r\rbrerFrfrxr~r�r}r�r�r�r�r�r�r�r�r�r�r�r�r��version_infor|r�Zgetcwdur�r�rr{rnr�Zpath_from_environZ
_get_home_dirZgetuser_unicoderjrirDr%r)rr�r[rEr�r�r�r�r�r�Zget_environ_unicodeZget_home_locationZ
get_user_namer�r�r�r�r�rNr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrZ
_offset_cacherrrrrr�urandomr%rr�r'rmr,r-r1r3r4r7Z_chunks_to_lines_pyxr8r>Z_chunks_to_lines_pyr;r9rFrJrLrKrNrOrPrQrYrZr`rfrgrirjrnrprtrurvrwryr{Znormalized_filenamer�Zdefault_terminal_widthr�r�r�r�r�r�r�r�r�r�rUr�r�r�r�r�rr�r�r�r�r�r�r�r�r�r!r�r�r�Z
ECONNRESETZEPIPEr�r�Z_enorOr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrr�r r!r(r+Zis_local_pid_deadZ_maybe_ignoredr.r,r0r2r5r9r6r>r��perf_counterZclockrrrr�<module>s0	�	

I



5�
0

�
�
�
2		"
"

	&5
	$U
	

B38*/


�"
(
$

$