U ��.e���@s�ddlZddlmZddlZddlZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZz ddlZWnek r�dZYnXddlZddlZddlZddlZddlZz ddlZWnek r�ddlZYnXddlZddlmZddlmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0e �1e2�Z3e �4d�Z5e �4d�Z6e �4d �Z7e �4d �Z8e �4d �Z9e �4d �Z:e �4d �Z;e �4d�Zdd�Z?dd�Z@dd�ZAd�dd�ZBdd�ZCdd�ZDdd �ZEejFd!d"��ZGejFd#d$��ZHejFd�d&d'��ZIGd(d)�d)eJ�ZKd*d+�ZLGd,d-�d-eJ�ZMd.d/�ZNGd0d1�d1eJ�ZOe �4d2e jP�ZQd3d4�ZRd�d5d6�ZSd7d8�ZTd9d:�ZUd;d<�ZVd=d>�ZWd?d@�ZXe �4dAe jY�ZZe �4dB�Z[d�dCdD�Z\e �4dE�Z]dFdG�Z^dHdI�Z_dJdK�Z`dLZadMdN�ZbdOdP�ZcGdQdR�dReJ�ZdGdSdT�dTeJ�ZeGdUdV�dVeJ�ZfdWZgd�dYdZ�Zhd[d\�Zid]ZjGd^d_�d_eJ�Zke �4d`�Zle �4da�Zme �4db�Zndcdd�Zdedf�Zoe�r�ddglmpZqmrZrmsZsGdhdi�die$jt�ZtGdjdk�dkeq�ZpGdldm�dmepe'�Zuejvddn�Zwewdok�rGdpdq�dqe$jx�Zxe�rGdrds�dse$jy�ZyGdtdu�due%jz�Zze�rBGdvdw�dwe%j{�Z{Gdxdy�dye%j|�Z|dzd{�Z}Gd|d}�d}eJ�Z~Gd~d�de~�ZGd�d��d�e~�Z�Gd�d��d�e(�Z�Gd�d��d�eJ�Z�d�d��Z�dS)��N)�deque)�iglob�)�DistlibException)� string_types� text_type�shutil� raw_input�StringIO�cache_from_source�urlopen�urljoin�httplib� xmlrpclib� splittype� HTTPHandler�BaseConfigurator� valid_ident� Container� configparser�URLError�ZipFile�fsdecode�unquote�urlparsez^([\w\.-]+)\s*z^([\w\.*+-]+)\s*z^(<=?|>=?|={2,3}|[~!]=)\s*z*^((<=?)|(>=?)|={2,3}|[~!]=|in|not\s+in)\s*z^or\b\s*z ^and\b\s*z(\S+)\s*z(([\s\w\.{}()*+#:;,/?!~`@$%^&=|<>\[\]-]+)cs6dd����fdd���fdd���fdd���|�S) ae Parse a marker string and return a dictionary containing a marker expression. The dictionary will contain keys "op", "lhs" and "rhs" for non-terminals in the expression grammar, or strings. A string contained in quotes is to be interpreted as a literal string, and a string not contained in quotes is a variable (such as os_name). cSs.t�|�}|r,|��d}||��d�}n�|s:td��n�|d}|dkrVtd|��d�|d�}|dd�}|g}|r�|d|kr��qqt|d|kr�|�|�|dd�}qtt�|�}|s�td|��|�|��d�||��d�}qtd�|�}td|��|�|�d�|�}|dd�� �}||fS) Nrzunexpected end of inputz'"zinvalid expression: %s�rzerror in string literal: %szunterminated string: %s) � IDENTIFIER�match�groups�end� SyntaxError�replace�append� STRING_CHUNK�join�lstrip)� remaining�m�result�qZoq�parts�s�r,�.marker_varcs�|rR|ddkrR�|dd����\}}|ddkr@td|��|dd���}nZ�|�\}}|r�t�|�}|srq�|��d}||��d�}�|�\}}|||d�}q^|}||fS)Nr�(r�)�unterminated parenthesis: %s��op�lhs�rhs)r%r � MARKER_OPrrr)r&r(r4r'r3r5)�markerr.r,r-� marker_expres       z!parse_marker..marker_exprcsR�|�\}}|rJt�|�}|s qJ||��d�}�|�\}}d||d�}q ||fS)N�andr2)�ANDrr�r&r4r'r5)r8r,r-� marker_andxs   z parse_marker..marker_andcsR�|�\}}|rJt�|�}|s qJ||��d�}�|�\}}d||d�}q ||fS)N�orr2)�ORrrr;)r<r,r-r7�s   zparse_marker..markerr,)Z marker_stringr,)r7r<r8r.r-� parse_marker8s $ r?cCs0|��}|r|�d�rdSt�|�}|s4td|��|��d}||��d�}d}}}}|�r:|ddk�r:|�dd�}|dkr�td|��|d|�} ||dd���}g}| �r0t�| �}|s�td | ��|� |��d�| |��d�} | �s�q0| dd k�rtd | ��| dd���} q�|�s:d}|�r�|dd k�r�|dd���}t �|�}|�sztd |��|��d}t |�} | j �r�| j �s�td|��||��d���}n�dd�} |ddk�r�| |�\}}n�|�dd�}|dk�rtd|��|d|�} ||dd���}t�| ��r@| | �\}} nXt�| �}|�s\td| ��|��d} | |��d���} | �r�td| ��d| fg}|�r�|ddk�r�td|��|dd���}t|�\}}|�r�|ddk�r�td|��|�s|}nd|d�dd�|D��f}t||||||d�S)z� Parse a requirement passed in as a string. Return a Container whose attributes contain the various parts of the requirement. �#Nzname expected: %sr�[�]rzunterminated extra: %szmalformed extra: %s�,zcomma expected in extras: %s�@zinvalid URI: %szInvalid URL: %scSs�t�|�}d}|r�g}|��d}||��d�}t�|�}|sLtd|��|��d}|�||f�||��d�}|r�|ddkr�q�|dd���}t�|�}|std|��q|s�d}||fS)z| Return a list of operator, version tuples if any are specified, else None. Nrzinvalid version: %srCr�invalid constraint: %s)� COMPARE_OPrrr�VERSION_IDENTIFIERr r"r%)Z ver_remainingr'�versionsr3�vr,r,r-� get_versions�s*      z'parse_requirement..get_versionsr/r0r1rEz~=�;zinvalid requirement: %szunexpected trailing data: %s�%s %s�, cSsg|] }d|�qS)rLr,)�.0Zconr,r,r-� sz%parse_requirement..)�name�extrasZ constraintsr7�urlZ requirement)�strip� startswithrrr rr�findr%r"� NON_SPACEr�scheme�netlocrFrGr?r$r)�reqr&r'ZdistnamerQZ mark_exprrH�uri�ir+�trJ�_rIZrsr,r,r-�parse_requirement�s�                          �r^cCs�dd�}i}|D]�\}}}tj�||�}t|�D]p}tj�||�} t| �D]T} ||| �} |dkrn|�| d�qJ||| �} |�tjjd��d�} | d| || <qJq0q|S)z%Find destinations for resources filescSsD|�tjjd�}|�tjjd�}|�|�s.t�|t|�d��d�S�N�/)r!�os�path�seprT�AssertionError�lenr%)�rootrbr,r,r-� get_rel_path sz)get_resources_dests..get_rel_pathNr`)rarbr$r�popr!rc�rstrip)Zresources_rootZrulesrgZ destinations�base�suffix�dest�prefixZabs_baseZabs_globZabs_pathZ resource_fileZrel_pathZrel_destr,r,r-�get_resources_dests s    rncCs(ttd�rd}ntjttdtj�k}|S)NZ real_prefixT� base_prefix)�hasattr�sysrm�getattr�r(r,r,r-�in_venv$s rtcCs$tj�tj�}t|t�s t|�}|S�N)rarb�normcaserq� executable� isinstancerrrsr,r,r-�get_executable.s  rycCsN|}t|�}|}|s|r|}|r|d��}||kr6qJ|rd|||f}q|S)Nrz %c: %s %s)r �lower)�promptZ allowed_charsZ error_prompt�default�pr+�cr,r,r-�proceed>s rcCs8t|t�r|��}i}|D]}||kr||||<q|Sru)rxr�split)�d�keysr(�keyr,r,r-�extract_by_keyNs r�cCsztjddkrt�d�|�}|��}t|�}zlt�|�}|ddd}|��D]B\}}|��D]0\}}d||f}t |�} | dk s�t �| ||<q`qP|WSt k r�|� dd�YnXdd �} t ��} z| | |�Wn<t jk �r|��t�|�}t|�}| | |�YnXi}| ��D]R} i|| <}| �| �D]4\} }d| |f}t |�} | dk �sft �| || <�q<�q"|S) Nr��utf-8� extensionszpython.exports�exportsz%s = %scSs$t|d�r|�|�n |�|�dS)N� read_file)rpr�Zreadfp)�cp�streamr,r,r-� read_streamks  z!read_exports..read_stream)rq� version_info�codecs� getreader�readr �json�load�items�get_export_entryrd� Exception�seekr� ConfigParserZMissingSectionHeaderError�close�textwrap�dedentZsections)r��dataZjdatar(�group�entries�krIr+�entryr�r�r�rP�valuer,r,r-� read_exportsWsD        r�cCs�tjddkrt�d�|�}t��}|��D]l\}}|�|�|��D]P}|j dkr\|j }nd|j |j f}|j r�d|d� |j �f}|� ||j|�qFq,|�|�dS)Nrr�r�z%s:%sz%s [%s]rM)rqr�r�� getwriterrr�r�Z add_section�valuesrkrm�flagsr$�setrP�write)r�r�r�r�rIr�r+r,r,r-� write_exports�s   r�c cs$t��}z |VW5t�|�XdSru)�tempfile�mkdtempr�rmtree)Ztdr,r,r-�tempdir�s r�c cs.t��}zt�|�dVW5t�|�XdSru)ra�getcwd�chdir)r��cwdr,r,r-r��s   r��c cs.t��}zt�|�dVW5t�|�XdSru)�socketZgetdefaulttimeoutZsetdefaulttimeout)ZsecondsZctor,r,r-�socket_timeout�s   r�c@seZdZdd�Zddd�ZdS)�cached_propertycCs ||_dSru)�func)�selfr�r,r,r-�__init__�szcached_property.__init__NcCs,|dkr |S|�|�}t�||jj|�|Sru)r��object� __setattr__�__name__)r��obj�clsr�r,r,r-�__get__�s  zcached_property.__get__)N)r�� __module__� __qualname__r�r�r,r,r,r-r��sr�cCs~tjdkr|S|s|S|ddkr.td|��|ddkrFtd|��|�d�}tj|krh|�tj�qP|srtjStjj|�S)a�Return 'pathname' as a name that will work on the native filesystem. The path is split on '/' and put back together again using the current directory separator. Needed because filenames in the setup script are always supplied in Unix style, and have to be converted to the local convention before we can actually use them in the filesystem. Raises ValueError on non-Unix-ish systems if 'pathname' either starts or ends with a slash. r`rzpath '%s' cannot be absolute�����zpath '%s' cannot end with '/')rarc� ValueErrorr��curdir�removerbr$)�pathname�pathsr,r,r-� convert_path�s       r�c@s�eZdZd$dd�Zdd�Zdd�Zdd �Zd%d d �Zd&dd�Zdd�Z dd�Z dd�Z dd�Z dd�Z d'dd�Zdd�Zdd�Zd d!�Zd"d#�Zd S)(� FileOperatorFcCs||_t�|_|��dSru)�dry_runr��ensured� _init_record)r�r�r,r,r-r��szFileOperator.__init__cCsd|_t�|_t�|_dS�NF)�recordr�� files_written� dirs_created�r�r,r,r-r��szFileOperator._init_recordcCs|jr|j�|�dSru)r�r��add)r�rbr,r,r-�record_as_written�szFileOperator.record_as_writtencCsHtj�|�s tdtj�|���tj�|�s0dSt�|�jt�|�jkS)a�Tell if the target is newer than the source. Returns true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Returns false if both exist and 'target' is the same age or younger than 'source'. Raise PackagingFileError if 'source' does not exist. Note that this test is not very accurate: files created in the same second will have the same "age". zfile '%r' does not existT)rarb�existsr�abspath�stat�st_mtime)r��source�targetr,r,r-�newer�s  � zFileOperator.newerTcCs�|�tj�|��t�d||�|js�d}|rdtj�|�rDd|}n tj�|�rdtj� |�sdd|}|rtt |d��t � ||�|� |�dS)z8Copy a file respecting dry-run and force flags. zCopying %s to %sNz%s is a symlinkz%s is a non-regular filez which would be overwritten)� ensure_dirrarb�dirname�logger�infor��islinkr��isfiler�rZcopyfiler�)r�Zinfile�outfile�check�msgr,r,r-� copy_files    zFileOperator.copy_fileNcCs�tj�|�rt�|�tj�|��t�d||�|jsv|dkrJt |d�}nt j |d|d�}zt � ||�W5|� �X|�|�dS)NzCopying stream %s to %s�wb�w��encoding)rarb�isdirrdr�r�r�r�r��openr�r�rZ copyfileobjr�)r�Zinstreamr�r�Z outstreamr,r,r-� copy_streams  zFileOperator.copy_streamc Cs\|�tj�|��|jsNtj�|�r.t�|�t|d��}|�|�W5QRX|� |�dS)Nr�) r�rarbr�r�r�r�r�r�r�)r�rbr��fr,r,r-�write_binary_file!s   zFileOperator.write_binary_filecCs|�||�|��dSru)r��encode)r�rbr�r�r,r,r-�write_text_file*szFileOperator.write_text_filecCsntjdkstjdkrjtjdkrj|D]F}|jr:t�d|�q"t�|�j|B|@}t�d||�t�||�q"dS)N�posix�javazchanging mode of %szchanging mode of %s to %o) rarP�_namer�r�r�r��st_mode�chmod)r��bits�mask�filesr��moder,r,r-�set_mode-szFileOperator.set_modecCs|�dd|�S)Nimi�)r�)r+r�r,r,r-�9�zFileOperator.cCs|tj�|�}||jkrxtj�|�sx|j�|�tj�|�\}}|�|�t� d|�|j sft� |�|j rx|j �|�dS)Nz Creating %s)rarbr�r�r�r�r�r�r�r�r��mkdirr�r�)r�rbr�r�r,r,r-r�;s    zFileOperator.ensure_dirc Cs�t|| �}t�d||�|js�|s0|�||�rX|s:d}n|�|�sHt�|t|�d�}i}|rvtt d�rvt j j |d<t j |||df|�|� |�|S)NzByte-compiling %s to %s�PycInvalidationMode�invalidation_modeT)r r�r�r�r�rTrdrerp� py_compiler�� CHECKED_HASH�compiler�) r�rb�optimize�forcermZhashed_invalidationZdpathZdiagpathZcompile_kwargsr,r,r-� byte_compileGs   zFileOperator.byte_compilecCs�tj�|�r�tj�|�r^tj�|�s^t�d|�|js@t� |�|j r�||j kr�|j � |�nPtj�|�rpd}nd}t�d||�|js�t� |�|j r�||j kr�|j � |�dS)NzRemoving directory tree at %s�link�filezRemoving %s %s)rarbr�r�r�r��debugr�rr�r�r�r�r�)r�rbr+r,r,r-�ensure_removedXs"       zFileOperator.ensure_removedcCsDd}|s@tj�|�r$t�|tj�}q@tj�|�}||kr:q@|}q|Sr�)rarbr��access�W_OKr�)r�rbr(�parentr,r,r-� is_writablems  zFileOperator.is_writablecCs"|js t�|j|jf}|��|S)zV Commit recorded changes, turn off recording, return changes. )r�rdr�r�r�)r�r(r,r,r-�commitys  zFileOperator.commitcCs�|js�t|j�D]}tj�|�rt�|�qt|jdd�}|D]F}t� |�}|rz|dgks^t �tj� ||d�}t� |�t� |�q>|� �dS)NT)�reverse� __pycache__r)r��listr�rarbr�r��sortedr��listdirrdr$�rmdirr�)r�r��dirsr��flistZsdr,r,r-�rollback�s     zFileOperator.rollback)F)T)N)FFNF)r�r�r�r�r�r�r�r�r�r�r�r�Zset_executable_moder�rrrr rr,r,r,r-r��s         r�cCs^|tjkrtj|}nt|�}|dkr,|}n.|�d�}t||�d��}|D]}t||�}qJ|S)N�.r)rq�modules� __import__r�rrrh)Z module_nameZ dotted_path�modr(r*r}r,r,r-�resolve�s    rc@s6eZdZdd�Zedd��Zdd�Zdd�Zej Z d S) � ExportEntrycCs||_||_||_||_dSru�rPrmrkr�)r�rPrmrkr�r,r,r-r��szExportEntry.__init__cCst|j|j�Sru)rrmrkr�r,r,r-r��szExportEntry.valuecCsd|j|j|j|jfS)Nzrr�r,r,r-�__repr__�s �zExportEntry.__repr__cCsDt|t�sd}n0|j|jko>|j|jko>|j|jko>|j|jk}|Sr�)rxrrPrmrkr�)r��otherr(r,r,r-�__eq__�s   � � �zExportEntry.__eq__N) r�r�r�r�r�r�rrr��__hash__r,r,r,r-r�s   rz�(?P(\w|[-.+])+) \s*=\s*(?P(\w+)([:\.]\w+)*) \s*(\[\s*(?P\w+(=\w+)?(,\s*\w+(=\w+)?)*)\s*\])? c Cs�t�|�}|s0d}d|ks"d|kr�td|��n�|��}|d}|d}|�d�}|dkrf|d}}n"|dkrztd|��|�d�\}}|d } | dkr�d|ks�d|kr�td|��g} nd d �| �d �D�} t|||| �}|S) NrArBzInvalid specification '%s'rP�callable�:rrr�cSsg|] }|���qSr,)rS)rNr�r,r,r-rO�sz$get_export_entry..rC)�ENTRY_RE�searchr� groupdict�countr�r) Z specificationr'r(r�rPrbZcolonsrmrkr�r,r,r-r��s8 �  ��r�cCs�|dkr d}tjdkr.dtjkr.tj�d�}n tj�d�}tj�|�rft�|tj�}|s�t � d|�n|�dd�\}}d|kr.|}n|�dd�\}}|rJt|�}|rVt|�}|||fS)NrDrr)�rsplitr�r)rXZusernameZpasswordrmr,r,r-�parse_credentials$sr3cCst�d�}t�|�|S)N�)ra�umaskrsr,r,r-�get_process_umask3s  r6cCs<d}d}t|�D]\}}t|t�sd}q,q|dk s8t�|S)NTF)� enumeraterxrrd)�seqr(r[r+r,r,r-�is_string_sequence8s  r9z3([a-z0-9_]+([.-][a-z_][a-z0-9_]*)*)-([a-z0-9_.+-]+)z -py(\d\.?\d?)cCs�d}d}t|��dd�}t�|�}|r@|�d�}|d|���}|r�t|�t|�dkr�t�t� |�d|�}|r�|� �}|d|�||dd�|f}|dkr�t �|�}|r�|�d�|�d�|f}|S)zw Extract name, version, python version from a filename (no extension) Return name, version, pyver or None N� �-rz\br�) rr!�PYTHON_VERSIONr!r��startre�rer�escaper�PROJECT_NAME_AND_VERSION)�filenameZ project_namer(Zpyverr'�nr,r,r-�split_filenameGs"   rCz-(?P[\w .-]+)\s*\(\s*(?P[^\s)]+)\)$cCs:t�|�}|std|��|��}|d����|dfS)z� A utility method used to get name and version from a string. From e.g. a Provides-Dist value. :param p: A value in a form 'foo (1.0)' :return: The name and version as a tuple. z$Ill-formed name/version string: '%s'rPZver)�NAME_VERSION_RErrr"rSrz)r}r'r�r,r,r-�parse_name_and_versioncs  rEcCs�t�}t|pg�}t|pg�}d|kr8|�d�||O}|D]x}|dkrT|�|�q<|�d�r�|dd�}||kr�t�d|�||kr�|�|�q<||kr�t�d|�|�|�q<|S)N�*r;rzundeclared extra: %s)r�r�r�rTr�r*)Z requestedZ availabler(�rZunwantedr,r,r-� get_extrasrs&        rHc Cs�i}zNt|�}|��}|�d�}|�d�s8t�d|�nt�d�|�}t� |�}Wn0t k r�}zt� d||�W5d}~XYnX|S)Nz Content-Typezapplication/jsonz(Unexpected response for JSON request: %sr�z&Failed to get external data for %s: %s) r r��getrTr�rr�r�r�r�r�� exception)rRr(ZrespZheadersZct�reader�er,r,r-�_get_external_data�s   rMz'https://www.red-dove.com/pypi/projects/cCs*d|d��|f}tt|�}t|�}|S)Nz%s/%s/project.jsonr��upperr �_external_data_base_urlrM)rPrRr(r,r,r-�get_project_data�s rQcCs(d|d��||f}tt|�}t|�S)Nz%s/%s/package-%s.jsonrrN)rP�versionrRr,r,r-�get_package_data�s rSc@s(eZdZdZdd�Zdd�Zdd�ZdS) �Cachez� A class implementing a cache for resources that need to live in the file system e.g. shared libraries. This class was moved from resources to here because it could be used by other modules, e.g. the wheel module. cCsPtj�|�st�|�t�|�jd@dkr6t�d|�tj�tj� |��|_ dS)zu Initialise an instance. :param base: The base directory where the cache should be located. �?rzDirectory '%s' is not privateN) rarbr�r+r�r�r�r*r��normpathrj)r�rjr,r,r-r��s    zCache.__init__cCst|�S)zN Converts a resource prefix to a directory name in the cache. )r/)r�rmr,r,r-� prefix_to_dir�szCache.prefix_to_dirc Cs�g}t�|j�D]r}tj�|j|�}z>tj�|�s>tj�|�rJt�|�ntj�|�r`t � |�Wqt k r�|� |�YqXq|S)z" Clear the cache. ) rarrjrbr$r�r�r�r�rr�r�r")r�Z not_removed�fnr,r,r-�clear�s  z Cache.clearN)r�r�r��__doc__r�rWrYr,r,r,r-rT�srTc@s:eZdZdZdd�Zddd�Zdd�Zd d �Zd d �Zd S)� EventMixinz1 A very simple publish/subscribe system. cCs i|_dSru)� _subscribersr�r,r,r-r��szEventMixin.__init__TcCsD|j}||krt|g�||<n"||}|r6|�|�n |�|�dS)a` Add a subscriber for an event. :param event: The name of an event. :param subscriber: The subscriber to be added (and called when the event is published). :param append: Whether to append or prepend the subscriber to an existing subscriber list for the event. N)r\rr"� appendleft)r��event� subscriberr"�subsZsqr,r,r-r��s  zEventMixin.addcCs,|j}||krtd|��||�|�dS)z� Remove a subscriber for an event. :param event: The name of an event. :param subscriber: The subscriber to be removed. zNo subscribers: %rN)r\r�r�)r�r^r_r`r,r,r-r��s zEventMixin.removecCst|j�|d��S)z� Return an iterator for the subscribers for an event. :param event: The event to return subscribers for. r,)�iterr\rI)r�r^r,r,r-�get_subscribersszEventMixin.get_subscribersc Oslg}|�|�D]F}z||f|�|�}Wn"tk rHt�d�d}YnX|�|�qt�d||||�|S)a^ Publish a event and return a list of values returned by its subscribers. :param event: The event to publish. :param args: The positional arguments to pass to the event's subscribers. :param kwargs: The keyword arguments to pass to the event's subscribers. z"Exception during event publicationNz/publish %s: args = %s, kwargs = %s, result = %s)rbr�r�rJr"r)r�r^�args�kwargsr(r_r�r,r,r-�publishs    �zEventMixin.publishN)T) r�r�r�rZr�r�r�rbrer,r,r,r-r[�s   r[c@s^eZdZdd�Zdd�Zddd�Zdd �Zd d �Zd d �Zdd�Z e dd��Z e dd��Z dS)� SequencercCsi|_i|_t�|_dSru)�_preds�_succsr��_nodesr�r,r,r-r�"szSequencer.__init__cCs|j�|�dSru)rir��r��noder,r,r-�add_node'szSequencer.add_nodeFcCs�||jkr|j�|�|r�t|j�|d��D]}|�||�q,t|j�|d��D]}|�||�qPt|j���D]\}}|sp|j|=qpt|j���D]\}}|s�|j|=q�dS)Nr,)rir�r�rgrIrhr r�)r�rkZedgesr}r+r�rIr,r,r-� remove_node*s   zSequencer.remove_nodecCs<||ks t�|j�|t���|�|j�|t���|�dSru)rdrg� setdefaultr�r�rh)r��pred�succr,r,r-r�:s z Sequencer.addcCs�||ks t�z|j|}|j|}Wn tk rDtd|��YnXz|�|�|�|�Wn$tk r�td||f��YnXdS)Nz%r not a successor of anythingz%r not a successor of %r)rdrgrh�KeyErrorr�r�)r�rorp�predsZsuccsr,r,r-r�?s   zSequencer.removecCs||jkp||jkp||jkSru)rgrhri)r��stepr,r,r-�is_stepLs�zSequencer.is_stepcCs�|�|�std|��g}g}t�}|�|�|r�|�d�}||krb||kr�|�|�|�|�q.|�|�|�|�|j�|d�}|� |�q.t |�S)Nz Unknown: %rrr,) rtr�r�r"rhr�r�rgrI�extend�reversed)r��finalr(Ztodo�seenrsrrr,r,r-� get_stepsPs"         zSequencer.get_stepscsRdg�g�i�i�g�|j��������fdd���D]}|�kr8�|�q8�S)Nrcs��d�|<�d�|<�dd7<��|�z �|}Wntk rVg}YnX|D]J}|�kr��|�t�|�|��|<q\|�kr\t�|�|��|<q\�|�|kr�g}���}|�|�||kr�q�q�t|�}��|�dS)Nrr)r"r��minrh�tuple)rkZ successorsZ successorZconnected_componentZ component�Zgraph�indexZ index_counterZlowlinksr(�stack� strongconnectr,r-rts,      z3Sequencer.strong_connections..strongconnect)rhrjr,r|r-�strong_connectionsis" zSequencer.strong_connectionscCsfdg}|jD]*}|j|}|D]}|�d||f�qq |jD]}|�d|�q>|�d�d�|�S)Nz digraph G {z %s -> %s;z %s;�}� )rgr"rir$)r�r(rprrrorkr,r,r-�dot�s    z Sequencer.dotN)F) r�r�r�r�rlrmr�r�rtry�propertyr�r�r,r,r,r-rf!s   2rf)�.tar.gz�.tar.bz2�.tar�.zip�.tgz�.tbz�.whlTc sZ��fdd�}tj����t���d}|dkr�|�d�r>d}nH|�d�rRd}d}n4|�d�rfd }d }n |�d �rzd }d }n td|��z�|dkr�t|d �}|r�|��}|D] }||�q�n*t � ||�}|r�|� �}|D] }||�q�|dk�r*t j ddk�r*|��D]"} t| jt��s| j�d�| _�qdd�} | |_|���W5|�rT|��XdS)NcsRt|t�s|�d�}tj�tj��|��}|���rB|�tjkrNt d|��dS)Nr�zpath outside destination: %r) rxr�decoderarbr�r$rTrcr�)rbr}��dest_dirZplenr,r-� check_path�s   zunarchive..check_path)r�r��zip)r�r�Ztgzzr:gz)r�r�Ztbzzr:bz2r�ZtarrGzUnknown format for %rrr�r�c SsDzt�||�WStjk r>}ztt|���W5d}~XYnXdS)z:Run tarfile.tar_fillter, but raise the expected ValueErrorN)�tarfileZ tar_filterZ FilterErrorr��str)�memberrb�excr,r,r-�extraction_filter�sz$unarchive..extraction_filter)rarbr�rer0r�r�rZnamelistr�r�Zgetnamesrqr�Z getmembersrxrPrr�r�Z extractall) Zarchive_filenamer��formatr�r��archiver��namesrPZtarinfor�r,r�r-� unarchive�sL           r�c Cs~t��}t|�}t|d��Z}t�|�D]H\}}}|D]8}tj�||�}||d�} tj�| |�} |�|| �q4q&W5QRX|S)z*zip a directory tree into a BytesIO objectr�N) �io�BytesIOrerra�walkrbr$r�) Z directoryr(ZdlenZzfrfrr�rPZfullZrelrlr,r,r-�zip_dir�s  r�)r�K�M�G�T�Pc@sreZdZdZddd�Zdd�Zdd �Zd d �Zd d �Ze dd��Z e dd��Z dd�Z e dd��Z e dd��ZdS)�ProgressZUNKNOWNr�dcCs<|dks||kst�||_|_||_d|_d|_d|_dS)NrF)rdrz�cur�max�started�elapsed�done)r�ZminvalZmaxvalr,r,r-r� s  zProgress.__init__cCsV|j|kst�|jdks&||jks&t�||_t��}|jdkrF||_n ||j|_dSru)rzrdr�r��timer�r�)r�ZcurvalZnowr,r,r-�updates zProgress.updatecCs |dks t�|�|j|�dS�Nr)rdr�r�)r�Zincrr,r,r-� increments zProgress.incrementcCs|�|j�|Sru)r�rzr�r,r,r-r=s zProgress.startcCs |jdk r|�|j�d|_dS)NT)r�r�r�r�r,r,r-�stop#s  z Progress.stopcCs|jdkr|jS|jSru)r��unknownr�r,r,r-�maximum(szProgress.maximumcCsD|jr d}n4|jdkrd}n$d|j|j|j|j}d|}|S)Nz100 %z ?? %gY@z%3d %%)r�r�r�rz)r�r(rIr,r,r-� percentage,s zProgress.percentagecCs:|dkr|jdks|j|jkr$d}nt�dt�|��}|S)Nrz??:??:??z%H:%M:%S)r�r�rzr��strftime�gmtime)r�Zdurationr(r,r,r-�format_duration7szProgress.format_durationcCs�|jrd}|j}n^d}|jdkr&d}nJ|jdks<|j|jkrBd}n.t|j|j�}||j|j}|d|j}d||�|�fS)NZDonezETA r�rrz%s: %s)r�r�r�r�rz�floatr�)r�rmr\r,r,r-�ETA@s z Progress.ETAcCsL|jdkrd}n|j|j|j}tD]}|dkr6q@|d}q&d||fS)Nrgi�g@�@z%d %sB/s)r�r�rz�UNITS)r�r(Zunitr,r,r-�speedSs  zProgress.speedN)rr�)r�r�r�r�r�r�r�r=r�r�r�r�r�r�r�r,r,r,r-r�s      r�z \{([^}]*)\}z[^/\\,{]\*\*|\*\*[^/\\,}]z^[^{]*\}|\{[^}]*$cCs<t�|�rd}t||��t�|�r4d}t||��t|�S)zAExtended globbing function that supports ** and {opt1,opt2,opt3}.z7invalid glob %r: recursive glob "**" must be used alonez2invalid glob %r: mismatching set marker '{' or '}')�_CHECK_RECURSIVE_GLOBr!r��_CHECK_MISMATCH_SET�_iglob)� path_globr�r,r,r-rhs    rc cst�|d�}t|�dkrht|�dks,t|��|\}}}|�d�D]$}td�|||f��D] }|VqXq@n�d|kr�t|�D] }|Vqxn~|�dd�\}}|dkr�d}|dkr�d}n|�d�}|�d �}t� |�D]4\}}} tj � |�}ttj �||��D] } | Vq�q�dS) Nrr�rCrz**rrFr`�\) � RICH_GLOBr�rerdr�r$� std_iglobr%rar�rbrV) r�Zrich_path_globrmr�rk�itemrbZradical�dirr�rXr,r,r-r�ss*         r�)� HTTPSHandler�match_hostname�CertificateErrorc@seZdZdZdZdd�ZdS)�HTTPSConnectionNTcCsRt�|j|jf|j�}t|dd�r0||_|��tt d�sp|j rHt j }nt j }t j ||j|j|t j|j d�|_nxt �t j�}|jt jO_|jr�|�|j|j�i}|j r�t j |_|j|j d�tt dd�r�|j|d<|j |f|�|_|j �rN|j�rNz$t|j��|j�t�d|j�Wn0tk �rL|j�tj�|j���YnXdS) NZ _tunnel_hostF� SSLContext)� cert_reqsZ ssl_version�ca_certs)ZcafileZHAS_SNIZserver_hostnamezHost verified: %s) r�Zcreate_connection�host�port�timeoutrr�sockZ_tunnelrp�sslr�Z CERT_REQUIREDZ CERT_NONEZ wrap_socketZkey_fileZ cert_fileZPROTOCOL_SSLv23r�ZoptionsZ OP_NO_SSLv2Zload_cert_chainZ verify_modeZload_verify_locations� check_domainr�Z getpeercertr�rr�ZshutdownZ SHUT_RDWRr�)r�r�r��contextrdr,r,r-�connect�s@  �     zHTTPSConnection.connect)r�r�r�r�r�r�r,r,r,r-r��sr�c@s&eZdZd dd�Zdd�Zdd�ZdS) r�TcCst�|�||_||_dSru)�BaseHTTPSHandlerr�r�r�)r�r�r�r,r,r-r��s zHTTPSHandler.__init__cOs$t||�}|jr |j|_|j|_|S)a This is called to create a connection instance. Normally you'd pass a connection class to do_open, but it doesn't actually check for a class, and just expects a callable. As long as we behave just as a constructor would have, we should be OK. If it ever changes so that we *must* pass a class, we'll create an UnsafeHTTPSConnection class which just sets check_domain to False in the class definition, and choose which one to pass to do_open. )r�r�r�)r�rcrdr(r,r,r-� _conn_maker�s zHTTPSHandler._conn_makerc CsXz|�|j|�WStk rR}z$dt|j�kr@td|j��n�W5d}~XYnXdS)Nzcertificate verify failedz*Unable to verify server certificate for %s)Zdo_openr�rr��reasonr�r�)r�rYrLr,r,r-� https_open�s�zHTTPSHandler.https_openN)T)r�r�r�r�r�r�r,r,r,r-r��s r�c@seZdZdd�ZdS)�HTTPSOnlyHandlercCstd|��dS)NzAUnexpected HTTP request on what should be a secure connection: %s)r)r�rYr,r,r-� http_open�s�zHTTPSOnlyHandler.http_openN)r�r�r�r�r,r,r,r-r��sr���r��c@seZdZddd�ZdS)�HTTPrNcKs&|dkr d}|�|j||f|��dSr���_setupZ_connection_class�r�r�r�rdr,r,r-r��sz HTTP.__init__)rN�r�r�r�r�r,r,r,r-r��sr�c@seZdZddd�ZdS)�HTTPSrNcKs&|dkr d}|�|j||f|��dSr�r�r�r,r,r-r��szHTTPS.__init__)rNr�r,r,r,r-r��sr�c@seZdZddd�Zdd�ZdS)� TransportrcCs||_tj�||�dSru)r�rr�r��r�r�� use_datetimer,r,r-r�szTransport.__init__cCs`|�|�\}}}tdkr(t||jd�}n4|jr<||jdkrR||_|t�|�f|_|jd}|S)Nr�)r�rr)� get_host_info� _ver_infor�r�� _connection�_extra_headersrZHTTPConnection)r�r��h�ehZx509r(r,r,r-�make_connection s zTransport.make_connectionN)r�r�r�r�r�r�r,r,r,r-r�s r�c@seZdZddd�Zdd�ZdS)� SafeTransportrcCs||_tj�||�dSru)r�rr�r�r�r,r,r-r�szSafeTransport.__init__cCsx|�|�\}}}|si}|j|d<tdkr:t|df|�}n:|jrN||jdkrj||_|tj|df|�f|_|jd}|S)Nr�r�rr)r�r�r�r�r�r�rr�)r�r�r�r�rdr(r,r,r-r�s  � zSafeTransport.make_connectionN)rr�r,r,r,r-r�s r�c@seZdZdd�ZdS)� ServerProxyc Kst|�dd�|_}|dk r^t|�\}}|�dd�}|dkr@t}nt}|||d�|d<}||_tjj ||f|�dS)Nr�r�rZhttps)r�� transport) rhr�rrIr�r�r�rr�r�) r�rZrdr�rWr]r�Ztclsr\r,r,r-r�,s  zServerProxy.__init__Nr�r,r,r,r-r�+sr�cKs6tjddkr|d7}nd|d<d|d<t||f|�S)Nrr��br�newliner�r�)rqr�r�)rXr�rdr,r,r-� _csv_open@s  r�c@s4eZdZed�ed�ed�d�Zdd�Zdd�Zd S) �CSVBaserC�"r�)Z delimiterZ quotecharZlineterminatorcCs|Srur,r�r,r,r-� __enter__RszCSVBase.__enter__cGs|j��dSru)r�r�)r�r&r,r,r-�__exit__UszCSVBase.__exit__N)r�r�r�r��defaultsr�r�r,r,r,r-r�Ks �r�c@s(eZdZdd�Zdd�Zdd�ZeZdS)� CSVReadercKs\d|kr4|d}tjddkr,t�d�|�}||_nt|dd�|_tj|jf|j�|_dS)Nr�rr�r�rbrG) rqr�r�r�r�r��csvrKr�)r�rdr�r,r,r-r�ZszCSVReader.__init__cCs|Srur,r�r,r,r-�__iter__eszCSVReader.__iter__cCsFt|j�}tjddkrBt|�D] \}}t|t�s |�d�||<q |S�Nrr�r�)�nextrKrqr�r7rxrr�)r�r(r[r�r,r,r-r�hs   zCSVReader.nextN)r�r�r�r�r�r��__next__r,r,r,r-r�Ys r�c@seZdZdd�Zdd�ZdS)� CSVWritercKs$t|d�|_tj|jf|j�|_dS)Nr�)r�r�r��writerr�)r�rXrdr,r,r-r�ss zCSVWriter.__init__cCsNtjddkr>g}|D]"}t|t�r.|�d�}|�|�q|}|j�|�dSr�)rqr�rxrr�r"r��writerow)r��rowrGr�r,r,r-r�ws   zCSVWriter.writerowN)r�r�r�r�r�r,r,r,r-r�rsr�csHeZdZeej�Zded<d �fdd� Zdd�Zdd �Zd d �Z �Z S) � Configurator� inc_convertZincNcs"tt|��|�|pt��|_dSru)�superrr�rar�rj)r��configrj�� __class__r,r-r��szConfigurator.__init__c s���fdd����d�}t|�s*��|�}��dd�}��dd�}|r\t�fdd�|D��}��fd d��D�}t|�}|||�}|r�|��D]\}} t||�| ��q�|S) Ncsvt|ttf�r*t|��fdd�|D��}nHt|t�rhd|krH��|�}qri}|D]}�||�||<qPn ��|�}|S)Ncsg|] }�|��qSr,r,)rNr[��convertr,r-rO�szBConfigurator.configure_custom..convert..�())rxr r{�type�dict�configure_customr)�or(r�)rr�r,r-r�s   z.Configurator.configure_custom..convertrrz[]r,csg|] }�|��qSr,r,)rNr rr,r-rO�sz1Configurator.configure_custom..cs$g|]}t|�r|��|�f�qSr,)r)rNr�)rrr,r-rO�s)rhrrr{r r��setattr) r�rr~Zpropsrcr�rdr(rBrIr,)rrr�r-r �s     zConfigurator.configure_customcCs4|j|}t|t�r0d|kr0|�|�|j|<}|S)Nr)rrxr r )r�r�r(r,r,r-� __getitem__�s zConfigurator.__getitem__c CsFtj�|�stj�|j|�}tj|ddd��}t�|�}W5QRX|S)z*Default converter for the inc:// protocol.rGr�r�) rarb�isabsr$rjr�r�r�r�)r�r�r�r(r,r,r-r�s  zConfigurator.inc_convert)N) r�r�r�r rZvalue_convertersr�r rr� __classcell__r,r,rr-r�s  rc@s*eZdZdZd dd�Zdd�Zdd �ZdS) �SubprocessMixinzC Mixin for running subprocesses and capturing their output FNcCs||_||_dSru)�verbose�progress)r�rrr,r,r-r��szSubprocessMixin.__init__cCsj|j}|j}|��}|sq^|dk r.|||�q |s@tj�d�ntj�|�d��tj��q |��dS)z� Read lines from a subprocess' output stream and either pass to a progress callable (if specified) or write progress information to sys.stderr. Nrr�) rr�readlinerq�stderrr�r��flushr�)r�r�r�rrr+r,r,r-rK�s  zSubprocessMixin.readercKs�tj|ftjtjd�|��}tj|j|jdfd�}|��tj|j|jdfd�}|��|� �|� �|� �|j dk r�|� dd�n|j r�t j�d�|S)N)�stdoutrr)r�rcrzdone.�mainzdone. )� subprocess�Popen�PIPE� threadingZThreadrKrr=r�waitr$rrrqr�)r��cmdrdr}�t1�t2r,r,r-� run_command�s" ��  zSubprocessMixin.run_command)FN)r�r�r�rZr�rKr!r,r,r,r-r�s rcCst�dd|���S)z,Normalize a python package name a la PEP 503z[-_.]+r;)r>�subrz)rPr,r,r-�normalize_name�sr#)NN)r�)N)N)NT)�r�� collectionsr� contextlibr�Zglobrr�r�r�Zloggingrar�r>r�r�� ImportErrorrrqr�r�r�rZdummy_threadingr�rr�compatrrrr r r r r rrrrrrrrrrrrrZ getLoggerr�r�r�rrGrFr6r>r:rVr#r?r^rnrtryrr�r�r��contextmanagerr�r�r�r�r�r�r�rr�VERBOSEr r�r-r/r1r3r6r9�Ir@r<rCrDrErHrMrPrQrSrTr[rfZARCHIVE_EXTENSIONSr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr#r,r,r,r-�s�      \         Yy   /   8� ) �   ,H  C]    *)   7.