Viewing File: /usr/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__pycache__/__init__.cpython-36.pyc

3

�Pf>��^@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZyddlZWnek
r�ddlZYnXddlmZddlmZm Z m!Z!ddlm"Z"yddlm#Z#m$Z$m%Z%d	Z&Wnek
�rHd
Z&YnXddlm'Z(ddl)m*Z*m+Z+yddl,j-Z.e.j/Wnek
�r�dZ.YnXdd
lm0Z0ddlm1Z1e2d�e2d�e2d�e2d�d�ej3k�o�d�kn�r�dZ4ej5e4�dZ6dZ7Gdd�de8�Z9Gdd�de:�Z;Gdd�de;e1j<j=�Z>Gdd�de;e1j<j?�Z@dd�ZAiZBdd �ZCd!d"�ZDd#d$�ZEd%d&�ZFd'd(�ZGd)d*�ZHd+d,�ZId-d.�ZJZKd/d0�ZLd1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPddQddRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtgFZMGdudL�dLeN�ZOGdvdM�dMeO�ZPGdwdx�dxeP�ZQGdydN�dNeO�ZRGdzdO�dOeO�ZSiZTej<dd�ZUdZVd{ZWd|ZXdZYd�ZZd}dp�Z[d~d3�Z\gfdd��Z]d�d��Z^d�d��Z_ej`d��Zaej`d��Zbe_Zcd�dU�Zdd�d2�ZeeeZfd�d4�Zgd�d5�Zhd�d�d6�Zid�d7�ZjGd�dc�dc�ZkGd�dd�ddek�ZlGd�dG�dGe:�ZmGd�d��d�en�ZoGd�dF�dFe:�ZpepZqGd�dP�dPer�ZsGd�dH�dH�Ztd�dE�Zud�dR�Zvd�dS�Zwd�dX�Zxd�dY�Zyd�dZ�Zzd�d�d[�Z{Gd�dj�dj�Z|e[e:e|�Gd�dk�dke|�Z}Gd�dl�dle}�Z~e~j�Gd�dh�dhe|�Z�e��Z�Gd�d��d�en�Z�Gd�d��d�e��Z�Gd�d��d�e	j��Z�Gd�dm�dme}�Z�e[e
j�e��Gd�de�dee��Z�Gd�df�dfe~�Z�Gd�dg�dge��Z�eCd�id��d�dn�Z�d�d�dB�Z�d�d�d��Z�e�e
j�e��d�d�d��Z�e�e:e��d�d��Z�d�d�d��Z�e�ej�e��e�e.d���r"e�e.j�e��eCd�id��eCd�id��d�do�Z�d�d��Z�d�d��Z�d�d?�Z�d�d�dq�Z�d�d��Z�e�ej�e��e�e
j�e��e�e.d���r�e�e.j�e��d�dÄZ�e�e:e��d�d]�Z�ifd�dƄZ�d�dȄZ�d�dʄZ�d�dV�Z�ej`d̃j�Z�ej`d�ej�ej�B�j�Z�Gd�dK�dKe:�Z�d�dЄZ�d�d҄Z�Gd�dI�dIe:�Z�Gd�dՄd�e��Z�Gd�dׄd�e��Z�e�e�e�d؜Z�d�dڄZ�Gd�d܄d�e��Z�d�dQ�Z�Gd�dJ�dJe1j�j��Z�d�d�Z�d�d�Z�d�d\�Z�d�d�Z�d�dW�Z�d�d�Z�ej�d�e9d	d�d�d�Z�e�e��fd�d��Z�e�d�d��Z�dS)�aZ
Package resource API
--------------------

A resource is a logical file contained within a package, or a logical
subdirectory thereof.  The package resource API expects resource names
to have their path parts separated with ``/``, *not* whatever the local
path separator is.  Do not use os.path operations to manipulate resource
names being passed into the API.

The package resource API is designed to work with normal filesystem packages,
.egg files, and unpacked .egg files.  It can also work in a limited way with
.zip files and with custom PEP 302 loaders that support the ``get_data()``
method.
�)�absolute_importN)�get_importer)�six)�urllib�map�filter)�utime)�mkdir�rename�unlinkTF)�open)�isdir�split)�appdirs)�	packagingzpip._vendor.packaging.versionz pip._vendor.packaging.specifiersz"pip._vendor.packaging.requirementszpip._vendor.packaging.markers�zLSupport for Python 3.0-3.2 has been dropped. Future versions will fail here.c@seZdZdZdS)�
PEP440Warningza
    Used when there is an issue with a version or specifier not complying with
    PEP 440.
    N)�__name__�
__module__�__qualname__�__doc__�rr�/usr/lib/python3.6/__init__.pyr[srcsteZdZ�fdd�Z�fdd�Z�fdd�Z�fdd�Z�fd	d
�Z�fdd�Z�fd
d�Z	dd�Z
dd�Z�ZS)�_SetuptoolsVersionMixincstt|�j�S)N)�superr�__hash__)�self)�	__class__rrrcsz _SetuptoolsVersionMixin.__hash__cs*t|t�rt|�|kStt|�j|�SdS)N)�
isinstance�tuplerr�__lt__)r�other)rrrr fs
z_SetuptoolsVersionMixin.__lt__cs*t|t�rt|�|kStt|�j|�SdS)N)rrrr�__le__)rr!)rrrr"ls
z_SetuptoolsVersionMixin.__le__cs*t|t�rt|�|kStt|�j|�SdS)N)rrrr�__eq__)rr!)rrrr#rs
z_SetuptoolsVersionMixin.__eq__cs*t|t�rt|�|kStt|�j|�SdS)N)rrrr�__ge__)rr!)rrrr$xs
z_SetuptoolsVersionMixin.__ge__cs*t|t�rt|�|kStt|�j|�SdS)N)rrrr�__gt__)rr!)rrrr%~s
z_SetuptoolsVersionMixin.__gt__cs*t|t�rt|�|kStt|�j|�SdS)N)rrrr�__ne__)rr!)rrrr&�s
z_SetuptoolsVersionMixin.__ne__cCst|�|S)N)r)r�keyrrr�__getitem__�sz#_SetuptoolsVersionMixin.__getitem__c#sjtjdtj��dddddd�j���fdd���fdd	�}tjd
tdd�x|t|��D]
}|VqXWdS)
Nz(\d+ | [a-z]+ | \.| -)�czfinal-�@)ZpreZpreview�-ZrcZdevc3s`xT�j|�D]F}�||�}|s|dkr*q|dd�dkrH|jd�Vqd|VqWdVdS)N�.��
0123456789��*z*final)r�zfill)�s�part)�component_re�replacerr�_parse_version_parts�s
z>_SetuptoolsVersionMixin.__iter__.<locals>._parse_version_partscszg}xl�|j��D]\}|jd�rd|dkrFx|rD|ddkrD|j�q*Wx|rb|ddkrb|j�qHW|j|�qWt|�S)Nr0z*finalr-z*final-Z00000000���r7)�lower�
startswith�pop�appendr)r2�partsr3)r6rr�old_parse_version�s
z;_SetuptoolsVersionMixin.__iter__.<locals>.old_parse_versiona�You have iterated over the result of pkg_resources.parse_version. This is a legacy behavior which is inconsistent with the new version class introduced in setuptools 8.0. In most cases, conversion to a tuple is unnecessary. For comparison of versions, sort the Version instances directly. If you have another use case requiring the tuple, please file a bug with the setuptools project describing that need.r-)�
stacklevel)�re�compile�VERBOSE�get�warnings�warn�RuntimeWarning�str)rr=r3r)r6r4r5r�__iter__�s
z _SetuptoolsVersionMixin.__iter__)
rrrrr r"r#r$r%r&r(rG�
__classcell__rr)rrrbsrc@seZdZdS)�SetuptoolsVersionN)rrrrrrrrI�srIc@seZdZdS)�SetuptoolsLegacyVersionN)rrrrrrrrJ�srJcCs*yt|�Stjjk
r$t|�SXdS)N)rIr�version�InvalidVersionrJ)�vrrr�
parse_version�srNcKs"t�j|�tjtj||��dS)N)�globals�update�_state_vars�dict�fromkeys)Zvartype�kwrrr�_declare_state�srUcCs<i}t�}x,tj�D] \}}|d|||�||<qW|S)NZ_sget_)rOrQ�items)�state�g�krMrrr�__getstate__�s
rZcCs<t�}x0|j�D]$\}}|dt|||||�qW|S)NZ_sset_)rOrVrQ)rWrXrYrMrrr�__setstate__�s r[cCs|j�S)N)�copy)�valrrr�
_sget_dict�sr^cCs|j�|j|�dS)N)�clearrP)r'�obrWrrr�
_sset_dict�sracCs|j�S)N)rZ)r]rrr�_sget_object�srbcCs|j|�dS)N)r[)r'r`rWrrr�_sset_object�srccGsdS)Nr)�argsrrr�<lambda>�srecCsbt�}tj|�}|dk	r^tjdkr^y&ddjt�dd��|jd�f}Wntk
r\YnX|S)aZReturn this platform's maximum compatible version.

    distutils.util.get_platform() normally reports the minimum version
    of Mac OS X that would be required to *use* extensions produced by
    distutils.  But what we want when checking compatibility is to know the
    version of Mac OS X that we are *running*.  To allow usage of packages that
    explicitly require a newer version of Mac OS X, we must also know the
    current version of the OS.

    If this condition occurs for any other platform with a version in its
    platform strings, this function should be extended accordingly.
    N�darwinzmacosx-%s-%sr,�r)	�get_build_platform�macosVersionString�match�sys�platform�join�_macosx_vers�group�
ValueError)�plat�mrrr�get_supported_platform�s

&rs�require�
run_script�get_provider�get_distribution�load_entry_point�
get_entry_map�get_entry_info�iter_entry_points�resource_string�resource_stream�resource_filename�resource_listdir�resource_exists�resource_isdir�declare_namespace�working_set�add_activation_listener�find_distributions�set_extraction_path�cleanup_resources�get_default_cache�Environment�
WorkingSet�ResourceManager�Distribution�Requirement�
EntryPoint�ResolutionError�VersionConflict�DistributionNotFound�UnknownExtra�ExtractionError�parse_requirements�	safe_name�safe_version�get_platform�compatible_platforms�yield_lines�split_sections�
safe_extra�to_filename�invalid_marker�evaluate_marker�ensure_directory�normalize_path�EGG_DIST�BINARY_DIST�SOURCE_DIST�
CHECKOUT_DIST�DEVELOP_DIST�IMetadataProvider�IResourceProvider�FileMetadata�PathMetadata�EggMetadata�
EmptyProvider�empty_provider�NullProvider�EggProvider�DefaultProvider�ZipProvider�register_finder�register_namespace_handler�register_loader_type�fixup_namespace_packagesr�run_main�AvailableDistributionsc@seZdZdZdd�ZdS)r�z.Abstract base for dependency resolution errorscCs|jjt|j�S)N)rr�reprrd)rrrr�__repr__IszResolutionError.__repr__N)rrrrr�rrrrr�Fsc@s<eZdZdZdZedd��Zedd��Zdd�Zd	d
�Z	dS)r�z�
    An already-installed version conflicts with the requested version.

    Should be initialized with the installed Distribution and the requested
    Requirement.
    z3{self.dist} is installed but {self.req} is requiredcCs
|jdS)Nr)rd)rrrr�distWszVersionConflict.distcCs
|jdS)Nr-)rd)rrrr�req[szVersionConflict.reqcCs|jjft��S)N)�	_template�format�locals)rrrr�report_szVersionConflict.reportcCs|s|S|j|f}t|�S)zt
        If required_by is non-empty, return a version of self that is a
        ContextualVersionConflict.
        )rd�ContextualVersionConflict)r�required_byrdrrr�with_contextbszVersionConflict.with_contextN)
rrrrr��propertyr�r�r�r�rrrrr�Msc@s&eZdZdZejdZedd��ZdS)r�z�
    A VersionConflict that accepts a third parameter, the set of the
    requirements that required the installed Distribution.
    z by {self.required_by}cCs
|jdS)Nrg)rd)rrrrr�usz%ContextualVersionConflict.required_byN)rrrrr�r�r�r�rrrrr�ms
r�c@sHeZdZdZdZedd��Zedd��Zedd��Zd	d
�Z	dd�Z
d
S)r�z&A requested distribution was not foundzSThe '{self.req}' distribution was not found and is required by {self.requirers_str}cCs
|jdS)Nr)rd)rrrrr��szDistributionNotFound.reqcCs
|jdS)Nr-)rd)rrrr�	requirers�szDistributionNotFound.requirerscCs|js
dSdj|j�S)Nzthe applicationz, )r�rm)rrrr�
requirers_str�sz"DistributionNotFound.requirers_strcCs|jjft��S)N)r�r�r�)rrrrr��szDistributionNotFound.reportcCs|j�S)N)r�)rrrr�__str__�szDistributionNotFound.__str__N)rrrrr�r�r�r�r�r�r�rrrrr�zsc@seZdZdZdS)r�z>Distribution doesn't have an "extra feature" of the given nameN)rrrrrrrrr��srgr-cCs|t|<dS)aRegister `provider_factory` to make providers for `loader_type`

    `loader_type` is the type or class of a PEP 302 ``module.__loader__``,
    and `provider_factory` is a function that, passed a *module* object,
    returns an ``IResourceProvider`` for that module.
    N)�_provider_factories)Zloader_typeZprovider_factoryrrrr��scCstt|t�r$tj|�p"tt|��dSytj|}Wn&tk
rXt	|�tj|}YnXt
|dd�}tt|�|�S)z?Return an IResourceProvider for the named module or requirementr�
__loader__N)
rr�r��findrtrFrk�modules�KeyError�
__import__�getattr�
_find_adapterr�)ZmoduleOrReq�module�loaderrrrrv�s
cCsd|s\tj�d}|dkrLd}tjj|�rLttd�rLtj|�}d|krL|d}|j|j	d��|dS)Nr�z0/System/Library/CoreServices/SystemVersion.plist�	readPlistZProductVersionr,)
rlZmac_ver�os�path�exists�hasattr�plistlibr�r;r)�_cacherKZplistZ
plist_contentrrrrn�s

rncCsddd�j||�S)NZppc)ZPowerPCZPower_Macintosh)rB)�machinerrr�_macosx_arch�sr�cCs�yddlm}Wn tk
r0ddlm}YnX|�}tjdkr�|jd�r�y<t�}tj	�dj
dd�}dt|d�t|d	�t|�fSt
k
r�YnX|S)
z�Return this platform's string for platform-specific distributions

    XXX Currently this is the same as ``distutils.util.get_platform()``, but it
    needs some hacks for Linux and Mac OS X.
    r)r�rfzmacosx-�� �_zmacosx-%d.%d-%sr-)�	sysconfigr��ImportErrorZdistutils.utilrkrlr9rnr��unamer5�intr�rp)r�rqrKr�rrrrh�srhzmacosx-(\d+)\.(\d+)-(.*)zdarwin-(\d+)\.(\d+)\.(\d+)-(.*)cCs�|dks|dks||krdStj|�}|r�tj|�}|s�tj|�}|r�t|jd��}d|jd�|jd�f}|dkr||dks�|dkr�|d	kr�dSd
S|jd�|jd�ks�|jd�|jd�kr�d
St|jd��t|jd��kr�d
SdSd
S)z�Can code for the `provided` platform run on the `required` platform?

    Returns true if either platform is ``None``, or the platforms are equal.

    XXX Needs compatibility checks for Linux and other unixy OSes.
    NTr-z%s.%srg�z10.3r/z10.4Fr)rirj�darwinVersionStringr�ro)ZprovidedZrequiredZreqMacZprovMacZ
provDarwinZdversionZmacosversionrrrr��s*


cCs<tjd�j}|d}|j�||d<t|�dj||�dS)z@Locate distribution `dist_spec` and run its `script_name` scriptr-rrN)rk�	_getframe�	f_globalsr_rtru)Z	dist_spec�script_name�ns�namerrrrus
cCs@t|tj�rtj|�}t|t�r(t|�}t|t�s<td|��|S)z@Return a current distribution object for a Requirement or stringz-Expected string, Requirement, or Distribution)rr�string_typesr��parservr��	TypeError)r�rrrrw)s



cCst|�j||�S)zDReturn `name` entry point of `group` for `dist` or raise ImportError)rwrx)r�ror�rrrrx4scCst|�j|�S)z=Return the entry point map for `group`, or the full entry map)rwry)r�rorrrry9scCst|�j||�S)z<Return the EntryPoint object for `group`+`name`, or ``None``)rwrz)r�ror�rrrrz>sc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)r�cCsdS)z;Does the package's distribution contain the named metadata?Nr)r�rrr�has_metadataDszIMetadataProvider.has_metadatacCsdS)z'The named metadata resource as a stringNr)r�rrr�get_metadataGszIMetadataProvider.get_metadatacCsdS)z�Yield named metadata resource as list of non-blank non-comment lines

       Leading and trailing whitespace is stripped from each line, and lines
       with ``#`` as the first non-blank character are omitted.Nr)r�rrr�get_metadata_linesJsz$IMetadataProvider.get_metadata_linescCsdS)z>Is the named metadata a directory?  (like ``os.path.isdir()``)Nr)r�rrr�metadata_isdirPsz IMetadataProvider.metadata_isdircCsdS)z?List of metadata names in the directory (like ``os.listdir()``)Nr)r�rrr�metadata_listdirSsz"IMetadataProvider.metadata_listdircCsdS)z=Execute the named script in the supplied namespace dictionaryNr)r��	namespacerrrruVszIMetadataProvider.run_scriptN)	rrrr�r�r�r�r�rurrrrr�Csc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)r�z3An object that provides access to package resourcescCsdS)zdReturn a true filesystem path for `resource_name`

        `manager` must be an ``IResourceManager``Nr)�manager�
resource_namerrr�get_resource_filename]sz'IResourceProvider.get_resource_filenamecCsdS)ziReturn a readable file-like object for `resource_name`

        `manager` must be an ``IResourceManager``Nr)r�r�rrr�get_resource_streambsz%IResourceProvider.get_resource_streamcCsdS)zmReturn a string containing the contents of `resource_name`

        `manager` must be an ``IResourceManager``Nr)r�r�rrr�get_resource_stringgsz%IResourceProvider.get_resource_stringcCsdS)z,Does the package contain the named resource?Nr)r�rrr�has_resourcelszIResourceProvider.has_resourcecCsdS)z>Is the named resource a directory?  (like ``os.path.isdir()``)Nr)r�rrrr�osz IResourceProvider.resource_isdircCsdS)z?List of resource names in the directory (like ``os.listdir()``)Nr)r�rrrrrsz"IResourceProvider.resource_listdirN)
rrrrr�r�r�r�r�rrrrrr�Zsc@s�eZdZdZd'dd�Zedd��Zedd��Zd	d
�Zdd�Z	d
d�Z
d(dd�Zdd�Zdd�Z
d)dd�Zd*dd�Zd+dd�Zdd�Zd,dd �Zd!d"�Zd#d$�Zd%d&�ZdS)-r�zDA collection of active distributions on sys.path (or a similar list)NcCsBg|_i|_i|_g|_|dkr&tj}x|D]}|j|�q,WdS)z?Create working set from list of path entries (default=sys.path)N)�entries�
entry_keys�by_key�	callbacksrkr��	add_entry)rr��entryrrr�__init__ys
zWorkingSet.__init__cCsZ|�}yddlm}Wntk
r*|SXy|j|�Wntk
rT|j|�SX|S)z1
        Prepare the master working set.
        r)�__requires__)�__main__r�r�rtr��_build_from_requirements)�cls�wsr�rrr�
_build_master�szWorkingSet._build_mastercCsn|g�}t|�}|j|t��}x|D]}|j|�q$Wx"tjD]}||jkr>|j|�q>W|jtjdd�<|S)zQ
        Build a working set from a requirement spec. Rewrites sys.path.
        N)r��resolver��addrkr�r�r�)rZreq_specr�reqs�distsr�r�rrrr�s

z#WorkingSet._build_from_requirementscCs@|jj|g�|jj|�x t|d�D]}|j||d�q&WdS)a�Add a path item to ``.entries``, finding any distributions on it

        ``find_distributions(entry, True)`` is used to find distributions
        corresponding to the path entry, and they are added.  `entry` is
        always appended to ``.entries``, even if it is already present.
        (This is because ``sys.path`` can contain the same value more than
        once, and the ``.entries`` of the ``sys.path`` WorkingSet should always
        equal ``sys.path``.)
        TFN)r��
setdefaultr�r;r�r)rr�r�rrrr��s
zWorkingSet.add_entrycCs|jj|j�|kS)z9True if `dist` is the active distribution for its project)r�rBr')rr�rrr�__contains__�szWorkingSet.__contains__cCs,|jj|j�}|dk	r(||kr(t||��|S)a�Find a distribution matching requirement `req`

        If there is an active distribution for the requested project, this
        returns it as long as it meets the version requirement specified by
        `req`.  But, if there is an active distribution for the project and it
        does *not* meet the `req` requirement, ``VersionConflict`` is raised.
        If there is no active distribution for the requested project, ``None``
        is returned.
        N)r�rBr'r�)rr�r�rrrr��s

zWorkingSet.findccsPxJ|D]B}|j|�}|dkr6x*|j�D]
}|Vq&Wq||kr||VqWdS)aYield entry point objects from `group` matching `name`

        If `name` is None, yields all entry points in `group` from all
        distributions in the working set, otherwise only ones matching
        both `group` and `name` are yielded (in distribution order).
        N)ry�values)rror�r�r��eprrrr{�s

zWorkingSet.iter_entry_pointscCs>tjd�j}|d}|j�||d<|j|�dj||�dS)z?Locate distribution for `requires` and run `script_name` scriptr-rrN)rkr�r�r_rtru)r�requiresr�r�r�rrrru�s
zWorkingSet.run_scriptccsTi}xJ|jD]@}||jkrqx.|j|D] }||kr(d||<|j|Vq(WqWdS)z�Yield distributions for non-duplicate projects in the working set

        The yield order is the order in which the items' path entries were
        added to the working set.
        r-N)r�r�r�)r�seen�itemr'rrrrG�s
zWorkingSet.__iter__TFcCs�|r|j|j||d�|dkr$|j}|jj|g�}|jj|jg�}|rX|j|jkrXdS||j|j<|j|krz|j|j�|j|kr�|j|j�|j|�dS)aAdd `dist` to working set, associated with `entry`

        If `entry` is unspecified, it defaults to the ``.location`` of `dist`.
        On exit from this routine, `entry` is added to the end of the working
        set's ``.entries`` (if it wasn't already present).

        `dist` is only added to the working set if it's for a project that
        doesn't already have a distribution in the set, unless `replace=True`.
        If it's added, any callbacks registered with the ``subscribe()`` method
        will be called.
        )r5N)	�	insert_onr��locationr�rr'r�r;�
_added_new)rr�r��insertr5�keysZkeys2rrrr�s

zWorkingSet.addcCs|t|�ddd�}i}i}g}t�}tjt�}	�xF|�rv|jd�}
|
|krLq2|j|
�sXq2|j|
j�}|dk�r|j	j|
j�}|dks�||
kr�|r�|}|dkr�|dkr�t
|j�}nt
g�}tg�}|j
|
||�}||
j<|dkr�|	j|
d�}
t|
|
��|j|�||
k�r"|	|
}t||
�j|��|j|
j�ddd�}|j|�x(|D] }|	|j|
j�|
j||<�qHWd||
<q2W|S)aeList all distributions needed to (recursively) meet `requirements`

        `requirements` must be a sequence of ``Requirement`` objects.  `env`,
        if supplied, should be an ``Environment`` instance.  If
        not supplied, it defaults to all distributions available within any
        entry or distribution in the working set.  `installer`, if supplied,
        will be invoked with each requirement that cannot be met by an
        already-installed distribution; it should return a ``Distribution`` or
        ``None``.

        Unless `replace_conflicting=True`, raises a VersionConflict exception if
        any requirements are found on the path that have the correct name but
        the wrong version.  Otherwise, if an `installer` is supplied it will be
        invoked to obtain the correct version of the requirement and activate
        it.
        Nr-rTr7r7)�list�
_ReqExtras�collections�defaultdict�setr:�markers_passrBr'r�r�r�r��
best_matchr�r;r�r�r�extras�extendr�project_name)r�requirements�env�	installerZreplace_conflictingZ	processedZbestZto_activateZ
req_extrasr�r�r�rr�Z
dependent_reqZnew_requirementsZnew_requirementrrrrsJ









zWorkingSet.resolvecCst|�}|j�i}i}|dkr4t|j�}||7}n||}|jg�}	tt|	j|��x�|D]�}
x�||
D]x}|j�g}y|	j|||�}
Wn4t	k
r�}z|||<|r�wjnPWYdd}~XqjXtt|	j|
��|j
tj|
��PqjWq\Wt|�}|j�||fS)asFind all activatable distributions in `plugin_env`

        Example usage::

            distributions, errors = working_set.find_plugins(
                Environment(plugin_dirlist)
            )
            # add plugins+libs to sys.path
            map(working_set.add, distributions)
            # display errors
            print('Could not load', errors)

        The `plugin_env` should be an ``Environment`` instance that contains
        only distributions that are in the project's "plugin directory" or
        directories. The `full_env`, if supplied, should be an ``Environment``
        contains all currently-available distributions.  If `full_env` is not
        supplied, one is created automatically from the ``WorkingSet`` this
        method is called on, which will typically mean that every directory on
        ``sys.path`` will be scanned for distributions.

        `installer` is a standard installer callback as used by the
        ``resolve()`` method. The `fallback` flag indicates whether we should
        attempt to resolve older versions of a plugin if the newest version
        cannot be resolved.

        This method returns a 2-tuple: (`distributions`, `error_info`), where
        `distributions` is a list of the distributions found in `plugin_env`
        that were loadable, along with any other distributions that are needed
        to resolve their dependencies.  `error_info` is a dictionary mapping
        unloadable plugin distributions to an exception instance describing the
        error that occurred. Usually this will be a ``DistributionNotFound`` or
        ``VersionConflict`` instance.
        N)
r�sortr�r�rrr�as_requirementrr�rPrRrS)rZ
plugin_envZfull_envr ZfallbackZplugin_projectsZ
error_infoZ
distributionsrZ
shadow_setrr�r�Z	resolveesrMrrr�find_pluginsks4$





zWorkingSet.find_pluginscGs*|jt|��}x|D]}|j|�qW|S)a�Ensure that distributions matching `requirements` are activated

        `requirements` must be a string or a (possibly-nested) sequence
        thereof, specifying the distributions and versions required.  The
        return value is a sequence of the distributions that needed to be
        activated to fulfill the requirements; all relevant distributions are
        included, even if they were already activated in this working set.
        )rr�r)rrZneededr�rrrrt�s	
zWorkingSet.requirecCs<||jkrdS|jj|�|s"dSx|D]}||�q(WdS)z�Invoke `callback` for all distributions

        If `existing=True` (default),
        call on all existing ones, as well.
        N)r�r;)r�callback�existingr�rrr�	subscribe�s

zWorkingSet.subscribecCsx|jD]}||�qWdS)N)r�)rr�r$rrrr�szWorkingSet._added_newcCs,|jdd�|jj�|jj�|jdd�fS)N)r�r�r\r�r�)rrrrrZ�szWorkingSet.__getstate__cCs@|\}}}}|dd�|_|j�|_|j�|_|dd�|_dS)N)r�r\r�r�r�)rZe_k_b_cr�rr�r�rrrr[�s


zWorkingSet.__setstate__)N)N)NTF)NNF)NNT)T)rrrrr��classmethodrrr�r	r�r{rurGrrr#rtr&rrZr[rrrrr�vs(




Q
S
c@seZdZdZdd�ZdS)rz>
    Map each requirement to the extras that demanded it.
    cs.�fdd�|j�f�dD�}�jp,t|�S)z�
        Evaluate markers for req against each extra that
        demanded it.

        Return False if the req has a marker and fails
        evaluation. Otherwise, return True.
        c3s|]}�jjd|i�VqdS)�extraN)�marker�evaluate)�.0r()r�rr�	<genexpr>�sz*_ReqExtras.markers_pass.<locals>.<genexpr>N)N)rBr)�any)rr�Zextra_evalsr)r�rr�s	
z_ReqExtras.markers_passN)rrrrrrrrrr�src@sxeZdZdZde�efdd�Zdd�Zdd�Zdd	d
�Z	dd�Z
d
d�Zddd�Zddd�Z
dd�Zdd�Zdd�ZdS)r�z5Searchable snapshot of distributions on a search pathNcCs i|_||_||_|j|�dS)a!Snapshot distributions available on a search path

        Any distributions found on `search_path` are added to the environment.
        `search_path` should be a sequence of ``sys.path`` items.  If not
        supplied, ``sys.path`` is used.

        `platform` is an optional string specifying the name of the platform
        that platform-specific distributions must be compatible with.  If
        unspecified, it defaults to the current platform.  `python` is an
        optional string naming the desired version of Python (e.g. ``'3.3'``);
        it defaults to the current version.

        You may explicitly set `platform` (and/or `python`) to ``None`` if you
        wish to map *all* distributions, not just those compatible with the
        running platform or Python version.
        N)�_distmaprl�python�scan)r�search_pathrlr/rrrr�szEnvironment.__init__cCs.|jdks |jdks |j|jko,t|j|j�S)z�Is distribution `dist` acceptable for this environment?

        The distribution must match the platform and python version
        requirements specified when this environment was created, or False
        is returned.
        N)r/�
py_versionr�rl)rr�rrr�can_addszEnvironment.can_addcCs|j|jj|�dS)z"Remove `dist` from the environmentN)r.r'�remove)rr�rrrr4(szEnvironment.removecCs<|dkrtj}x(|D] }xt|�D]}|j|�q"WqWdS)adScan `search_path` for distributions usable in this environment

        Any distributions found are added to the environment.
        `search_path` should be a sequence of ``sys.path`` items.  If not
        supplied, ``sys.path`` is used.  Only distributions conforming to
        the platform/python version defined at initialization are added.
        N)rkr�r�r)rr1rr�rrrr0,s

zEnvironment.scancCs|j�}|jj|g�S)aReturn a newest-to-oldest list of distributions for `project_name`

        Uses case-insensitive `project_name` comparison, assuming all the
        project's distributions use their project's name converted to all
        lowercase as their key.

        )r8r.rB)rrZdistribution_keyrrrr(;szEnvironment.__getitem__cCsL|j|�rH|j�rH|jj|jg�}||krH|j|�|jtjd�dd�dS)zLAdd `dist` if we ``can_add()`` it and it has not already been added
        �hashcmpT)r'�reverseN)	r3�has_versionr.rr'r;r!�operator�
attrgetter)rr�rrrrrFs

zEnvironment.addcCsB|j|�}|dk	r|Sx||jD]}||kr"|Sq"W|j||�S)a�Find distribution best matching `req` and usable on `working_set`

        This calls the ``find(req)`` method of the `working_set` to see if a
        suitable distribution is already active.  (This may raise
        ``VersionConflict`` if an unsuitable version of the project is already
        active in the specified `working_set`.)  If a suitable distribution
        isn't active, this method returns the newest distribution in the
        environment that meets the ``Requirement`` in `req`.  If no suitable
        distribution is found, and `installer` is supplied, then the result of
        calling the environment's ``obtain(req, installer)`` method will be
        returned.
        N)r�r'�obtain)rr�r�r r�rrrrOs
zEnvironment.best_matchcCs|dk	r||�SdS)a�Obtain a distribution matching `requirement` (e.g. via download)

        Obtain a distro that matches requirement (e.g. via download).  In the
        base ``Environment`` class, this routine just returns
        ``installer(requirement)``, unless `installer` is None, in which case
        None is returned instead.  This method is a hook that allows subclasses
        to attempt other ways of obtaining a distribution before falling back
        to the `installer` argument.Nr)rZrequirementr rrrr:es	zEnvironment.obtainccs&x |jj�D]}||r|VqWdS)z=Yield the unique project names of the available distributionsN)r.r)rr'rrrrGqszEnvironment.__iter__cCs^t|t�r|j|�nDt|t�rLx8|D] }x||D]}|j|�q4Wq&Wntd|f��|S)z2In-place addition of a distribution or environmentzCan't add %r to environment)rr�rr�r�)rr!Zprojectr�rrr�__iadd__ws


zEnvironment.__iadd__cCs.|jgddd�}x||fD]}||7}qW|S)z4Add an environment or distribution to an environmentN)rlr/)r)rr!�newrrrr�__add__�szEnvironment.__add__)N)N)N)rrrrrs�PY_MAJORr�r3r4r0r(rrr:rGr;r=rrrrr�s
	

c@seZdZdZdS)r�aTAn error occurred extracting a resource

    The following attributes are available from instances of this exception:

    manager
        The resource manager that raised this exception

    cache_path
        The base directory for resource extraction

    original_error
        The exception instance that caused extraction to fail
    N)rrrrrrrrr��s
c@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zffdd�Z
edd��Zdd�Zdd�Zddd�ZdS)r�z'Manage resource extraction and packagesNcCs
i|_dS)N)�cached_files)rrrrr��szResourceManager.__init__cCst|�j|�S)zDoes the named resource exist?)rvr�)r�package_or_requirementr�rrrr��szResourceManager.resource_existscCst|�j|�S)z,Is the named resource an existing directory?)rvr�)rr@r�rrrr��szResourceManager.resource_isdircCst|�j||�S)z4Return a true filesystem path for specified resource)rvr�)rr@r�rrrr~�sz!ResourceManager.resource_filenamecCst|�j||�S)z9Return a readable file-like object for specified resource)rvr�)rr@r�rrrr}�szResourceManager.resource_streamcCst|�j||�S)z%Return specified resource as a string)rvr�)rr@r�rrrr|�szResourceManager.resource_stringcCst|�j|�S)z1List the contents of the named resource directory)rvr)rr@r�rrrr�sz ResourceManager.resource_listdircCsRtj�d}|jpt�}tjd�j�}t|jft	���}||_
||_||_|�dS)z5Give an error message for problems extracting file(s)r-a
            Can't extract file(s) to egg cache

            The following error occurred while trying to extract file(s) to the Python egg
            cache:

              {old_exc}

            The Python egg cache directory is currently set to:

              {cache_path}

            Perhaps your account does not have write access to this directory?  You can
            change the cache directory by setting the PYTHON_EGG_CACHE environment
            variable to point to an accessible directory.
            N)
rk�exc_info�extraction_pathr��textwrap�dedent�lstripr�r�r�r��
cache_pathZoriginal_error)r�old_excrF�tmpl�errrrr�extraction_error�s
z ResourceManager.extraction_errorc	Cs^|jp
t�}tjj||df|��}yt|�Wn|j�YnX|j|�d|j|<|S)a�Return absolute location in cache for `archive_name` and `names`

        The parent directory of the resulting path will be created if it does
        not already exist.  `archive_name` should be the base filename of the
        enclosing egg (which may not be the name of the enclosing zipfile!),
        including its ".egg" extension.  `names`, if provided, should be a
        sequence of path name parts "under" the egg's extraction location.

        This method should only be called by resource providers that need to
        obtain an extraction location, and only for names they intend to
        extract, as it tracks the generated names for possible cleanup later.
        z-tmpr-)	rBr�r�r�rm�_bypass_ensure_directoryrJ�_warn_unsafe_extraction_pathr?)rZarchive_name�namesZextract_pathZtarget_pathrrr�get_cache_path�s


zResourceManager.get_cache_pathcCsXtjdkr |jtjd�r dStj|�j}|tj@s@|tj@rTd|}tj	|t
�dS)aN
        If the default extraction path is overridden and set to an insecure
        location, such as /tmp, it opens up an opportunity for an attacker to
        replace an extracted file with an unauthorized payload. Warn the user
        if a known insecure location is used.

        See Distribute #375 for more details.
        �ntZwindirNz�%s is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).)r�r�r9�environ�stat�st_mode�S_IWOTH�S_IWGRPrCrD�UserWarning)r��mode�msgrrrrL�s
z,ResourceManager._warn_unsafe_extraction_pathcCs.tjdkr*tj|�jdBd@}tj||�dS)a4Perform any platform-specific postprocessing of `tempname`

        This is where Mac header rewrites should be done; other platforms don't
        have anything special they should do.

        Resource providers should call this method ONLY after successfully
        extracting a compressed resource.  They must NOT call it on resources
        that are already in the filesystem.

        `tempname` is the current (temporary) name of the file, and `filename`
        is the name it will be renamed to by the caller after this routine
        returns.
        �posiximi�N)r�r�rQrR�chmod)rZtempname�filenamerVrrr�postprocesss
zResourceManager.postprocesscCs|jrtd��||_dS)a�Set the base path where resources will be extracted to, if needed.

        If you do not call this routine before any extractions take place, the
        path defaults to the return value of ``get_default_cache()``.  (Which
        is based on the ``PYTHON_EGG_CACHE`` environment variable, with various
        platform-specific fallbacks.  See that routine's documentation for more
        details.)

        Resources are extracted to subdirectories of this path based upon
        information given by the ``IResourceProvider``.  You may set this to a
        temporary directory, but then you must call ``cleanup_resources()`` to
        delete the extracted files when done.  There is no guarantee that
        ``cleanup_resources()`` will be able to remove all extracted files.

        (Note: you may not change the extraction path for a given resource
        manager once resources have been extracted, unless you first call
        ``cleanup_resources()``.)
        z5Can't change extraction path, files already extractedN)r?rprB)rr�rrrr�)sz#ResourceManager.set_extraction_pathFcCsdS)aB
        Delete all extracted resource files and directories, returning a list
        of the file and directory names that could not be successfully removed.
        This function does not have any concurrency protection, so it should
        generally only be called when the extraction path is a temporary
        directory exclusive to a single process.  This method is not
        automatically called; you must call it explicitly or register it as an
        ``atexit`` function if you wish to ensure cleanup of a temporary
        directory used for extractions.
        Nr)r�forcerrrr�Csz!ResourceManager.cleanup_resources)F)rrrrrBr�r�r�r~r}r|rrJrN�staticmethodrLr[r�r�rrrrr��scCstjjd�ptjdd�S)z�
    Return the ``PYTHON_EGG_CACHE`` environment variable
    or a platform-relevant user cache dir for an app
    named "Python-Eggs".
    ZPYTHON_EGG_CACHEzPython-Eggs)Zappname)r�rPrBrZuser_cache_dirrrrrr�QscCstjdd|�S)z�Convert an arbitrary string to a standard distribution name

    Any runs of non-alphanumeric/. characters are replaced with a single '-'.
    z[^A-Za-z0-9.]+r+)r?�sub)r�rrrr�]scCsDyttjj|��Stjjk
r>|jdd�}tjdd|�SXdS)zB
    Convert an arbitrary string to a standard version string
    r�r,z[^A-Za-z0-9.]+r+N)rFrrK�VersionrLr5r?r^)rKrrrr�es
cCstjdd|�j�S)z�Convert an arbitrary string to a standard 'extra' name

    Any runs of non-alphanumeric characters are replaced with a single '_',
    and the result is always lowercased.
    z[^A-Za-z0-9.-]+r�)r?r^r8)r(rrrr�qscCs|jdd�S)z|Convert a project or version name to its filename-escaped form

    Any '-' characters are currently replaced with '_'.
    r+r�)r5)r�rrrr�zscCs>yt|�Wn,tk
r8}zd|_d|_|Sd}~XnXdS)zo
    Validate text as a PEP 508 environment marker; return an exception
    if invalid or False otherwise.
    NF)r��SyntaxErrorrZ�lineno)�text�errrr��scCsHytjj|�}|j�Stjjk
rB}zt|��WYdd}~XnXdS)z�
    Evaluate a PEP 508 environment marker.
    Return a boolean indicating the marker result in this environment.
    Raise SyntaxError if marker is invalid.

    This implementation uses the 'pyparsing' module.
    N)rZmarkersZMarkerr*Z
InvalidMarkerr`)rbr(r)rcrrrr��s
c@s�eZdZdZdZdZdZdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�ZdS)'r�zETry to implement resources and metadata for arbitrary PEP 302 loadersNcCs(t|dd�|_tjjt|dd��|_dS)Nr��__file__r�)r�r�r�r��dirname�module_path)rr�rrrr��szNullProvider.__init__cCs|j|j|�S)N)�_fnrf)rr�r�rrrr��sz"NullProvider.get_resource_filenamecCstj|j||��S)N)�io�BytesIOr�)rr�r�rrrr��sz NullProvider.get_resource_streamcCs|j|j|j|��S)N)�_getrgrf)rr�r�rrrr��sz NullProvider.get_resource_stringcCs|j|j|j|��S)N)�_hasrgrf)rr�rrrr��szNullProvider.has_resourcecCs|jo|j|j|j|��S)N)�egg_inforkrg)rr�rrrr��szNullProvider.has_metadatacCs2|js
dS|j|j|j|��}tjr.|jd�S|S)Nr�zutf-8)rlrjrgrZPY3�decode)rr��valuerrrr��szNullProvider.get_metadatacCst|j|��S)N)r�r�)rr�rrrr��szNullProvider.get_metadata_linescCs|j|j|j|��S)N)�_isdirrgrf)rr�rrrr��szNullProvider.resource_isdircCs|jo|j|j|j|��S)N)rlrorg)rr�rrrr��szNullProvider.metadata_isdircCs|j|j|j|��S)N)�_listdirrgrf)rr�rrrr�szNullProvider.resource_listdircCs|jr|j|j|j|��SgS)N)rlrprg)rr�rrrr��szNullProvider.metadata_listdirc
Cs�d|}|j|�std|��|j|�jdd�}|jdd�}|j|j|�}||d<tjj|�r�t	|�j
�}t||d�}t|||�n>dd	l
m}t|�d|jd�|f||<t||d�}	t|	||�dS)
Nzscripts/zNo script named %rz
�
�
rd�execr)�cache)r�r�r�r5rgrlr�r�r�r�readr@rs�	linecachert�lenr)
rr�r�ZscriptZscript_textZscript_filename�source�codertZscript_coderrrru�s
zNullProvider.run_scriptcCstd��dS)Nz9Can't perform this operation for unregistered loader type)�NotImplementedError)rr�rrrrk�szNullProvider._hascCstd��dS)Nz9Can't perform this operation for unregistered loader type)rz)rr�rrrro�szNullProvider._isdircCstd��dS)Nz9Can't perform this operation for unregistered loader type)rz)rr�rrrrp�szNullProvider._listdircCs |rtjj|f|jd���S|S)N�/)r�r�rmr)r�baser�rrrrg�szNullProvider._fncCs$t|jd�r|jj|�Std��dS)N�get_dataz=Can't perform this operation for loaders without 'get_data()')r�r�r}rz)rr�rrrrj�szNullProvider._get)rrrr�egg_namerlr�r�r�r�r�r�r�r�r�r�r�rr�rurkrorprgrjrrrrr��s,c@s eZdZdZdd�Zdd�ZdS)r�z&Provider based on a virtual filesystemcCstj||�|j�dS)N)r�r��
_setup_prefix)rr�rrrr�szEggProvider.__init__cCs^|j}d}xN||krXt|�rBtjj|�|_tjj|d�|_||_P|}tjj	|�\}}qWdS)NzEGG-INFO)
rf�_is_unpacked_eggr�r��basenamer~rmrl�egg_rootr)rr��oldr|rrrr
s
zEggProvider._setup_prefixN)rrrrr�rrrrrr�sc@sDeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	dd
��Z
dS)r�z6Provides access to package resources in the filesystemcCstjj|�S)N)r�r�r�)rr�rrrrkszDefaultProvider._hascCstjj|�S)N)r�r�r
)rr�rrrroszDefaultProvider._isdircCs
tj|�S)N)r��listdir)rr�rrrrp"szDefaultProvider._listdircCst|j|j|�d�S)N�rb)rrgrf)rr�r�rrrr�%sz#DefaultProvider.get_resource_streamc	Cst|d��
}|j�SQRXdS)Nr�)rru)rr��streamrrrrj(szDefaultProvider._getcCsttdtd��}t||�dS)N�SourceFileLoader)r��importlib_machinery�typer�)rZ
loader_clsrrr�	_register,s
zDefaultProvider._registerN)rrrrrkrorpr�rjr'r�rrrrr�sc@s8eZdZdZdd�ZZdd�Zdd�ZdZdd�Z	dS)	r�z.Provider that returns nothing for all requestscCsdS)NFr)rr�rrrre9szEmptyProvider.<lambda>cCsdS)Nr�r)rr�rrrre:scCsgS)Nr)rr�rrrre;sNcCsdS)Nr)rrrrr�>szEmptyProvider.__init__)
rrrrrorkrjrprfr�rrrrr�6sc@s eZdZdZedd��ZeZdS)�ZipManifestsz
    zip manifest builder
    c
s2t|�� ��fdd��j�D�}t|�SQRXdS)a
        Build a dictionary similar to the zipimport directory
        caches, except instead of tuples, store ZipInfo objects.

        Use a platform-specific path separator (os.sep) for the path keys
        for compatibility with pypy on Windows.
        c3s&|]}|jdtj��j|�fVqdS)r{N)r5r��sepZgetinfo)r+r�)�zfilerrr,Usz%ZipManifests.build.<locals>.<genexpr>N)�ContextualZipFileZnamelistrR)rr�rVr)r�r�buildJs	

zZipManifests.buildN)rrrrr'r��loadrrrrr�Esr�c@s$eZdZdZejdd�Zdd�ZdS)�MemoizedZipManifestsz%
    Memoized zipfile manifests.
    �manifest_modzmanifest mtimecCsRtjj|�}tj|�j}||ks.||j|krH|j|�}|j||�||<||jS)zW
        Load a manifest at path or return a suitable manifest already loaded.
        )	r�r��normpathrQ�st_mtime�mtimer�r��manifest)rr�r�r�rrrr�fs
zMemoizedZipManifests.loadN)rrrrr�
namedtupler�r�rrrrr�`sr�cs0eZdZdZdd�Zdd�Z�fdd�Z�ZS)r�zL
    Supplement ZipFile class to support context manager for Python 2.6
    cCs|S)Nr)rrrr�	__enter__yszContextualZipFile.__enter__cCs|j�dS)N)�close)rr�rn�	tracebackrrr�__exit__|szContextualZipFile.__exit__cs(ttjd�rtj||�Stt|�j|�S)zI
        Construct a ZipFile or ContextualZipFile as appropriate
        r�)r��zipfile�ZipFilerr��__new__)rrd�kwargs)rrrr�szContextualZipFile.__new__)rrrrr�r�r�rHrr)rrr�tsr�c@s�eZdZdZdZe�Zdd�Zdd�Zdd�Z	e
d	d
��Zdd�Ze
d
d��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �ZdS)!r�z"Resource support for zips and eggsNcCs tj||�|jjtj|_dS)N)r�r�r��archiver�r��zip_pre)rr�rrrr��szZipProvider.__init__cCs4|j|j�r|t|j�d�Std||jf��dS)Nz%s is not a subpath of %s)r9r�rw�AssertionError)r�fspathrrr�
_zipinfo_name�szZipProvider._zipinfo_namecCsP|j|}|j|jtj�r:|t|j�dd�jtj�Std||jf��dS)Nr-z%s is not a subpath of %s)r�r9r�r�r�rwrr�)r�zip_pathr�rrr�_parts�s

zZipProvider._partscCs|jj|jj�S)N)�_zip_manifestsr�r�r�)rrrr�zipinfo�szZipProvider.zipinfocCs`|jstd��|j|�}|j�}dj|j|��|krTx|D]}|j||j|��q:W|j||�S)Nz5resource_filename() only supported for .egg, not .zipr{)r~rz�_resource_to_zip�_get_eager_resourcesrmr��_extract_resource�
_eager_to_zip)rr�r�r��eagersr�rrrr��s

z!ZipProvider.get_resource_filenamecCs"|j}|jd}tj|�}||fS)Nrr-r7)rrr7)Z	file_size�	date_time�timeZmktime)Zzip_stat�sizer��	timestamprrr�_get_date_and_size�s

zZipProvider._get_date_and_sizec
Csn||j�krDx*|j�|D]}|j|tjj||��}qWtjj|�S|j|j|�\}}tsdt	d��y�|j
|j|j|��}|j
||�r�|Stdtjj|�d�\}}	tj||jj|��tj|�t|	||f�|j|	|�yt|	|�Wn\tjk
�rDtjj|��r>|j
||��r|Stjdk�r>t|�t|	|�|S�YnXWn tjk
�rh|j�YnX|S)Nz>"os.rename" and "os.unlink" are not supported on this platformz	.$extract)�dirrO)�_indexr�r�r�rmrer�r��
WRITE_SUPPORT�IOErrorrNr~r��_is_current�_mkstemp�writer�r}r�rr[r
�error�isfiler�rrJ)
rr�r�r�Zlastr�r�Z	real_pathZoutfZtmpnamrrrr��s@

zZipProvider._extract_resourcec		Csx|j|j|�\}}tjj|�s$dStj|�}|j|ksB|j|krFdS|jj	|�}t
|d��}|j�}WdQRX||kS)zK
        Return True if the file_path is current for this zip_path
        Fr�N)r�r�r�r�r�rQ�st_sizer�r�r}rru)	rZ	file_pathr�r�r�rQZzip_contents�fZ
file_contentsrrrr��s
zZipProvider._is_currentcCsB|jdkr<g}x&dD]}|j|�r|j|j|��qW||_|jS)N�native_libs.txt�eager_resources.txt)r�r�)r�r�rr�)rr�r�rrrr�s


z ZipProvider._get_eager_resourcescCs�y|jStk
r�i}xd|jD]Z}|jtj�}xH|rztjj|dd��}||krj||j|d�Pq4|j�g||<q4Wq"W||_|SXdS)Nr-r7r7)	Z	_dirindex�AttributeErrorr�rr�r�rmr;r:)rZindr�r<�parentrrrr�szZipProvider._indexcCs |j|�}||jkp||j�kS)N)r�r�r�)rr�r�rrrrks
zZipProvider._hascCs|j|�|j�kS)N)r�r�)rr�rrrro!szZipProvider._isdircCst|j�j|j|�f��S)N)rr�rBr�)rr�rrrrp$szZipProvider._listdircCs|j|j|j|��S)N)r�rgr�)rr�rrrr�'szZipProvider._eager_to_zipcCs|j|j|j|��S)N)r�rgrf)rr�rrrr�*szZipProvider._resource_to_zip)rrrrr�r�r�r�r�r�r�r�r�r]r�r�r�r�r�rkrorpr�r�rrrrr��s$	

	4	c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
r�a*Metadata handler for standalone PKG-INFO files

    Usage::

        metadata = FileMetadata("/path/to/PKG-INFO")

    This provider rejects all data and metadata requests except for PKG-INFO,
    which is treated as existing, and will be the contents of the file at
    the provided location.
    cCs
||_dS)N)r�)rr�rrrr�=szFileMetadata.__init__cCs|dkotjj|j�S)NzPKG-INFO)r�r�r�)rr�rrrr�@szFileMetadata.has_metadatac	CsD|dkrtd��tj|jddd��}|j�}WdQRX|j|�|S)NzPKG-INFOz(No metadata except PKG-INFO is availablezutf-8r5)�encoding�errors)r�rhrr�ru�_warn_on_replacement)rr�r��metadatarrrr�Cs
zFileMetadata.get_metadatacCs2djd�}||kr.d}|jft��}tj|�dS)Ns�zutf-8z2{self.path} could not be properly decoded in UTF-8)rmr�r�rCrD)rr�Zreplacement_charrHrWrrrr�Ls

z!FileMetadata._warn_on_replacementcCst|j|��S)N)r�r�)rr�rrrr�TszFileMetadata.get_metadata_linesN)	rrrrr�r�r�r�r�rrrrr�1s
	c@seZdZdZdd�ZdS)r�asMetadata provider for egg directories

    Usage::

        # Development eggs:

        egg_info = "/path/to/PackageName.egg-info"
        base_dir = os.path.dirname(egg_info)
        metadata = PathMetadata(base_dir, egg_info)
        dist_name = os.path.splitext(os.path.basename(egg_info))[0]
        dist = Distribution(basedir, project_name=dist_name, metadata=metadata)

        # Unpacked egg directories:

        egg_path = "/path/to/PackageName-ver-pyver-etc.egg"
        metadata = PathMetadata(egg_path, os.path.join(egg_path,'EGG-INFO'))
        dist = Distribution.from_filename(egg_path, metadata=metadata)
    cCs||_||_dS)N)rfrl)rr�rlrrrr�lszPathMetadata.__init__N)rrrrr�rrrrr�Xsc@seZdZdZdd�ZdS)r�z Metadata provider for .egg filescCsD|jtj|_||_|jr0tjj|j|j�|_n|j|_|j	�dS)z-Create a metadata provider from a zipimporterN)
r�r�r�r�r��prefixr�rmrfr)r�importerrrrr�tszEggMetadata.__init__N)rrrrr�rrrrr�qsrR)�_distribution_finderscCs|t|<dS)axRegister `distribution_finder` to find distributions in sys.path items

    `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
    handler), and `distribution_finder` is a callable that, passed a path
    item and the importer instance, yields ``Distribution`` instances found on
    that path item.  See ``pkg_resources.find_on_path`` for an example.N)r�)�
importer_typeZdistribution_finderrrrr��scCst|�}tt|�}||||�S)z.Yield distributions accessible via `path_item`)rr�r�)�	path_item�onlyr��finderrrrr��s
ccs�|jjd�rdSt|�}|jd�r2tj||d�V|r:dSxH|jd�D]:}t|�rFtj	j
||�}xttj
|�|�D]
}|VqrWqFWdS)z@
    Find eggs in zip files; possibly multiple nested eggs.
    z.whlNzPKG-INFO)r�r{)r��endswithr�r�r��
from_filenamerr�r�r�rm�find_eggs_in_zip�	zipimport�zipimporter)r�r�r�r�Zsubitem�subpathr�rrrr��s
r�cCsfS)Nr)r�r�r�rrr�find_nothing�sr�cCsdd�}t||dd�S)aL
    Given a list of filenames, return them in descending order
    by version number.

    >>> names = 'bar', 'foo', 'Python-2.7.10.egg', 'Python-2.7.2.egg'
    >>> _by_version_descending(names)
    ['Python-2.7.10.egg', 'Python-2.7.2.egg', 'foo', 'bar']
    >>> names = 'Setuptools-1.2.3b1.egg', 'Setuptools-1.2.3.egg'
    >>> _by_version_descending(names)
    ['Setuptools-1.2.3.egg', 'Setuptools-1.2.3b1.egg']
    >>> names = 'Setuptools-1.2.3b1.egg', 'Setuptools-1.2.3.post1.egg'
    >>> _by_version_descending(names)
    ['Setuptools-1.2.3.post1.egg', 'Setuptools-1.2.3b1.egg']
    cSs2tjj|�\}}tj|jd�|g�}dd�|D�S)z6
        Parse each component of the filename
        r+cSsg|]}tjj|��qSr)rrKr�)r+r3rrr�
<listcomp>�sz?_by_version_descending.<locals>._by_version.<locals>.<listcomp>)r�r��splitext�	itertools�chainr)r��extr<rrr�_by_version�sz+_by_version_descending.<locals>._by_versionT)r'r6)�sorted)rMr�rrr�_by_version_descending�sr�ccs�t|�}tjj|�o tj|tj��r�t|�rPtj|t	|tjj
|d��d�V�nTttj|��}�xB|D�]8}|j
�}|jd�s�|jd�r�tjj
||�}tjj|�r�ttj|��dkr�qft	||�}nt|�}tj|||td�Vqf|o�t|��rttjj
||��}x�|D]}	|	V�qWqf|rf|jd�rfttjj
||���}
|
j�}WdQRXxN|D]F}|j��sh�qVtjj
||j��}
t|
�}x|D]}|V�q�WP�qVWqfWdS)	z6Yield distributions accessible on a sys.path directoryzEGG-INFO)r�z	.egg-infoz
.dist-infor)�
precedencez	.egg-linkN)�_normalize_cachedr�r�r
�access�R_OKr�r�r�r�rmr�r�r8r�rwr��
from_locationr�r�r�	readlines�strip�rstrip)r�r�r�Zpath_item_entriesr�r8Zfullpathr�rr�Z
entry_fileZentry_lines�liner�rrrr�find_on_path�sB



r��
FileFinder)�_namespace_handlers)�_namespace_packagescCs|t|<dS)a�Register `namespace_handler` to declare namespace packages

    `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
    handler), and `namespace_handler` is a callable like this::

        def namespace_handler(importer, path_entry, moduleName, module):
            # return a path_entry to use for child packages

    Namespace handlers are only called if the importer object has already
    agreed that it can handle the relevant path item, and they should only
    return a subpath if the module __path__ does not already contain an
    equivalent subpath.  For an example namespace handler, see
    ``pkg_resources.file_ns_handler``.
    N)r�)r�Znamespace_handlerrrrr�scCs�t|�}|dkrdS|j|�}|dkr*dStjj|�}|dkrbtj|�}tj|<g|_t|�nt	|d�svt
d|��tt|�}|||||�}|dk	r�|j}|j
|�|j|�t|||�|S)zEEnsure that named package includes a subpath of path_item (if needed)N�__path__zNot a package:)r�find_modulerkr�rB�types�
ModuleTyper��_set_parent_nsr�r�r�r�r;�load_module�_rebuild_mod_path)�packageNamer�r�r�r�Zhandlerr�r�rrr�
_handle_nss*






r�csRdd�tjD���fdd����fdd�}|j|d�dd�|D�|jd	d	�<d	S)
zq
    Rebuild module.__path__ ensuring that all entries are ordered
    corresponding to their sys.path order
    cSsg|]}t|��qSr)r�)r+�prrrr�5sz%_rebuild_mod_path.<locals>.<listcomp>cs(y
�j|�Stk
r"td�SXdS)z/
        Workaround for #520 and #513.
        �infN)�indexrp�float)r�)�sys_pathrr�safe_sys_path_index7s
z._rebuild_mod_path.<locals>.safe_sys_path_indexcs<|jtj�}�jd�d}|d|�}�ttjj|���S)zR
        Return the ordinal of the path based on its position in sys.path
        r,r-N)rr�r��countr�rm)r��
path_partsZmodule_partsr<)�package_namer�rr�position_in_sys_path@sz/_rebuild_mod_path.<locals>.position_in_sys_path)r'cSsg|]}t|��qSr)r�)r+r�rrrr�JsN)rkr�r!r�)Z	orig_pathr�r�r�r)r�r�r�rr�0s
		r�cCs�tj�z�|tkrdStjd}}d|kr�dj|jd�dd��}t|�|tkrZt|�ytj	|j
}Wntk
r�td|��YnXtj
|g�j|�tj
|g�x|D]}t||�q�WWdtj�XdS)z9Declare that package 'packageName' is a namespace packageNr,r-zNot a package:r7)�_imp�acquire_lockr�rkr�rmrr�r�r�r�r�r�rr;r��release_lock)r�r�r�r�rrrr�Ms&
c
CsJtj�z2x,tj|f�D]}t||�}|rt||�qWWdtj�XdS)zDEnsure that previously-declared namespace packages include path_itemN)r�r�r�rBr�r�r�)r�r��packager�rrrr�ns
cCsFtjj||jd�d�}t|�}x |jD]}t|�|kr(Pq(W|SdS)zBCompute an ns-package subpath for a filesystem or zipfile importerr,r-Nr7)r�r�rmrr�r�)r�r�r�r�r�Z
normalizedrrrr�file_ns_handlerzsrcCsdS)Nr)r�r�r�r�rrr�null_ns_handler�srcCstjjtjj|��S)z1Normalize a file/dir name for comparison purposes)r�r��normcase�realpath)rZrrrr��scCs2y||Stk
r,t|�||<}|SXdS)N)r�r�)rZr��resultrrrr��s
r�cCs|j�jd�S)z@
    Determine if given path appears to be an unpacked egg.
    z.egg)r8r�)r�rrrr��sr�cCs<|jd�}|j�}|r8dj|�}ttj||tj|�dS)Nr,)rr:rm�setattrrkr�)r�r<r�r�rrrr��s


r�ccsht|tj�r>xV|j�D]"}|j�}|r|jd�r|VqWn&x$|D]}xt|�D]
}|VqRWqDWdS)z9Yield non-empty/non-comment lines of a string or sequence�#N)rrr��
splitlinesr�r9r�)�strsr2Zssrrrr��s
z\w+(\.\w+)*$z�
    (?P<name>[^-]+) (
        -(?P<ver>[^-]+) (
            -py(?P<pyver>[^-]+) (
                -(?P<plat>.+)
            )?
        )?
    )?
    c@s�eZdZdZffdfdd�Zdd�Zdd�Zdd
d�Zdd
�Zddd�Z	e
jd�Ze
ddd��Ze
dd��Ze
ddd��Ze
ddd��ZdS)r�z3Object representing an advertised importable objectNcCsJt|�std|��||_||_t|�|_tjddj|��j	|_	||_
dS)NzInvalid module namezx[%s]�,)�MODULErpr��module_namer�attrsr�r�rmrr�)rr�rrrr�rrrr��s

zEntryPoint.__init__cCsHd|j|jf}|jr*|ddj|j�7}|jrD|ddj|j�7}|S)Nz%s = %s�:r,z [%s]r	)r�rrrmr)rr2rrrr��szEntryPoint.__str__cCsdt|�S)NzEntryPoint.parse(%r))rF)rrrrr��szEntryPoint.__repr__TcOs6|s|s|rtjdtdd�|r.|j||�|j�S)zH
        Require packages for this EntryPoint, then resolve it.
        zJParameters to load are deprecated.  Call .resolve and .require separately.rg)r>)rCrD�DeprecationWarningrtr)rrtrdr�rrrr��szEntryPoint.loadcCsVt|jdgdd�}ytjt|j|�Stk
rP}ztt|���WYdd}~XnXdS)zD
        Resolve the entry point from its module and attrs.
        rr)�fromlist�levelN)	r�r�	functools�reducer�rr�r�rF)rr��excrrrr�s
zEntryPoint.resolvecCsH|jr|jrtd|��|jj|j�}tj|||�}tttj|��dS)Nz&Can't require() without a distribution)	rr�r�rr�rrrr)rrr rrVrrrrt	s

zEntryPoint.requirez]\s*(?P<name>.+?)\s*=\s*(?P<module>[\w.]+)\s*(:\s*(?P<attr>[\w.]+))?\s*(?P<extras>\[.*\])?\s*$cCsf|jj|�}|sd}t||��|j�}|j|d�}|drJ|djd�nf}||d|d|||�S)aParse a single entry point from string `src`

        Entry point syntax follows the form::

            name = some.module:some.attr [extra1, extra2]

        The entry name and module name are required, but the ``:attrs`` and
        ``[extras]`` parts are optional
        z9EntryPoint must be in 'name=module:attrs [extras]' formatr�attrr,r�r�)�patternrjrp�	groupdict�
_parse_extrasr)r�srcr�rrrW�resrrrrrr�	s
zEntryPoint.parsecCs(|sfStjd|�}|jr"t��|jS)N�x)r�r��specsrpr)rZextras_specr�rrrr$	szEntryPoint._parse_extrascCsZt|�std|��i}x>t|�D]2}|j||�}|j|krHtd||j��|||j<q W|S)zParse an entry point groupzInvalid group namezDuplicate entry point)r
rpr�r�r�)rro�linesr��thisr�rrrr�parse_group-	s

zEntryPoint.parse_groupcCsxt|t�r|j�}nt|�}i}xR|D]J\}}|dkrD|s<q&td��|j�}||kr^td|��|j|||�||<q&W|S)z!Parse a map of entry point groupsNz%Entry points must be listed in groupszDuplicate group name)rrRrVr�rpr�r)r�datar��mapsrorrrr�	parse_map:	s


zEntryPoint.parse_map)T)NN)N)N)N)rrrrr�r�r�r�rrtr?r@rr'r�rrr!rrrrr��s 	


	cCs>|sdStjj|�}|djd�r:tjj|dd�d�S|S)Nr�r-zmd5=r7r7)r�)rr�Zurlparser9Z
urlunparse)rZparsedrrr�_remove_md5_fragmentN	sr"cCs@dd�}t||�}tt|�d�}|jd�\}}}t|j��p>dS)z�
    Given an iterable of lines from a Metadata file, return
    the value of the Version field, if present, or None otherwise.
    cSs|j�jd�S)Nzversion:)r8r9)r�rrrre\	sz$_version_from_file.<locals>.<lambda>r�r
N)r�next�iter�	partitionr�r�)rZis_version_lineZ
version_linesr�r�rnrrr�_version_from_fileW	s

r&c@sZeZdZdZdZddddedefdd�ZedGdd��Z	dd	�Z
ed
d��Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zedd��Zedd��Zdd�Zed d!��Zed"d#��Zffd$d%�Zd&d'�ZdHd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�ZedId3d4��Z d5d6�Z!d7d8�Z"dJd9d:�Z#d;d<�Z$dKd=d>�Z%d?d@�Z&dAdB�Z'dCdD�Z(edEdF��Z)dS)Lr�z5Wrap an actual or potential sys.path entry w/metadatazPKG-INFONcCsFt|pd�|_|dk	r t|�|_||_||_||_||_|p>t|_	dS)NZUnknown)
r�rr��_versionr2rlrr�r��	_provider)rrr�rrKr2rlr�rrrr�g	s
zDistribution.__init__cKs~dgd\}}}}tjj|�\}}	|	j�tkr^t|	j�}t|�}
|
r^|
jdddd�\}}}}|||f||||d�|��j�S)Nr�r�ZverZpyverrq)rrKr2rl)r�r�r�r8�_distributionImpl�EGG_NAMEro�_reload_version)rrr�r�rTrrKr2rlr�rjrrrr�s	s
zDistribution.from_locationcCs|S)Nr)rrrrr+�	szDistribution._reload_versioncCs(|j|j|jt|j�|jpd|jp$dfS)Nr�)�parsed_versionr�r'r"rr2rl)rrrrr5�	szDistribution.hashcmpcCs
t|j�S)N)�hashr5)rrrrr�	szDistribution.__hash__cCs|j|jkS)N)r5)rr!rrrr �	szDistribution.__lt__cCs|j|jkS)N)r5)rr!rrrr"�	szDistribution.__le__cCs|j|jkS)N)r5)rr!rrrr%�	szDistribution.__gt__cCs|j|jkS)N)r5)rr!rrrr$�	szDistribution.__ge__cCst||j�sdS|j|jkS)NF)rrr5)rr!rrrr#�	szDistribution.__eq__cCs
||kS)Nr)rr!rrrr&�	szDistribution.__ne__cCs0y|jStk
r*|jj�|_}|SXdS)N)Z_keyr�rr8)rr'rrrr'�	s
zDistribution.keycCst|d�st|j�|_|jS)N�_parsed_version)r�rNrKr.)rrrrr,�	s
zDistribution.parsed_versioncCsXtjj}t|j|�}|sdS|js&dStjd�j�jdd�}t	j
|jft|��t
�dS)Na>
            '{project_name} ({version})' is being parsed as a legacy,
            non PEP 440,
            version. You may find odd behavior and sort order.
            In particular it will be sorted as less than 0.0. It
            is recommended to migrate to PEP 440 compatible
            versions.
            rqr�)rrK�
LegacyVersionrr.rCrDr�r5rCrDr��varsr)rZLVZ	is_legacyrHrrr�_warn_legacy_version�	sz!Distribution._warn_legacy_versioncCsLy|jStk
rFt|j|j��}|dkrBd}t||j|��|SXdS)Nz(Missing 'Version:' header and/or %s file)r'r�r&�
_get_metadata�PKG_INFOrp)rrKrHrrrrK�	szDistribution.versioncCs�y|jStk
r�dgi}|_x�dD]x}xrt|j|��D]`\}}|r�d|kr||jdd�\}}t|�rpg}nt|�s|g}t|�p�d}|j|g�j	t
|��q>Wq*W|SXdS)N�requires.txt�depends.txtr
r-)r4r5)Z_Distribution__dep_mapr�r�r2rr�r�r�rrr�)r�dmr�r(rr)rrr�_dep_map�	s 
zDistribution._dep_mapcCsj|j}g}|j|jdf��xH|D]@}y|j|t|��Wq"tk
r`td||f��Yq"Xq"W|S)z@List of Requirements needed for this distro if `extras` are usedNz%s has no such extra feature %r)r7rrBr�r�r�)rrr6Zdepsr�rrrr�	s
zDistribution.requiresccs(|j|�r$x|j|�D]
}|VqWdS)N)r�r�)rr�r�rrrr2
s
zDistribution._get_metadataFcCsZ|dkrtj}|j||d�|tjkrVt|j�x$|jd�D]}|tjkr<t|�q<WdS)z>Ensure distribution is importable on `path` (default=sys.path)N)r5znamespace_packages.txt)rkr�rr�rr2r�r�)rr�r5Zpkgrrr�activate	
s


zDistribution.activatecCs8dt|j�t|j�|jptf}|jr4|d|j7}|S)z@Return what this distribution's standard .egg filename should bez
%s-%s-py%sr+)r�rrKr2r>rl)rrZrrrr~
szDistribution.egg_namecCs |jrd||jfSt|�SdS)Nz%s (%s))rrF)rrrrr�
szDistribution.__repr__cCs@yt|dd�}Wntk
r(d}YnX|p0d}d|j|fS)NrKz[unknown version]z%s %s)r�rpr)rrKrrrr�%
s
zDistribution.__str__cCs|jd�rt|��t|j|�S)zADelegate all unrecognized public attributes to .metadata providerr�)r9r�r�r()rrrrr�__getattr__-
s
zDistribution.__getattr__cKs|jt|�tjj|�|f|�S)N)r�r�r�r�r�)rrZr�rTrrrr�3
szDistribution.from_filenamecCs<t|jtjj�r"d|j|jf}nd|j|jf}tj|�S)z?Return a ``Requirement`` that matches this distribution exactlyz%s==%sz%s===%s)rr,rrKr_rr�r�)r�specrrrr":
szDistribution.as_requirementcCs.|j||�}|dkr&td||ff��|j�S)z=Return the `name` entry point of `group` or raise ImportErrorNzEntry point %r not found)rzr�r�)rror�rrrrrxC
szDistribution.load_entry_pointcCsPy
|j}Wn,tk
r6tj|jd�|�}|_YnX|dk	rL|j|i�S|S)z=Return the entry point map for `group`, or the full entry mapzentry_points.txtN)Z_ep_mapr�r�r!r2rB)rroZep_maprrrryJ
s
zDistribution.get_entry_mapcCs|j|�j|�S)z<Return the EntryPoint object for `group`+`name`, or ``None``)ryrB)rror�rrrrzV
szDistribution.get_entry_infoc
Cs2|p|j}|sdSt|�}tjj|�}dd�|D�}x�t|�D]v\}}||kr\|rVPq�dSq>||kr>|jtkr>|r�|||d�kr�dS|tjkr�|j	�|j
||�|j
||�Pq>W|tjkr�|j	�|r�|j
d|�n
|j|�dSxBy|j||d�}	Wnt
k
�rPYq�X||	=||	=|	}q�WdS)a�Ensure self.location is on path

        If replace=False (default):
            - If location is already in path anywhere, do nothing.
            - Else:
              - If it's an egg and its parent directory is on path,
                insert just ahead of the parent.
              - Else: add to the end of path.
        If replace=True:
            - If location is already on path anywhere (not eggs)
              or higher priority than its parent (eggs)
              do nothing.
            - Else:
              - If it's an egg and its parent directory is on path,
                insert just ahead of the parent,
                removing any lower-priority entries.
              - Else: add it to the front of path.
        NcSsg|]}|rt|�p|�qSr)r�)r+r�rrrr�t
sz*Distribution.insert_on.<locals>.<listcomp>rr-)rr�r�r�re�	enumerater�r�rk�check_version_conflictrr;r�rp)
rr��locr5ZnlocZbdirZnpathr�rZnprrrrZ
sB



zDistribution.insert_oncCs�|jdkrdStj|jd��}t|j�}x~|jd�D]p}|tjks4||ks4|tkrTq4|dkr^q4t	tj|dd�}|r�t|�j
|�s4|j
|j�r�q4td|||jf�q4WdS)	N�
setuptoolsznamespace_packages.txtz
top_level.txt�
pkg_resources�siterdzIModule %s was already imported from %s, but %s is being added to sys.path)r?r>r@)r'rRrSr2r�rrkr�r�r�r9�
issue_warning)rZnspr=�modname�fnrrrr<�
s"

z#Distribution.check_version_conflictcCs4y
|jWn$tk
r.tdt|��dSXdS)NzUnbuilt egg for FT)rKrprAr�)rrrrr7�
s
zDistribution.has_versioncKsDd}x$|j�D]}|j|t||d��qW|jd|j�|jf|�S)z@Copy this distribution, substituting in any changed keyword argsz<project_name version py_version platform location precedenceNr�)rrr�r(r)rrTrMrrrr�clone�
s
zDistribution.clonecCsdd�|jD�S)NcSsg|]}|r|�qSrr)r+Zdeprrrr��
sz'Distribution.extras.<locals>.<listcomp>)r7)rrrrr�
szDistribution.extras)N)NF)N)N)NF)*rrrrr3r>r�r�r'r�r+r�r5rr r"r%r$r#r&r'r,r1rKr7rr2r8r~r�r�r9r�r"rxryrzrr<r7rDrrrrrr�c	sN

	

Cc@seZdZdd�ZdS)�EggInfoDistributioncCst|j|j��}|r||_|S)a�
        Packages installed by distutils (e.g. numpy or scipy),
        which uses an old safe_version, and so
        their version numbers can get mangled when
        converted to filenames (e.g., 1.11.0.dev0+2329eae to
        1.11.0.dev0_2329eae). These distributions will not be
        parsed properly
        downstream by Distribution and safe_version, so
        take an extra step and try to get the version number from
        the metadata file itself instead of the filename.
        )r&r2r3r')rZ
md_versionrrrr+�
sz#EggInfoDistribution._reload_versionN)rrrr+rrrrrE�
srEc@s>eZdZdZdZejd�Zedd��Z	edd��Z
dd	�Zd
S)�DistInfoDistributionzGWrap an actual or potential sys.path entry w/metadata, .dist-info styleZMETADATAz([\(,])\s*(\d.*?)\s*([,\)])cCs@y|jStk
r:|j|j�}tjj�j|�|_|jSXdS)zParse and cache metadataN)Z	_pkg_infor�r�r3�email�parserZParserZparsestr)rr�rrr�_parsed_pkg_info�
sz%DistInfoDistribution._parsed_pkg_infocCs,y|jStk
r&|j�|_|jSXdS)N)�_DistInfoDistribution__dep_mapr��_compute_dependencies)rrrrr7�
s

zDistInfoDistribution._dep_mapcs�dgi}|_g�x&|jjd�p"gD]}�jt|��q$W�fdd�}t|d��}|dj|�x<|jjd�ppgD](}t|j��}tt||��|�||<qrW|S)z+Recompute this distribution's dependencies.Nz
Requires-Distc3s0x*�D]"}|js"|jjd|i�r|VqWdS)Nr()r)r*)r(r�)rrr�reqs_for_extra�
s
zBDistInfoDistribution._compute_dependencies.<locals>.reqs_for_extrazProvides-Extra)	rJrIZget_allrr��	frozensetr�r�r)rr6r�rL�commonr(Zs_extrar)rrrK�
sz*DistInfoDistribution._compute_dependenciesN)rrrrr3r?r@ZEQEQr�rIr7rKrrrrrF�
s

rF)z.eggz	.egg-infoz
.dist-infoc
Os^d}t�}y"xtj|�j|kr(|d7}qWWntk
r@YnXtj|d|di|��dS)Nr-r>)rOrkr�r�rprCrD)rdrTrrXrrrrAsrAc@seZdZdd�ZdS)�RequirementParseErrorcCsdj|j�S)Nr�)rmrd)rrrrr�szRequirementParseError.__str__N)rrrr�rrrrrOsrOccshtt|��}xV|D]N}d|kr0|d|jd��}|jd�rV|dd�j�}|t|�7}t|�VqWdS)z�Yield ``Requirement`` objects for each specification in `strs`

    `strs` must be a string, or a (possibly-nested) iterable thereof.
    z #N�\rg���)r$r�r�r�r�r#r�)rrr�rrrr�#s

csPeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	d
d��Z
�ZS)r�cs�ytt|�j|�Wn2tjjk
rF}ztt|���WYdd}~XnX|j|_	t
|j�}||j�|_|_
dd�|jD�|_ttt|j��|_|j
|jt|j�|jr�t|j�ndf|_t|j�|_dS)z>DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!NcSsg|]}|j|jf�qSr)r8rK)r+r:rrrr�Asz(Requirement.__init__.<locals>.<listcomp>)rr�r�rrZInvalidRequirementrOrFr�Zunsafe_namer�r8rr'�	specifierrrrr�rrMr)�hashCmpr-�_Requirement__hash)rZrequirement_stringrcr)rrrr�7s
zRequirement.__init__cCst|t�o|j|jkS)N)rr�rS)rr!rrrr#Ks
zRequirement.__eq__cCs
||kS)Nr)rr!rrrr&QszRequirement.__ne__cCs0t|t�r |j|jkrdS|j}|jj|dd�S)NFT)Zprereleases)rr�r'rKrR�contains)rrrrrr	Ts

zRequirement.__contains__cCs|jS)N)rT)rrrrr`szRequirement.__hash__cCsdt|�S)NzRequirement.parse(%r))rF)rrrrr�cszRequirement.__repr__cCst|�\}|S)N)r�)r2r�rrrr�es
zRequirement.parse)rrrr�r#r&r	rr�r]r�rHrr)rrr�6scCs0t|t�s*Gdd�d|t�}|jdd�S|jS)z&Get an mro for a type or classic classc@seZdZdS)z_get_mro.<locals>.clsN)rrrrrrrrosrr-N)rr��object�__mro__)rrrr�_get_mroks
rXcCs2x,tt|dt|���D]}||kr||SqWdS)z2Return an adapter factory for `ob` from `registry`rN)rXr�r�)�registryr`�trrrr�vsr�cCs&tjj|�}tjj|�s"tj|�dS)z1Ensure that the parent directory of `path` existsN)r�r�rer
�makedirs)r�rerrrr�}scCs@tstd��t|�\}}|r<|r<t|�r<t|�t|d�dS)z/Sandbox-bypassing version of ensure_directory()z*"os.mkdir" not supported on this platform.i�N)r�r�rr
rKr	)r�rerZrrrrK�srKccszd}g}xbt|�D]V}|jd�r^|jd�rR|s2|r<||fV|dd�j�}g}qhtd|��q|j|�qW||fVdS)asSplit a string or iterable thereof into (section, content) pairs

    Each ``section`` is a stripped version of the section header ("[section]")
    and each ``content`` is a list of stripped lines excluding blank lines and
    comment-only lines.  If there are any such lines before the first section
    header, they're returned in a first ``section`` of ``None``.
    N�[�]r-zInvalid section headingr7)r�r9r�r�rpr;)r2ZsectionZcontentr�rrrr��s


cOs&tj}ztt_tj||�S|t_XdS)N)r�r�os_open�tempfileZmkstemp)rdrTZold_openrrrr��s
r��ignore)�categoryr;cOs|||�|S)Nr)r�rdr�rrr�_call_aside�s
rbcCs<t�}||d<x(t|�D]}|jd�st||�||<qWdS)z=Set up global resource manager (deliberately not state-saved)Z_managerr�N)r�r�r9r�)rXr�r�rrr�_initialize�s

rccCs�tj�}td|d�|j}|j}|j}|j}|}d}x|D]}|jdd�q:W~|dd�dd�g|_t	t
|jtj
��t�jt��dS)	aE
    Prepare the master working set and make the ``require()``
    API available.

    This function has explicit effects on the global state
    of pkg_resources. It is intended to be invoked once at
    the initialization of this module.

    Invocation by other packages is unsupported and done
    at their own risk.
    rV)r�NF)r5cSs|jdd�S)NT)r5)r8)r�rrrre�sz0_initialize_master_working_set.<locals>.<lambda>)r%)r�rrUrtr{r&rur8r�rrr�rkr�rOrPr�)r�rtr{r�rur�r�rrr�_initialize_master_working_set�s

rd)rr)rrr7)N)N)F)F)F)F)N)�rZ
__future__rrkr�rhr�r?r�r�r�rCrQrZpkgutilr8rlrr�Zemail.parserrGr_rCr�rr�r�ZimpZpip._vendorrZpip._vendor.six.movesrrrrr	r
rr�rr^Zos.pathr
rZimportlib.machinery�	machineryr�rrrr��version_inforWrDrtr�rErrVrrKr_rIr/rJrNrQrUrZr[r^rarbrcZ
_sget_noneZ
_sset_noners�__all__�	Exceptionr�r�r�r�r�r�r>r�r�r�r�r�r�rvrnr�rhr@rir�r�r�rur�rwrxryrzr�r�r�rRrr�r��RuntimeErrorr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�ZImpImporterr�r�r�r�r�r�r�rrr�r�r�r�r�rjr
rA�
IGNORECASEr*r�r"r&r�rErFr)rArprOr�rr�rXr�r�rKr�r��filterwarningsrbrOrcrdrrrr�<module>s�




b

 




.

{
3	
a
''





.!


		~	g0
5
	
Back to Directory File Manager
<