Your IP : 3.149.29.209


Current Path : /opt/alt/python37/lib/python3.7/site-packages/distlib/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/distlib/__pycache__/locators.cpython-37.pyc

B

:��a���@s2ddlZddlmZddlZddlZddlZddlZddlZyddlZWne	k
rdddl
ZYnXddlZddlm
Z
ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlmZm Z m!Z!ddl"m#Z#m$Z$ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-dd	l.m/Z/m0Z0dd
l1m2Z2m3Z3e�4e5�Z6e�7d�Z8e�7dej9�Z:e�7d
�Z;dZ<d,dd�Z=Gdd�de�Z>Gdd�de?�Z@Gdd�de@�ZAGdd�de@�ZBGdd�de?�ZCGdd�de@�ZDGdd�de@�ZEGdd �d e@�ZFGd!d"�d"e@�ZGGd#d$�d$e@�ZHeHeF�eDd%d&d'�d(d)�ZIeIjJZJGd*d+�d+e?�ZKdS)-�N)�BytesIO�)�DistlibException)�urljoin�urlparse�
urlunparse�url2pathname�pathname2url�queue�quote�unescape�build_opener�HTTPRedirectHandler�	text_type�Request�	HTTPError�URLError)�Distribution�DistributionPath�	make_dist)�Metadata�MetadataInvalidError)�cached_property�ensure_slash�split_filename�get_project_data�parse_requirement�parse_name_and_version�ServerProxy�normalize_name)�
get_scheme�UnsupportedVersionError)�Wheel�
is_compatiblez^(\w+)=([a-f0-9]+)z;\s*charset\s*=\s*(.*)\s*$ztext/html|application/x(ht)?mlzhttps://pypi.org/pypicCs2|dkrt}t|dd�}z|��S|d��XdS)z�
    Return all distribution names known by an index.
    :param url: The URL of the index.
    :return: A list of all known distribution names.
    Ng@)�timeout�close)�
DEFAULT_INDEXr�
list_packages)�url�client�r*�A/opt/alt/python37/lib/python3.7/site-packages/distlib/locators.py�get_all_distribution_names)sr,c@s$eZdZdZdd�ZeZZZdS)�RedirectHandlerzE
    A class to work around a bug in some Python 3.2.x releases.
    c	Cs�d}xdD]}||kr
||}Pq
W|dkr0dSt|�}|jdkrpt|��|�}t|d�rh|�||�n|||<t�||||||�S)N)�locationZuri��replace_header)r�schemerZget_full_url�hasattrr0�BaseRedirectHandler�http_error_302)	�self�req�fp�code�msg�headersZnewurl�keyZurlpartsr*r*r+r4@s


zRedirectHandler.http_error_302N)�__name__�
__module__�__qualname__�__doc__r4Zhttp_error_301Zhttp_error_303Zhttp_error_307r*r*r*r+r-7sr-c@s�eZdZdZdZdZdZdZedZd)dd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zee
e�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd*d'd(�ZdS)+�LocatorzG
    A base class for locators - things that locate distributions.
    )z.tar.gzz.tar.bz2z.tarz.zipz.tgzz.tbz)z.eggz.exez.whl)z.pdfN)z.whl�defaultcCs,i|_||_tt��|_d|_t��|_dS)a^
        Initialise an instance.
        :param scheme: Because locators look for most recent versions, they
                       need to know the version scheme to use. This specifies
                       the current PEP-recommended scheme - use ``'legacy'``
                       if you need to support existing distributions on PyPI.
        N)	�_cacher1r
r-�opener�matcherr
�Queue�errors)r5r1r*r*r+�__init__fs
zLocator.__init__cCsXg}xN|j��sRy|j�d�}|�|�Wn|jjk
rDwYnX|j��qW|S)z8
        Return any errors which have occurred.
        F)rF�empty�get�appendZEmpty�	task_done)r5�result�er*r*r+�
get_errorsyszLocator.get_errorscCs|��dS)z>
        Clear any errors which may have been logged.
        N)rN)r5r*r*r+�clear_errors�szLocator.clear_errorscCs|j��dS)N)rB�clear)r5r*r*r+�clear_cache�szLocator.clear_cachecCs|jS)N)�_scheme)r5r*r*r+�_get_scheme�szLocator._get_schemecCs
||_dS)N)rR)r5�valuer*r*r+�_set_scheme�szLocator._set_schemecCstd��dS)a=
        For a given project, get a dictionary mapping available versions to Distribution
        instances.

        This should be implemented in subclasses.

        If called from a locate() request, self.matcher will be set to a
        matcher for the requirement to satisfy, otherwise it will be None.
        z Please implement in the subclassN)�NotImplementedError)r5�namer*r*r+�_get_project�s
zLocator._get_projectcCstd��dS)zJ
        Return all the distribution names known to this locator.
        z Please implement in the subclassN)rV)r5r*r*r+�get_distribution_names�szLocator.get_distribution_namescCsL|jdkr|�|�}n2||jkr,|j|}n|��|�|�}||j|<|S)z�
        For a given project, get a dictionary mapping available versions to Distribution
        instances.

        This calls _get_project to do all the work, and just implements a caching layer on top.
        N)rBrXrO)r5rWrLr*r*r+�get_project�s



zLocator.get_projectcCs^t|�}t�|j�}d}|�d�}|�|j�}|rBtt|�|j�}|j	dkd|j
k||||fS)zu
        Give an url a score which can be used to choose preferred URLs
        for a given project release.
        Tz.whl�httpszpypi.org)r�	posixpath�basename�path�endswith�downloadable_extensionsr#r"�
wheel_tagsr1�netloc)r5r(�tr]Z
compatibleZis_wheelZis_downloadabler*r*r+�	score_url�s
zLocator.score_urlcCsR|}|rN|�|�}|�|�}||kr(|}||kr@t�d||�nt�d||�|S)a{
        Choose one of two URLs where both are candidates for distribution
        archives for the same version of a distribution (for example,
        .tar.gz vs. zip).

        The current implementation favours https:// URLs over http://, archives
        from PyPI over those from other locations, wheel compatibility (if a
        wheel) and then the archive name.
        zNot replacing %r with %rzReplacing %r with %r)rd�logger�debug)r5�url1�url2rL�s1�s2r*r*r+�
prefer_url�s


zLocator.prefer_urlcCs
t||�S)zZ
        Attempt to split a filename in project name, version and Python version.
        )r)r5�filename�project_namer*r*r+r�szLocator.split_filenamecCsdd�}d}t|�\}}}}}	}
|
���d�r<t�d||
�t�|
�}|rX|��\}}
nd\}}
|}|r�|ddkr�|dd�}|�d	��r>y~t	|�}t
||j�s�t�d
|�nX|dkr�d}n||j|�}|�r|j|j
|jt|||||	df�d
�dd�|jD��d�}Wn0tk
�r:}zt�d|�Wdd}~XYnXn�|�|j��sZt�d|�n�t�|�}}x�|jD]�}|�|��rp|dt|��}|�||�}|�s�t�d|�nH|\}}}|�r�|||��r�|||t|||||	df�d�}|�r�||d<P�qpW|�r|�r|
|d|<|S)a
        See if a URL is a candidate for a download URL for a project (the URL
        has typically been scraped from an HTML page).

        If it is, a dictionary is returned with keys "name", "version",
        "filename" and "url"; otherwise, None is returned.
        cSst|�t|�kS)N)r)Zname1Zname2r*r*r+�same_project�sz:Locator.convert_url_to_download_info.<locals>.same_projectNzegg=z %s: version hint in fragment: %r)NN����/z.whlzWheel not compatible: %sTr/z, cSs"g|]}d�t|dd����qS)�.�N)�join�list)�.0�vr*r*r+�
<listcomp>sz8Locator.convert_url_to_download_info.<locals>.<listcomp>)rW�versionrlr(zpython-versionzinvalid path for wheel: %szNot downloadable: %sz No match for project/version: %s)rWrxrlr(zpython-versionz	%s_digest)r�lower�
startswithrerf�HASHER_HASH�match�groupsr_r"r#rarWrxrlrrs�pyver�	Exception�warningr`r\r]�lenr)r5r(rmrnrLr1rbr^�params�query�frag�m�algo�digestZorigpath�wheel�includerMrl�extrcrWrxr~r*r*r+�convert_url_to_download_info�sj

 
z$Locator.convert_url_to_download_infocCsld}d|kr8|d}x"dD]}||kr|||f}PqW|shx*dD]"}d|}||krB|||f}PqBW|S)z�
        Get a digest from a dictionary by looking at a "digests" dictionary
        or keys of the form 'algo_digest'.

        Returns a 2-tuple (algo, digest) if found, else None. Currently
        looks only for SHA256, then MD5.
        N�digests)Zsha256�md5z	%s_digestr*)r5�inforLr�r�r;r*r*r+�_get_digest1s

zLocator._get_digestc	Cs�|�d�}|�d�}||kr,||}|j}nt|||jd�}|j}|�|�|_}|d}||d|<|j|dkr�|�|j|�|_|d�|t	���
|�||_|||<dS)z�
        Update a result dictionary (the final result from _get_project) with a
        dictionary for a specific version, which typically holds information
        gleaned from a filename or URL for an archive for the distribution.
        rWrx)r1r(r��urlsN)�pop�metadatarr1r�r��
source_urlrk�
setdefault�set�add�locator)	r5rLr�rWrx�dist�mdr�r(r*r*r+�_update_version_dataHs

zLocator._update_version_dataFc	Cs�d}t|�}|dkr td|��t|j�}|�|j�|_}t�d|t|�j	�|�
|j�}t|�dk�rg}|j
}	xb|D]Z}
|
dkr�qzy(|�|
�s�n|s�|	|
�js�|�|
�Wqztk
r�t�d||
�YqzXqzWt|�dkr�t||jd�}|�rt�d	|�|d
}||}|�r�|j�r*|j|_|�di��|t��|_i}|�di�}
x&|jD]}||
k�rZ|
|||<�qZW||_d|_|S)
a
        Find the most recent distribution which matches the given
        requirement.

        :param requirement: A requirement of the form 'foo (1.0)' or perhaps
                            'foo (>= 1.0, < 2.0, != 1.3)'
        :param prereleases: If ``True``, allow pre-release versions
                            to be located. Otherwise, pre-release versions
                            are not returned.
        :return: A :class:`Distribution` instance, or ``None`` if no such
                 distribution could be located.
        NzNot a valid requirement: %rzmatcher: %s (%s)rr)r�r�zerror matching %s with %rr)r;zsorted list: %sror�r�)rrr r1rD�requirementrerf�typer<rZrWr�Z
version_classr|Z
is_prereleaserJrr��sortedr;ZextrasrIr��
download_urlsr�)r5r��prereleasesrL�rr1rD�versionsZslistZvcls�krx�d�sdr(r*r*r+�locate_sP





zLocator.locate)rA)F)r<r=r>r?�source_extensions�binary_extensions�excluded_extensionsrar`rGrNrOrQrSrU�propertyr1rXrYrZrdrkrr�r�r�r�r*r*r*r+r@Vs.

Jr@cs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�PyPIRPCLocatorz�
    This locator uses XML-RPC to locate distributions. It therefore
    cannot be used with simple mirrors (that only mirror file content).
    cs*tt|�jf|�||_t|dd�|_dS)z�
        Initialise an instance.

        :param url: The URL to use for XML-RPC.
        :param kwargs: Passed to the superclass constructor.
        g@)r$N)�superr�rG�base_urlrr))r5r(�kwargs)�	__class__r*r+rG�szPyPIRPCLocator.__init__cCst|j���S)zJ
        Return all the distribution names known to this locator.
        )r�r)r')r5r*r*r+rY�sz%PyPIRPCLocator.get_distribution_namescCsiid�}|j�|d�}x�|D]�}|j�||�}|j�||�}t|jd�}|d|_|d|_|�d�|_	|�dg�|_
|�d�|_t|�}|r|d	}	|	d
|_
|�|	�|_||_|||<xB|D]:}	|	d
}
|�|	�}|d�|t���|
�||d|
<q�WqW|S)
N)r�r�T)r1rWrx�license�keywords�summaryrr(r�r�)r)Zpackage_releasesZrelease_urlsZrelease_datarr1rWrxrIr�r�r�rr�r�r�r�r�r�r�)r5rWrLr�rvr��datar�r�r�r(r�r*r*r+rX�s0






zPyPIRPCLocator._get_project)r<r=r>r?rGrYrX�
__classcell__r*r*)r�r+r��sr�cs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�PyPIJSONLocatorzw
    This locator uses PyPI's JSON interface. It's very limited in functionality
    and probably not worth using.
    cs tt|�jf|�t|�|_dS)N)r�r�rGrr�)r5r(r�)r�r*r+rG�szPyPIJSONLocator.__init__cCstd��dS)zJ
        Return all the distribution names known to this locator.
        zNot available from this locatorN)rV)r5r*r*r+rY�sz&PyPIJSONLocator.get_distribution_namesc
Csiid�}t|jdt|��}�y�|j�|�}|����}t�|�}t	|j
d�}|d}|d|_|d|_|�
d�|_|�
dg�|_|�
d	�|_t|�}||_|d
}	|||j<x`|d
D]T}
|
d}|j�|�|�|
�|j|<|d
�|jt���|�|�|
�|d|<q�Wx�|d
��D]�\}}||jk�r:�q"t	|j
d�}
|j|
_||
_t|
�}||_|||<x\|D]T}
|
d}|j�|�|�|
�|j|<|d
�|t���|�|�|
�|d|<�qpW�q"WWn@tk
�r}z |j�t|��t�d|�Wdd}~XYnX|S)N)r�r�z%s/json)r1r�rWrxr�r�r�r�r(r�ZreleaseszJSON fetch failed: %s) rr�rrC�open�read�decode�json�loadsrr1rWrxrIr�r�r�rr�r�r�r�r�r�r��itemsrrF�putrre�	exception)r5rWrLr(�respr�r�r�r�r�r�rxZinfosZomd�odistrMr*r*r+rX�sT





"	zPyPIJSONLocator._get_project)r<r=r>r?rGrYrXr�r*r*)r�r+r��sr�c@s`eZdZdZe�dejejBejB�Z	e�dejejB�Z
dd�Ze�dej�Ze
dd��Zd	S)
�Pagez4
    This class represents a scraped HTML page.
    z�
(rel\s*=\s*(?:"(?P<rel1>[^"]*)"|'(?P<rel2>[^']*)'|(?P<rel3>[^>\s
]*))\s+)?
href\s*=\s*(?:"(?P<url1>[^"]*)"|'(?P<url2>[^']*)'|(?P<url3>[^>\s
]*))
(\s+rel\s*=\s*(?:"(?P<rel4>[^"]*)"|'(?P<rel5>[^']*)'|(?P<rel6>[^>\s
]*)))?
z!<base\s+href\s*=\s*['"]?([^'">]+)cCs4||_||_|_|j�|j�}|r0|�d�|_dS)zk
        Initialise an instance with the Unicode page contents and the URL they
        came from.
        rN)r�r�r(�_base�search�group)r5r�r(r�r*r*r+rG s
z
Page.__init__z[^a-z0-9$&+,/:;=?@.#%_\\|-]cCs�dd�}t�}x�|j�|j�D]�}|�d�}|dpZ|dpZ|dpZ|dpZ|dpZ|d	}|d
pr|dpr|d}t|j|�}t|�}|j�	d
d�|�}|�
||f�qWt|dd�dd�}|S)z�
        Return the URLs of all the links on a page together with information
        about their "rel" attribute, for determining which ones to treat as
        downloads and which ones to queue for further scraping.
        cSs,t|�\}}}}}}t||t|�|||f�S)zTidy up an URL.)rrr)r(r1rbr^r�r�r�r*r*r+�clean4szPage.links.<locals>.cleanr/Zrel1Zrel2Zrel3Zrel4Zrel5Zrel6rgrhZurl3cSsdt|�d��S)Nz%%%2xr)�ordr�)r�r*r*r+�<lambda>B�zPage.links.<locals>.<lambda>cSs|dS)Nrr*)rcr*r*r+r�Fr�T)r;�reverse)r��_href�finditerr��	groupdictrr�r�	_clean_re�subr�r�)r5r�rLr|r��relr(r*r*r+�links-s
z
Page.linksN)r<r=r>r?�re�compile�I�S�Xr�r�rGr�rr�r*r*r*r+r�sr�cs�eZdZdZejdd�dd�d�Zd�fdd	�	Zd
d�Zdd
�Z	dd�Z
e�dej
�Zdd�Zdd�Zdd�Zdd�Zdd�Ze�d�Zdd�Z�ZS)�SimpleScrapingLocatorz�
    A locator which scrapes HTML pages to locate downloads for a distribution.
    This runs multiple threads to do the I/O; performance is at least as good
    as pip's PackageFinder, which works in an analogous fashion.
    cCstjt|�d���S)N)�fileobj)�gzipZGzipFilerr�)�br*r*r+r�Tr�zSimpleScrapingLocator.<lambda>cCs|S)Nr*)r�r*r*r+r�Ur�)�deflater�ZnoneN�
csltt|�jf|�t|�|_||_i|_t�|_t	�
�|_t�|_d|_
||_t��|_t��|_d|_dS)a�
        Initialise an instance.
        :param url: The root URL to use for scraping.
        :param timeout: The timeout, in seconds, to be applied to requests.
                        This defaults to ``None`` (no timeout specified).
        :param num_workers: The number of worker threads you want to do I/O,
                            This defaults to 10.
        :param kwargs: Passed to the superclass.
        FN)r�r�rGrr�r$�_page_cacher��_seenr
rE�	_to_fetch�
_bad_hosts�skip_externals�num_workers�	threading�RLock�_lock�_gplock�platform_check)r5r(r$r�r�)r�r*r+rGXs




zSimpleScrapingLocator.__init__cCsFg|_x:t|j�D],}tj|jd�}d|_|��|j�|�qWdS)z�
        Threads are created only when get_project is called, and terminate
        before it returns. They are there primarily to parallelise I/O (i.e.
        fetching web pages).
        )�targetTN)	�_threads�ranger�r��Thread�_fetch�daemon�startrJ)r5�ircr*r*r+�_prepare_threadsssz&SimpleScrapingLocator._prepare_threadscCs>x|jD]}|j�d�qWx|jD]}|��q$Wg|_dS)zu
        Tell all the threads to terminate (by sending a sentinel value) and
        wait for them to do so.
        N)r�r�r�rs)r5rcr*r*r+�
_wait_threads�s
z#SimpleScrapingLocator._wait_threadsc	Cs�iid�}|j�x||_||_t|jdt|��}|j��|j��|�	�z&t
�d|�|j�
|�|j��Wd|��X|`WdQRX|S)N)r�r�z%s/zQueueing %s)r�rLrmrr�rr�rPr�r�rerfr�r�rsr�)r5rWrLr(r*r*r+rX�s



z"SimpleScrapingLocator._get_projectz<\b(linux_(i\d86|x86_64|arm\w+)|win(32|_amd64)|macosx_?\d+)\bcCs|j�|�S)zD
        Does an URL refer to a platform-specific download?
        )�platform_dependentr�)r5r(r*r*r+�_is_platform_dependent�sz,SimpleScrapingLocator._is_platform_dependentc	CsZ|jr|�|�rd}n|�||j�}t�d||�|rV|j�|�|j|�WdQRX|S)a%
        See if an URL is a suitable download for a project.

        If it is, register information in the result dictionary (for
        _get_project) about the specific version it's for.

        Note that the return value isn't actually used other than as a boolean
        value.
        Nzprocess_download: %s -> %s)	r�r�r�rmrerfr�r�rL)r5r(r�r*r*r+�_process_download�s
z'SimpleScrapingLocator._process_downloadc
Cs�t|�\}}}}}}|�|j|j|j�r2d}n||jrJ|�|j�sJd}nd|�|j�s\d}nR|dkrjd}nD|dkrxd}n6|�|�r�d}n&|�	dd�d}	|	�
�dkr�d}nd}t�d	||||�|S)
z�
        Determine whether a link URL from a referring page and with a
        particular "rel" attribute should be queued for scraping.
        F)ZhomepageZdownload)Zhttpr[Zftp�:rrZ	localhostTz#should_queue: %s (%s) from %s -> %s)
rr_r�r�r�r�rzr�r��splitryrerf)
r5�linkZreferrerr�r1rbr^�_rL�hostr*r*r+�
_should_queue�s*


z#SimpleScrapingLocator._should_queuec
Cs�x�|j��}z�y�|r�|�|�}|dkr(wxt|jD]j\}}||jkr0yB|j�|�|�|�s�|�|||�r�t�	d||�|j�
|�Wq0tk
r�Yq0Xq0WWn2tk
r�}z|j
�
t|��Wdd}~XYnXWd|j��X|sPqWdS)z�
        Get a URL to fetch from the work queue, get the HTML page, examine its
        links for download candidates and candidates for further scraping.

        This is a handy method to run in a thread.
        NzQueueing %s from %s)r�rI�get_pager�r�r�r�r�rerfr�rrrFrrK)r5r(�pager�r�rMr*r*r+r��s,



&zSimpleScrapingLocator._fetchcCsXt|�\}}}}}}|dkr:tj�t|��r:tt|�d�}||jkr`|j|}t�	d||��n�|�
dd�d}d}||jkr�t�	d||��n�t|d	d
id�}�z�y�t�	d|�|j
j||jd
�}	t�	d|�|	��}
|
�dd�}t�|��r�|	��}|	��}
|
�d�}|�r"|j|}||
�}
d}t�|�}|�r@|�d�}y|
�|�}
Wn tk
�rn|
�d�}
YnXt|
|�}||j|<Wn�tk
�r�}z|jdk�r�t�d||�Wdd}~XYn�t k
�r}z0t�d||�|j!�|j�"|�WdQRXWdd}~XYn2t#k
�rB}zt�d||�Wdd}~XYnXWd||j|<X|S)a
        Get the HTML for an URL, possibly from an in-memory cache.

        XXX TODO Note: this cache is never actually cleared. It's assumed that
        the data won't get stale over the lifetime of a locator instance (not
        necessarily true for the default_locator).
        �filez
index.htmlzReturning %s from cache: %sr�rrNzSkipping %s due to bad host %szAccept-encodingZidentity)r:zFetching %s)r$z
Fetched %szContent-Typer/zContent-Encodingzutf-8zlatin-1i�zFetch failed: %s: %s)$r�osr^�isdirrrrr�rerfr�r�rrCr�r$r�rI�HTML_CONTENT_TYPEr|Zgeturlr��decoders�CHARSETr�r�r��UnicodeErrorr�rr8r�rr�r�r)r5r(r1rbr^r�rLr�r6r�r:�content_typeZ	final_urlr��encoding�decoderr�rMr*r*r+r��sZ	







&$zSimpleScrapingLocator.get_pagez<a href=[^>]*>([^<]+)<cCsPt�}|�|j�}|s$td|j��x&|j�|j�D]}|�|�d��q4W|S)zJ
        Return all the distribution names known to this locator.
        zUnable to get %sr)	r�r�r�r�_distname_rer�r�r�r�)r5rLr�r|r*r*r+rY7sz,SimpleScrapingLocator.get_distribution_names)Nr�)r<r=r>r?�zlib�
decompressr�rGr�r�rXr�r�r�r�r�r�r�r�r�rrYr�r*r*)r�r+r�Js"

!;
r�cs8eZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�ZS)
�DirectoryLocatorz?
    This class locates distributions in a directory tree.
    csN|�dd�|_tt|�jf|�tj�|�}tj�|�sDt	d|��||_
dS)a�
        Initialise an instance.
        :param path: The root of the directory tree to search.
        :param kwargs: Passed to the superclass constructor,
                       except for:
                       * recursive - if True (the default), subdirectories are
                         recursed into. If False, only the top-level directory
                         is searched,
        �	recursiveTzNot a directory: %rN)r�rr�rrGr�r^�abspathr�r�base_dir)r5r^r�)r�r*r+rGHs
zDirectoryLocator.__init__cCs|�|j�S)z�
        Should a filename be considered as a candidate for a distribution
        archive? As well as the filename, the directory which contains it
        is provided, though not used by the current implementation.
        )r_r`)r5rl�parentr*r*r+�should_includeYszDirectoryLocator.should_includec		Cs�iid�}x�t�|j�D]v\}}}xb|D]Z}|�||�r(tj�||�}tddttj�|��dddf�}|�	||�}|r(|�
||�q(W|jsPqW|S)N)r�r�r�r/)r��walkr
rr^rsrr	r	r�r�r)	r5rWrL�root�dirs�files�fnr(r�r*r*r+rXas

zDirectoryLocator._get_projectc	Cs�t�}x�t�|j�D]x\}}}xd|D]\}|�||�r$tj�||�}tddttj�	|��dddf�}|�
|d�}|r$|�|d�q$W|jsPqW|S)zJ
        Return all the distribution names known to this locator.
        r�r/NrW)
r�r�r
r
rr^rsrr	r	r�r�r)r5rLrrrrr(r�r*r*r+rYqs
z'DirectoryLocator.get_distribution_names)	r<r=r>r?rGrrXrYr�r*r*)r�r+rCs
rc@s eZdZdZdd�Zdd�ZdS)�JSONLocatora
    This locator uses special extended metadata (not available on PyPI) and is
    the basis of performant dependency resolution in distlib. Other locators
    require archive downloads before dependencies can be determined! As you
    might imagine, that can be slow.
    cCstd��dS)zJ
        Return all the distribution names known to this locator.
        zNot available from this locatorN)rV)r5r*r*r+rY�sz"JSONLocator.get_distribution_namescCs�iid�}t|�}|r�x�|�dg�D]�}|ddks$|ddkrBq$t|d|d|�d	d
�|jd�}|j}|d|_d
|kr�|d
r�d|d
f|_|�di�|_|�di�|_|||j	<|d�
|j	t���|d�q$W|S)N)r�r�rZptype�sdistZ	pyversion�sourcerWrxr�zPlaceholder for summary)r�r1r(r�r�Zrequirements�exportsr�)
rrIrr1r�r�r�Zdependenciesrrxr�r�r�)r5rWrLr�r�r�r�r*r*r+rX�s&



"zJSONLocator._get_projectN)r<r=r>r?rYrXr*r*r*r+r�srcs(eZdZdZ�fdd�Zdd�Z�ZS)�DistPathLocatorz�
    This locator finds installed distributions in a path. It can be useful for
    adding to an :class:`AggregatingLocator`.
    cs*tt|�jf|�t|t�s t�||_dS)zs
        Initialise an instance.

        :param distpath: A :class:`DistributionPath` instance to search.
        N)r�rrG�
isinstancer�AssertionError�distpath)r5rr�)r�r*r+rG�szDistPathLocator.__init__cCsP|j�|�}|dkr iid�}n,|j|d|jt|jg�id|jtdg�ii}|S)N)r�r�r�r�)rZget_distributionrxr�r�)r5rWr�rLr*r*r+rX�szDistPathLocator._get_project)r<r=r>r?rGrXr�r*r*)r�r+r�s
rcsReZdZdZ�fdd�Z�fdd�Zdd�Zeej	j
e�Z	dd	�Zd
d�Z�Z
S)�AggregatingLocatorzI
    This class allows you to chain and/or merge a list of locators.
    cs*|�dd�|_||_tt|�jf|�dS)a�
        Initialise an instance.

        :param locators: The list of locators to search.
        :param kwargs: Passed to the superclass constructor,
                       except for:
                       * merge - if False (the default), the first successful
                         search from any of the locators is returned. If True,
                         the results from all locators are merged (this can be
                         slow).
        �mergeFN)r�r�locatorsr�rrG)r5rr�)r�r*r+rG�szAggregatingLocator.__init__cs*tt|���x|jD]}|��qWdS)N)r�rrQr)r5r�)r�r*r+rQ�szAggregatingLocator.clear_cachecCs ||_x|jD]
}||_qWdS)N)rRrr1)r5rTr�r*r*r+rU�szAggregatingLocator._set_schemecCs�i}x�|jD]�}|�|�}|r|jr�|�di�}|�di�}|�|�|�d�}|r�|r�x6|��D]*\}}	||kr�|||	O<qb|	||<qbW|�d�}
|r�|
r�|
�|�q|jdkr�d}n$d}x|D]}|j�|�r�d}Pq�W|r|}PqW|S)Nr�r�TF)rrZrrI�updater�rDr|)r5rWrLr�r�rr�Zdfr�rv�dd�foundr*r*r+rX�s8





zAggregatingLocator._get_projectc	Cs@t�}x4|jD]*}y||��O}Wqtk
r6YqXqW|S)zJ
        Return all the distribution names known to this locator.
        )r�rrYrV)r5rLr�r*r*r+rYs
z)AggregatingLocator.get_distribution_names)r<r=r>r?rGrQrUr�r@r1�fgetrXrYr�r*r*)r�r+r�s,rzhttps://pypi.org/simple/g@)r$Zlegacy)r1c@sLeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	ddd�Z
dS)�DependencyFinderz0
    Locate dependencies for distributions.
    NcCs|pt|_t|jj�|_dS)zf
        Initialise an instance, using the specified locator
        to locate distributions.
        N)�default_locatorr�r r1)r5r�r*r*r+rG/s
zDependencyFinder.__init__cCsvt�d|�|j}||j|<||j||jf<xD|jD]:}t|�\}}t�d|||�|j�	|t
���||f�q4WdS)z�
        Add a distribution to the finder. This will update internal information
        about who provides what.
        :param dist: The distribution to add.
        zadding distribution %szAdd to provided: %s, %s, %sN)rerfr;�
dists_by_name�distsrx�providesr�providedr�r�r�)r5r�rW�prxr*r*r+�add_distribution7s
z!DependencyFinder.add_distributioncCs|t�d|�|j}|j|=|j||jf=xN|jD]D}t|�\}}t�d|||�|j|}|�	||f�|s0|j|=q0WdS)z�
        Remove a distribution from the finder. This will update internal
        information about who provides what.
        :param dist: The distribution to remove.
        zremoving distribution %sz Remove from provided: %s, %s, %sN)
rerfr;r#r$rxr%rr&�remove)r5r�rWr'rx�sr*r*r+�remove_distributionFs
z$DependencyFinder.remove_distributioncCsBy|j�|�}Wn,tk
r<|��d}|j�|�}YnX|S)z�
        Get a version matcher for a requirement.
        :param reqt: The requirement
        :type reqt: str
        :return: A version matcher (an instance of
                 :class:`distlib.version.Matcher`).
        r)r1rDr!r�)r5�reqtrDrWr*r*r+�get_matcherXszDependencyFinder.get_matcherc		Csv|�|�}|j}t�}|j}||krrxL||D]@\}}y|�|�}Wntk
r\d}YnX|r.|�|�Pq.W|S)z�
        Find the distributions which can fulfill a requirement.

        :param reqt: The requirement.
         :type reqt: str
        :return: A set of distribution which can fulfill the requirement.
        F)r-r;r�r&r|r!r�)	r5r,rDrWrLr&rx�providerr|r*r*r+�find_providershs


zDependencyFinder.find_providersc	Cs�|j|}t�}x,|D]$}|�|�}|�|j�s|�|�qW|r^|�d||t|�f�d}nD|�|�|j|=x"|D]}|j�|t���|�qvW|�	|�d}|S)a�
        Attempt to replace one provider with another. This is typically used
        when resolving dependencies from multiple sources, e.g. A requires
        (B >= 1.0) while C requires (B >= 1.1).

        For successful replacement, ``provider`` must meet all the requirements
        which ``other`` fulfills.

        :param provider: The provider we are trying to replace with.
        :param other: The provider we're trying to replace.
        :param problems: If False is returned, this will contain what
                         problems prevented replacement. This is currently
                         a tuple of the literal string 'cantreplace',
                         ``provider``, ``other``  and the set of requirements
                         that ``provider`` couldn't fulfill.
        :return: True if we can replace ``other`` with ``provider``, else
                 False.
        ZcantreplaceFT)
�reqtsr�r-r|rxr��	frozensetr+r�r()	r5r.�other�problemsZrlistZ	unmatchedr*rDrLr*r*r+�try_to_replace�s"






zDependencyFinder.try_to_replaceFcCs
i|_i|_i|_i|_t|p g�}d|krH|�d�|tdddg�O}t|t�rh|}}t�	d|�n4|j
j||d�}}|dkr�td|��t�	d	|�d
|_
t�}t|g�}t|g�}�x�|�r�|��}|j}	|	|jkr�|�|�n"|j|	}
|
|k�r|�||
|�|j|jB}|j}t�}
|�rh||k�rhx2dD]*}d|}||k�r:|
t|d
|�O}
�q:W||B|
B}�x<|D�]2}|�|�}|�sRt�	d|�|j
j||d�}|dk�r�|�s�|j
j|d
d�}|dk�r�t�	d|�|�d|f�n^|j|j}}||f|jk�r|�|�|�|�||k�rR||k�rR|�|�t�	d|j�xZ|D]R}|j}	|	|jk�r�|j�|t���|�n"|j|	}
|
|k�rX|�||
|��qXW�q|Wq�Wt|j���}x.|D]&}||k|_|j�r�t�	d|j��q�Wt�	d|�||fS)a�
        Find a distribution and all distributions it depends on.

        :param requirement: The requirement specifying the distribution to
                            find, or a Distribution instance.
        :param meta_extras: A list of meta extras such as :test:, :build: and
                            so on.
        :param prereleases: If ``True``, allow pre-release versions to be
                            returned - otherwise, don't return prereleases
                            unless they're all that's available.

        Return a set of :class:`Distribution` instances and a set of
        problems.

        The distributions returned should be such that they have the
        :attr:`required` attribute set to ``True`` if they were
        from the ``requirement`` passed to ``find()``, and they have the
        :attr:`build_time_dependency` attribute set to ``True`` unless they
        are post-installation dependencies of the ``requirement``.

        The problems should be a tuple consisting of the string
        ``'unsatisfied'`` and the requirement which couldn't be satisfied
        by any distribution known to the locator.
        z:*:z:test:z:build:z:dev:zpassed %s as requirement)r�NzUnable to locate %rz
located %sT)�test�build�devz:%s:z%s_requireszNo providers found for %rzCannot satisfy %rZunsatisfiedzAdding %s to install_distsz#%s is a build-time dependency only.zfind done for %s)r&r$r#r0r�r)rrrerfr�r�rZ	requestedr�r;r(r4Zrun_requiresZ
meta_requiresZbuild_requires�getattrr/r�rxZname_and_versionr��valuesZbuild_time_dependency)r5r�Zmeta_extrasr�r�r�r3ZtodoZ
install_distsrWr2ZireqtsZsreqtsZereqtsr;rMZ	all_reqtsr�Z	providersr.�nrvr'r$r*r*r+�find�s�



















zDependencyFinder.find)N)NF)r<r=r>r?rGr(r+r-r/r4r;r*r*r*r+r!*s
(r!)N)Lr��iorr��loggingr�r\r�r��ImportErrorZdummy_threadingrr/r�compatrrrrr	r
rrr
rr3rrrrZdatabaserrrr�rr�utilrrrrrrrrrxr r!r�r"r#�	getLoggerr<rer�r{r�r�r�r&r,r-�objectr@r�r�r�r�rrrrr"r�r!r*r*r*r+�<module>sX@(



G0E:zA&[

?>