Your IP : 18.118.195.30


Current Path : /opt/alt/python34/lib/python3.4/site-packages/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib/python3.4/site-packages/__pycache__/pkg_resources.cpython-34.pyc

�
M�Re_��m@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZyddl
m
Z
mZWn(ek
r�ddlm
Z
mZYnXyeWn"ek
rddlmZYnXy$edd�ZddlmZWn:ek
rleZdd	lmZddd
d�ZYnXddlmZy&dd
lmZmZm Z dZ!Wnek
r�dZ!YnXddlm"Z#ddl$m%Z%m&Z&ej'ddfkoej(j)dkrddl*j+Z,ndZ,yddl-Z-Wnek
rGYnXddd�Z.iZ/dd�Z0dd�Z1dd�Z2dd�Z3dd �Z4d!d"�Z5d#d$�Z6d%d�Z7Z8d&d'�Z9d(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdlgEZ:GdmdC�dCe;�Z<GdndD�dDe<�Z=GdodE�dEe<�Z>GdpdF�dFe<�Z?iZ@ejAdd�ZBdZCdqZDdrZEdZFdrZGdsdh�ZHdtd*�ZIgdudv�ZJdwdx�ZKdydz�ZLejMd{�ZNejMd|�ZOeLZPd}dM�ZQd~d)�ZReRZSdd+�ZTd�d,�ZUdd�d-�ZVd�d.�ZWGd�d[�d[�ZXGd�d\�d\eX�ZYGd�d>�d>eZ�Z[Gd�d=�d=eZ�Z\e\Z]Gd�dG�dGe^�Z_Gd�d?�d?�Z`d�d<�Zad�dJ�Zbd�dK�Zcd�dP�Zdd�dQ�Zeid�gd�6d�gd�6d�d�d�gd�6gd�6gd�6gd�6Zfid�d�d�6d�d�d�6d�d�d�6d�d�d�6d�d�d�6d�d�d�6d�d�d�6Zgd�d��Zhd�d��Zid�d��Zjd�dR�Zkdid�dS�Zld�d��Zmd�en�kr�emZlnGd�db�db�ZoeHeZeo�Gd�dc�dceo�ZpGd�dd�ddep�ZqeHerd�eq�e,dk	r*eHe,jseq�nGd�d`�d`eo�Ztet�Zud�d��ZvGd�de�deep�ZweHejxew�Gd�d]�d]et�ZyGd�d^�d^eq�ZzGd�d_�d_ew�Z{e0d�d�i�d�df�Z|dd�d9�Z}dd�d��Z~e|ejxe~�dd�d��Ze|eZe�dd�d��Z�e|ej�e��e,dk	rae|e,j�e��ne0d�d�i�e0d�d�i�d�dg�Z�d�d��Z�d�d6�Z�dd�di�Z�d�d��Z�e�ej�e��e�ejxe��e,dk	r�e�e,j�e��nd�d��Z�e�eZe��d�dU�Z�id�d��Z�d�d��Z�d�dN�Z�ejMd��j�Z�ejMd��j�Z�ejMd��j�Z�ejMd��j�Z�ejMd��j�Z�ejMd��j�Z�ejMd��j�Z�ejMd��j�Z�ejMd�ej�ej�B�j�Z�ejMd�ej��Z�id�d�6d�d�6d�d�6d�d�6d�d�6j�Z�d�d��Z�d�dI�Z�Gd�dB�dBeZ�Z�d�d��Z�Gd�d@�d@eZ�Z�Gd�d��d�e��Z�ie�d�6e�d�6e�d�6Z�d�d��Z�d�dH�Z�d�d��Z�Gd�dA�dA�Z�id�d�6d�d�6d�d�6d�d�6d�d6dd6Z�dd�Z�dd�Z�ddT�Z�ddO�Z�d	d
�Z�e`�Z�dd�Z�e�en��e0d
d7e[��yddl�m�Z�Wnek
r�Yn�Xye�j�e��Wn�e=k
rje[g�Z�x0e�j�e�e��e\��D]Z�e�j�e��qWx0ej�D]%Z�e�e�j�krLe�j�e��nq'We�j�ej�dd�<YnXe�j�Z�e�j�Z�e�j�Z�e�jRZReRZSe�dd��ge�_�e�e�e�j�ej���dS(aYPackage 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.
�N)�get_importer)�urlparse�
urlunparse)�ImmutableSetcCs
|j�S)N)�next)�o�r�(/tmp/pip-l4uy7dan-build/pkg_resources.py�<lambda>(sr
)�StringIO)�BytesIOcCsY|dkrt�}n|dkr-|}nttt|�j�|d�||�dS)N�exec)�globalsr
�compile�open�read)�fn�globs�locsrrr	�execfile-s
	r)�utime)�mkdir�rename�unlinkTF)r)�isdir�split�Zcpythoni�cCs^tstd��nt|�\}}|rZ|rZt|�rZt|�t||�ndS)Nz*"os.mkdir" not supported on this platform.)�
WRITE_SUPPORT�IOErrorrr�_bypass_ensure_directoryr)�name�mode�dirname�filenamerrr	rKs
rcKs>t�}x.|j�D] \}}|||<|t|<qWdS)N)r�items�_state_vars)�vartype�kw�gr �valrrr	�_declare_stateWs	
r*cCsLi}t�}x6tj�D](\}}|d|||�||<qW|S)N�_sget_)rr%r$)�stater(�k�vrrr	�__getstate__]s
	 r/cCsJt�}x:|j�D],\}}|dt|||||�qW|S)N�_sset_)rr$r%)r,r(r-r.rrr	�__setstate__ds	$r1cCs
|j�S)N)�copy)r)rrr	�
_sget_dictjsr3cCs|j�|j|�dS)N)�clear�update)�key�obr,rrr	�
_sset_dictms
r8cCs
|j�S)N)r/)r)rrr	�_sget_objectqsr9cCs|j|�dS)N)r1)r6r7r,rrr	�_sset_objecttsr:cGsdS)Nr)�argsrrr	r
wscCs�t�}tj|�}|dk	r~tjdkr~y3ddjt�dd��|jd�f}Wq~tk
rzYq~Xn|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-%s�.�r)	�get_build_platform�macosVersionString�match�sys�platform�join�_macosx_vers�group�
ValueError)�plat�mrrr	�get_supported_platformzs
	3
rJ�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�
parse_version�	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@s"eZdZdZdd�ZdS)rfz.Abstract base for dependency resolution errorscCs|jjt|j�S)N)�	__class__�__name__�reprr;)�selfrrr	�__repr__�szResolutionError.__repr__N)r��
__module__�__qualname__�__doc__r�rrrr	rf�sc@seZdZdZdS)rgzAAn already-installed version conflicts with the requested versionN)r�r�r�r�rrrr	rg�sc@seZdZdZdS)rhz&A requested distribution was not foundN)r�r�r�r�rrrr	rh�sc@seZdZdZdS)riz>Distribution doesn't have an "extra feature" of the given nameN)r�r�r�r�rrrr	ri�sr>�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)�loader_type�provider_factoryrrr	r��scCs�t|t�r2tj|�p1tt|��dSytj|}Wn)tk
rnt	|�tj|}YnXt
|dd�}tt|�|�S)z?Return an IResourceProvider for the named module or requirementr�
__loader__N)
�
isinstancerdrZ�findrK�strrB�modules�KeyError�
__import__�getattr�
_find_adapterr�)�moduleOrReq�module�loaderrrr	rM�s#

cCs�|s�ddl}|j�d}|dkr�ddl}d}tjj|�r�t|d�r�|j|�}d|kr�|d}q�q�q�n|j|j	d��n|dS)Nr�z0/System/Library/CoreServices/SystemVersion.plist�	readPlist�ProductVersionr=)
rC�mac_ver�plistlib�os�path�exists�hasattrr��appendr)�_cacherC�versionr��plist�
plist_contentrrr	rE�srEcCsidd6dd6j||�S)N�ppc�PowerPC�Power_Macintosh)�get)�machinerrr	�_macosx_arch�sr�cCs�yddlm}Wn"tk
r8ddlm}YnX|�}tjdkr�|jd�r�yTt�}tj	�dj
dd�}dt|d�t|d	�t|�fSWq�t
k
r�Yq�Xn|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)ror<zmacosx-�� �_zmacosx-%d.%d-%sr�)�	sysconfigro�ImportError�distutils.utilrBrC�
startswithrEr��uname�replace�intr�rG)rorHr�r�rrr	r?�s
		
r?zmacosx-(\d+)\.(\d+)-(.*)zdarwin-(\d+)\.(\d+)\.(\d+)-(.*)cCsO|dks$|dks$||kr(dStj|�}|rKtj|�}|s�tj|�}|r�t|jd��}d|jd�|jd�f}|dkr�|dks�|dkr�|d	kr�dSnd
S|jd�|jd�ks|jd�|jd�krd
St|jd��t|jd��krGd
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.%sr>�z10.3�z10.4Fr)r@rA�darwinVersionStringr�rF)�provided�required�reqMac�provMac�
provDarwin�dversion�macosversionrrr	rps*$"*cCsNtjd�j}|d}|j�||d<t|�dj||�dS)z@Locate distribution `dist_spec` and run its `script_name` scriptr�r�rN)rB�	_getframe�	f_globalsr4rKrL)Z	dist_spec�script_name�nsr rrr	rLHs



cCsdt|t�r!tj|�}nt|t�r?t|�}nt|t�s`td|��n|S)z@Return a current distribution object for a Requirement or stringz-Expected string, Requirement, or Distribution)r��
basestringrd�parserMrc�	TypeError)�distrrr	rNRscCst|�j||�S)zDReturn `name` entry point of `group` for `dist` or raise ImportError)rNrO)r�rFr rrr	rOZscCst|�j|�S)z=Return the entry point map for `group`, or the full entry map)rNrP)r�rFrrr	rP^scCst|�j||�S)z<Return the EntryPoint object for `group`+`name`, or ``None``)rNrQ)r�rFr rrr	rQbsc@sXeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)r~cCsdS)z;Does the package's distribution contain the named metadata?Nr)r rrr	�has_metadataiszIMetadataProvider.has_metadatacCsdS)z'The named metadata resource as a stringNr)r rrr	�get_metadatalszIMetadataProvider.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_linesosz$IMetadataProvider.get_metadata_linescCsdS)z>Is the named metadata a directory?  (like ``os.path.isdir()``)Nr)r rrr	�metadata_isdirusz IMetadataProvider.metadata_isdircCsdS)z?List of metadata names in the directory (like ``os.listdir()``)Nr)r rrr	�metadata_listdirxsz"IMetadataProvider.metadata_listdircCsdS)z=Execute the named script in the supplied namespace dictionaryNr)r��	namespacerrr	rL{szIMetadataProvider.run_scriptN)	r�r�r�r�r�r�r�r�rLrrrr	r~gsc@s^eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)rz3An 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_stream�sz%IResourceProvider.get_resource_streamcCsdS)zmReturn a string containing the contents of `resource_name`

        `manager` must be an ``IResourceManager``Nr)r�r�rrr	�get_resource_string�sz%IResourceProvider.get_resource_stringcCsdS)z,Does the package contain the named resource?Nr)r�rrr	�has_resource�szIResourceProvider.has_resourcecCsdS)z>Is the named resource a directory?  (like ``os.path.isdir()``)Nr)r�rrr	rX�sz IResourceProvider.resource_isdircCsdS)z?List of resource names in the directory (like ``os.listdir()``)Nr)r�rrr	rV�sz"IResourceProvider.resource_listdirN)
r�r�r�r�r�r�r�r�rXrVrrrr	rsc@s�eZdZdZddd�Zdd�Zdd�Zd	d
�Zddd�Zd
d�Z	dd�Z
dddd�Zdddd�Zddddd�Z
dd�Zdd�Zdd�Zdd�Zd d!�ZdS)"razDA collection of active distributions on sys.path (or a similar list)NcCs^g|_i|_i|_g|_|dkr<tj}nx|D]}|j|�qCWdS)z?Create working set from list of path entries (default=sys.path)N)�entries�
entry_keys�by_key�	callbacksrBr��	add_entry)r�r��entryrrr	�__init__�s				
zWorkingSet.__init__cCsT|jj|g�|jj|�x*t|d�D]}|j||d�q3WdS)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\�add)r�r�r�rrr	r��s
zWorkingSet.add_entrycCs|jj|j�|kS)z9True if `dist` is the active distribution for its project)r�r�r6)r�r�rrr	�__contains__�szWorkingSet.__contains__cCsG|jj|j�}|dk	r?||kr?t||��n|SdS)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�r�r6rg)r��reqr�rrr	r��s
zWorkingSet.findccsgx`|D]X}|j|�}|dkrGx4|j�D]}|Vq5Wq||kr||VqqWdS)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)rP�values)r�rFr r�r��eprrr	rR�s
zWorkingSet.iter_entry_pointscCsQtjd�j}|d}|j�||d<|j|�dj||�dS)z?Locate distribution for `requires` and run `script_name` scriptr�r�rN)rBr�r�r4rKrL)r��requiresr�r�r rrr	rL�s



zWorkingSet.run_scriptccspi}xc|jD]X}||jkr+qnx:|j|D]+}||kr9d||<|j|Vq9q9WqWdS)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�itemr6rrr	�__iter__�s
zWorkingSet.__iter__TcCs�|r|j|j|�n|dkr4|j}n|jj|g�}|jj|jg�}|j|jkrwdS||j|j<|j|kr�|j|j�n|j|kr�|j|j�n|j|�dS)a�Add `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.  If it's added, any
        callbacks registered with the ``subscribe()`` method will be called.
        N)	�	insert_onr��locationr�r�r6r�r��
_added_new)r�r�r��insert�keys�keys2rrr	r��szWorkingSet.addc	CsVt|�ddd�}i}i}g}x$|rQ|jd�}||krUq.n|j|j�}|dkr|jj|j�}|dkr�|dkr�t|j�}n|j|||�}||j<|dkr�t|��q�n|j	|�n||krt
||��n|j|j|j
�ddd��d||<q.W|S)aList 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``.
        Nr�rT���r�)�list�popr�r6r�r`r��
best_matchrhr�rg�extendr��extras)	r��requirements�env�	installer�	processed�best�to_activater�r�rrr	�resolves.	 &zWorkingSet.resolvecCsPt|�}|j�i}i}|dkrJt|j�}||7}n
||}|jg�}	tt|	j|��x�|D]�}
x�||
D]�}|j�g}y|	j|||�}
Wn9t	k
r�t
j�d}|||<|r�w�nPYq�Xtt|	j|
��|jt
j|
��Pq�Wq�Wt|�}|j�||fS)abFind all activatable distributions in `plugin_env`

        Example usage::

            distributions, errors = working_set.find_plugins(
                Environment(plugin_dirlist)
            )
            map(working_set.add, distributions)  # add plugins+libs to sys.path
            print 'Could not load', errors        # display 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.
        Nr�)r��sortr`r�r��mapr��as_requirementrrfrB�exc_infor5�dict�fromkeys)r��
plugin_env�full_envr�fallback�plugin_projects�
error_info�
distributionsr�
shadow_set�project_namer�r��	resolveesr.rrr	�find_pluginsAs6"





	
zWorkingSet.find_pluginscGs7|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.
        )rrkr�)r�r�neededr�rrr	rK�s	
zWorkingSet.requirecCsB||jkrdS|jj|�x|D]}||�q*WdS)zAInvoke `callback` for all distributions (including existing ones)N)r�r�)r��callbackr�rrr	�	subscribe�s

zWorkingSet.subscribecCs"x|jD]}||�q
WdS)N)r�)r�r�rrrr	r��szWorkingSet._added_newcCs<|jdd�|jj�|jj�|jdd�fS)N)r�r�r2r�r�)r�rrr	r/�s(zWorkingSet.__getstate__cCsZ|\}}}}|dd�|_|j�|_|j�|_|dd�|_dS)N)r�r2r�r�r�)r��e_k_b_cr�r�r�r�rrr	r1�s
zWorkingSet.__setstate__)r�r�r�r�r�r�r�r�rRrLr�r�rrrKrr�r/r1rrrr	ra�s"
/Mc@s�eZdZdZde�edd�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 pathNcCs5i|_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)�_distmapr�rC�python�scan)r��search_pathrCrrrr	r��s
				zEnvironment.__init__cCsC|jdks0|jdks0|j|jkoBt|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_versionrprC)r�r�rrr	�can_add�szEnvironment.can_addcCs|j|jj|�dS)z"Remove `dist` from the environmentN)rr6�remove)r�r�rrr	r!�szEnvironment.removecCsQ|dkrtj}nx2|D]*}x!t|�D]}|j|�q2WqWdS)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)rBr�r\r�)r�rr�r�rrr	r�s

zEnvironment.scancCs�y|j|SWn1tk
rB|j�}||jkr>gSYnX||jkrw|j|}|j|<t|�n|j|S)zKReturn a newest-to-oldest list of distributions for `project_name`
        )r�r��lowerr�_sort_dists)r�r�distsrrr	�__getitem__�s
	
zEnvironment.__getitem__cCs|j|�r{|j�r{|jj|jg�}||kr{|j|�|j|jkrxt|j|j�qxq{ndS)z<Add `dist` if we ``can_add()`` it and it isn't already addedN)r �has_versionrr�r6r�r�r#)r�r�r$rrr	r�s
zEnvironment.addcCsW|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�r6�obtain)r�r�rZrr�rrr	r�
s
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)r��requirementrrrr	r's	zEnvironment.obtainccs0x)|jj�D]}||r|VqqWdS)z=Yield the unique project names of the available distributionsN)rr�)r�r6rrr	r�+s
zEnvironment.__iter__cCs{t|t�r|j|�nXt|t�rdxF|D](}x||D]}|j|�qFWq5Wntd|f��|S)z2In-place addition of a distribution or environmentzCan't add %r to environment)r�rcr�r`r�)r��other�projectr�rrr	�__iadd__0s
zEnvironment.__iadd__cCs@|jgdddd�}x||fD]}||7}q(W|S)z4Add an environment or distribution to an environmentrCNr)r�)r�r)�newrrrr	�__add__<szEnvironment.__add__)r�r�r�r�rJ�PY_MAJORr�r r!rr%r�r�r'r�r+r-rrrr	r`�s	c@seZdZdZdS)rjaTAn 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)r�r�r�r�rrrr	rjGs
c@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zfdd�Z
edd��Zdd�Zdd�Zddd�ZdS)rbz'Manage resource extraction and packagesNcCs
i|_dS)N)�cached_files)r�rrr	r�[szResourceManager.__init__cCst|�j|�S)zDoes the named resource exist?)rMr�)r��package_or_requirementr�rrr	rW^szResourceManager.resource_existscCst|�j|�S)z,Is the named resource an existing directory?)rMrX)r�r0r�rrr	rXbszResourceManager.resource_isdircCst|�j||�S)z4Return a true filesystem path for specified resource)rMr�)r�r0r�rrr	rUhsz!ResourceManager.resource_filenamecCst|�j||�S)z9Return a readable file-like object for specified resource)rMr�)r�r0r�rrr	rTnszResourceManager.resource_streamcCst|�j||�S)z%Return specified resource as a string)rMr�)r�r0r�rrr	rStszResourceManager.resource_stringcCst|�j|�S)z1List the contents of the named resource directory)rMrV)r�r0r�rrr	rVzsz ResourceManager.resource_listdircCs]tj�d}|jpt�}td||f�}||_||_||_|�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:

  %s

The Python egg cache directory is currently set to:

  %s

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)rBr
�extraction_pathr_rjr��
cache_path�original_error)r��old_excr2�errrrr	�extraction_error�s			z ResourceManager.extraction_errorc	Cso|jpt�}tjj||d|�}yt|�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�)	r1r_r�r�rDrr6�_warn_unsafe_extraction_pathr/)r��archive_name�names�extract_path�target_pathrrr	�get_cache_path�s


zResourceManager.get_cache_pathcCswtjdkr*|jtjd�r*dStj|�j}|tj@sV|tj@rsd|}tj	|t
�ndS)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.
        �nt�windirNz�%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 r��environ�stat�st_mode�S_IWOTH�S_IWGRP�warnings�warn�UserWarning)r�r!�msgrrr	r7�s
&z,ResourceManager._warn_unsafe_extraction_pathcCs@tjdkr<tj|�jdBd@}tj||�ndS)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 r@rA�chmod)r��tempnamer#r!rrr	�postprocess�szResourceManager.postprocesscCs%|jrtd��n||_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/rGr1)r�r�rrr	r]�s	z#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��forcerrr	r^�sz!ResourceManager.cleanup_resources)r�r�r�r�r1r�rWrXrUrTrSrVr6r<�staticmethodr7rKr]r^rrrr	rbWscCsytjdSWntk
r#YnXtjdkrCtjjd�Sd}dd|fd|fd|fdd|fg}x�|D]�\}}d}xn|D]5}|tjkr�tjj|tj|�}q�Pq�W|r�tjj||�}ntjj|d
�Sq�Wtd��dS)aDetermine the default cache location

    This returns the ``PYTHON_EGG_CACHE`` environment variable, if set.
    Otherwise, on Windows, it returns a "Python-Eggs" subdirectory of the
    "Application Data" directory.  On all other systems, it's "~/.python-eggs".
    �PYTHON_EGG_CACHEr=z~/.python-eggszApplication Data�APPDATAN�USERPROFILE�	HOMEDRIVE�HOMEPATH�HOME�WINDIRr�zPython-Eggsz3Please set the PYTHON_EGG_CACHE enviroment variable�zAPPDATA)rUN)zUSERPROFILE)z	HOMEDRIVE�HOMEPATH)rV�zHOME)rWN)zWINDIR)r�r?r�r r��
expanduserrD�RuntimeError)�app_data�	app_homesr��subdirr"r6rrr	r_s0
			
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.]+�-)�re�sub)r rrr	rm0scCs%|jdd�}tjdd|�S)z�Convert an arbitrary string to a standard version string

    Spaces become dots, and all other non-alphanumeric characters become
    dashes, with runs of multiple dashes condensed to a single dash.
    r�r=z[^A-Za-z0-9.]+r])r�r^r_)r�rrr	rn8scCstjdd|�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_r")�extrarrr	rsBscCs|jdd�S)z|Convert a project or version name to its filename-escaped form

    Any '-' characters are currently replaced with '_'.
    r]r�)r�)r rrr	rtKsr r�rCrBr�r��python_implementation�python_version�python_full_versionr`cCstjS)N)r�r rrrr	r
Ys�os_namecCstjS)N)rBrCrrrr	r
Zs�sys_platformcCstjj�dS)Nr)rBr�rrrrr	r
[scCsdtjdtjdfS)Nz%s.%srr�)rB�version_inforrrr	r
\scCs
td�S)Nr�)�	_platinforrrr	r
]s�platform_versioncCs
td�S)Nr�)rgrrrr	r
^s�platform_machinecCstd�pt�S)Nra)rg�_pyimprrrr	r
_sc
CsByddl}Wntk
r(dSYnXt||dd���S)Nrr�cSsdS)Nr�rrrrr	r
gsz_platinfo.<locals>.<lambda>)rCr�r�)�attrrCrrr	rgbs

	rgcCsDtjdkrdStjjd�r)dSdtjkr<dSdSdS)N�cli�
IronPython�java�JythonZ__pypy__�PyPy�CPython)rBrCr��builtin_module_namesrrrr	rjisrjcCsEidd6dd6}d|_d|_|j|j|j�|_|S)z�
    Given a SyntaxError from a marker evaluation, normalize the error message:
     - Remove indications of filename and line number.
     - Replace platform-specific error messages with standard error messages.
    zinvalid syntaxzunexpected EOF while parsingzparenthesis is never closedN)r#�linenor�rG)�exc�subsrrr	�normalize_exceptionss
		rvcCs;yt|�Wn&tk
r6ttj�d�SYnXdS)zHValidate text as a PEP 426 environment marker; return exception or Falser�F)rv�SyntaxErrorrvrBr
)�textrrr	ru�s

csf�sddlm�m�ddl�ddl�ddl���fdd�}��fdd�}��fdd	�}���fd
d�}�ji|�j6|�j6|�j6|�j	6dd
�d6dd
�d6�j
d6�jd6�t�d�r|��j
<qn��fdd����fdd���tj|�jd�d�S)aV
    Evaluate a PEP 426 environment marker on CPython 2.4+.
    Return a boolean indicating the marker result in this environment.
    Raise SyntaxError if marker is invalid.

    This implementation uses the 'parser' module, which is not implemented on
    Jython and has been superseded by the 'ast' module in Python 2.6 and
    later.
    r)�NAME�STRINGNcs;tj�j��fdd�tdt��d�D��S)Ncs g|]}��|��qSrr)�.0�i)�	interpret�nodelistrr	�
<listcomp>�s	z5evaluate_marker.<locals>.and_test.<locals>.<listcomp>r�r>)�	functools�reduce�and_�range�len)r~)r}�operator)r~r	�and_test�sz!evaluate_marker.<locals>.and_testcs;tj�j��fdd�tdt��d�D��S)Ncs g|]}��|��qSrr)r{r|)r}r~rr	r�s	z1evaluate_marker.<locals>.test.<locals>.<listcomp>r�r>)r�r��or_r�r�)r~)r}r�)r~r	�test�szevaluate_marker.<locals>.testcsa|dd}|�jkrQ|dd�jkrCtd��n�|d�Std��dS)Nr�rr>zEmpty parenthesesz5Language feature not supported in environment markers)�LPAR�RPARrw)r~�t)r}�tokenrr	�atom�szevaluate_marker.<locals>.atomc
s�t|�dkr!td��n|dd}|d}|d�kr�t|d�dkr�|dkrtd}q}d	}q�ny�|}Wn(tk
r�tt|�d
��YnX|�|d��|d��S)Nr�z5Chained comparison not allowed in environment markersr>r�rr�notznot inzis notz, operator not allowed in environment markers)r�rwr�r�)r~�comp�cop)ry�_ops�evaluaterr	�
comparison�s
	
z#evaluate_marker.<locals>.comparisoncSs
||kS)Nr)�x�yrrr	r
�sz!evaluate_marker.<locals>.<lambda>znot incSs
||kS)Nr)r�r�rrr	r
�s�inz==z!=�or_testcs{x t|�dkr"|d}qWy�|d}Wn9tk
rptd��td�j|d��YnX||�S)Nr>r�rz)Comparison or logical expression expectedz7Language feature not supported in environment markers: )r�r�rw�sym_name)r~�op)r��symbolrr	r}�s
 z"evaluate_marker.<locals>.interpretcsx t|�dkr"|d}qW|d}|d}|�kr}yt|}Wn"tk
rutd|��YnX|�S|�kr�|d}|dd�dks�|jd�s�|jd�s�d|kr�td	��n|dd�Std
��dS)Nr>r�rzUnknown name %rz'"z"""z'''�\z1Only plain strings allowed in environment markersz5Language feature not supported in environment markersr�)r��_marker_valuesr�rwr�)r~�kindr r��s)ryrzrr	r��s$



4z!evaluate_marker.<locals>.evaluater�)r�ryrzr�r�r5r�r�r�r��eq�ner�r��parser�expr�totuple)rxr`r�r�r�r�r�r)ryrzr�r�r}r�r�r�r	rv�s$	%	cCs�ddl}|j�}x9|j�D]+}|jdd�}|j|�||<q%Wy|j||�}Wn5tk
r�tj�d}t	|j
d��YnX|S)z�
    Evaluate a PEP 426 environment marker using markerlib.
    Return a boolean indicating the marker result in this environment.
    Raise SyntaxError if marker is invalid.
    rNr=r�r�)�
_markerlib�default_environmentr�r�r�r}�	NameErrorrBr
rwr;)rxr�rr6�new_key�result�errr	�_markerlib_evaluate�s
r�r�c@seZdZdZdZdZdZdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Ze
jd)kr�dd�Zndd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�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�r"�module_path)r�r�rrr	r�szNullProvider.__init__cCs|j|j|�S)N)�_fnr�)r�r�r�rrr	r�	sz"NullProvider.get_resource_filenamecCst|j||��S)N)rr�)r�r�r�rrr	r�sz NullProvider.get_resource_streamcCs|j|j|j|��S)N)�_getr�r�)r�r�r�rrr	r�sz NullProvider.get_resource_stringcCs|j|j|j|��S)N)�_hasr�r�)r�r�rrr	r�szNullProvider.has_resourcecCs%|jo$|j|j|j|��S)N)�egg_infor�r�)r�r rrr	r�szNullProvider.has_metadatarcCs)|js
dS|j|j|j|��S)Nr�)r�r�r�)r�r rrr	r�s	zNullProvider.get_metadatacCs2|js
dS|j|j|j|��jd�S)Nr�zutf-8)r�r�r��decode)r�r rrr	r�s	cCst|j|��S)N)rqr�)r�r rrr	r�#szNullProvider.get_metadata_linescCs|j|j|j|��S)N)�_isdirr�r�)r�r�rrr	rX&szNullProvider.resource_isdircCs%|jo$|j|j|j|��S)N)r�r�r�)r�r rrr	r�)szNullProvider.metadata_isdircCs|j|j|j|��S)N)�_listdirr�r�)r�r�rrr	rV,szNullProvider.resource_listdircCs)|jr%|j|j|j|��SgS)N)r�r�r�)r�r rrr	r�/s	zNullProvider.metadata_listdircCs�d|}|j|�s,td|��n|j|�jdd�}|jdd�}|j|j|�}||d<tjj|�r�t	|||�nWddl
m}t|�d|j
d�|f||<t||d	�}t|||�dS)
Nzscripts/zNo script named %rz
�
�
r�r)�cacher
)r�rfr�r�r�r�r�r�r�r�	linecacher�r�rrr
)r�r�r��script�script_text�script_filenamer��script_coderrr	rL4s

%zNullProvider.run_scriptcCstd��dS)Nz9Can't perform this operation for unregistered loader type)�NotImplementedError)r�r�rrr	r�FszNullProvider._hascCstd��dS)Nz9Can't perform this operation for unregistered loader type)r�)r�r�rrr	r�KszNullProvider._isdircCstd��dS)Nz9Can't perform this operation for unregistered loader type)r�)r�r�rrr	r�PszNullProvider._listdircCs&|r"tjj||jd��S|S)N�/)r�r�rDr)r��baser�rrr	r�UszNullProvider._fncCs2t|jd�r"|jj|�Std��dS)N�get_dataz=Can't perform this operation for loaders without 'get_data()')r�r�r�r�)r�r�rrr	r�ZszNullProvider._get)r)r�r�r�r��egg_namer�r�r�r�r�r�r�r�rBrfr�r�rXr�rVr�rLr�r�r�r�r�rrrr	r��s0c@s.eZdZdZdd�Zdd�ZdS)r�z&Provider based on a virtual filesystemcCstj||�|j�dS)N)r�r��
_setup_prefix)r�r�rrr	r�gszEggProvider.__init__cCs�|j}d}x}||kr�|j�jd�rmtjj|�|_tjj|d�|_||_	Pn|}tjj
|�\}}qWdS)Nz.eggzEGG-INFO)r�r"�endswithr�r��basenamer�rDr��egg_rootr)r�r��oldr�rrr	r�ks		zEggProvider._setup_prefixN)r�r�r�r�r�r�rrrr	r�dsc@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
r�z6Provides access to package resources in the filesystemcCstjj|�S)N)r�r�r�)r�r�rrr	r�|szDefaultProvider._hascCstjj|�S)N)r�r�r)r�r�rrr	r�szDefaultProvider._isdircCs
tj|�S)N)r��listdir)r�r�rrr	r��szDefaultProvider._listdircCst|j|j|�d�S)N�rb)rr�r�)r�r�r�rrr	r��sz#DefaultProvider.get_resource_streamc
Cs/t|d�}z|j�SWd|j�XdS)Nr�)rr�close)r�r��streamrrr	r��szDefaultProvider._getN)	r�r�r�r�r�r�r�r�r�rrrr	r�ysc@sPeZdZdZdd�ZZdd�Zdd�ZdZdd�Z	dS)	r�z.Provider that returns nothing for all requestscCsdS)NFr)r�r�rrr	r
�szEmptyProvider.<lambda>cCsdS)Nr�r)r�r�rrr	r
�scCsgS)Nr)r�r�rrr	r
�sNcCsdS)Nr)r�rrr	r��szEmptyProvider.__init__)
r�r�r�r�r�r�r�r�r�r�rrrr	r��sc
Cs�t�}tj|�}zYxR|j�D]D}|jdtj�}|j|�||<||dk	s(t�q(WWd|j	�X|S)af
    This builds a similar dictionary to the zipimport directory
    caches.  However instead of tuples, ZipInfo objects are stored.

    The translation of the tuple is as follows:
      * [0] - zipinfo.filename on stock pythons this needs "/" --> os.sep
              on pypy it is the same (one reason why distribute did work
              in some cases on pypy and win32).
      * [1] - zipinfo.compress_type
      * [2] - zipinfo.compress_size
      * [3] - zipinfo.file_size
      * [4] - len(utf-8 encoding of filename) if zipinfo & 0x800
              len(ascii encoding of filename) otherwise
      * [5] - (zipinfo.date_time[0] - 1980) << 9 |
               zipinfo.date_time[1] << 5 | zipinfo.date_time[2]
      * [6] - (zipinfo.date_time[3] - 1980) << 11 |
               zipinfo.date_time[4] << 5 | (zipinfo.date_time[5] // 2)
      * [7] - zipinfo.CRC
    r�N)
r�zipfile�ZipFile�namelistr�r��sep�getinfo�AssertionErrorr�)r��zipinfo�zfile�zitem�zpathrrr	�build_zipmanifest�s	r�c@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Ze	dd��Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)r�z"Resource support for zips and eggsNcCs?tj||�t|jj�|_|jjtj|_dS)N)	r�r�r�r��archiver�r�r��zip_pre)r�r�rrr	r��szZipProvider.__init__cCsF|j|j�r)|t|j�d�Std||jf��dS)Nz%s is not a subpath of %s)r�r�r�r�)r��fspathrrr	�
_zipinfo_name�szZipProvider._zipinfo_namecCsj|j|}|j|jtj�rM|t|j�dd�jtj�Std||jf��dS)Nr�z%s is not a subpath of %s)r�r�r�r�r�r�rr�)r��zip_pathr�rrr	�_parts�s

'zZipProvider._partscCs�|jstd��n|j|�}|j�}dj|j|��|kr~x*|D]}|j||j|��qXWn|j||�S)Nz5resource_filename() only supported for .egg, not .zipr�)r�r��_resource_to_zip�_get_eager_resourcesrDr��_extract_resource�
_eager_to_zip)r�r�r�r��eagersr rrr	r��s	
 z!ZipProvider.get_resource_filenamecCs/|j}|jd}tj|�}||fS)Nrr�r�)rrr�)�	file_size�	date_time�time�mktime)�zip_stat�sizer��	timestamprrr	�_get_date_and_size�s	
zZipProvider._get_date_and_sizec
Cs�||j�kr^x9|j�|D]'}|j|tjj||��}q#Wtjj|�S|j|j|�\}}ts�t	d��ny)|j
|j|j|��}|j
||�r�|Stddtjj|��\}}	tj||jj|��tj|�t|	||f�|j|	|�yt|	|�Wnmtjk
r�tjj|�r�|j
||�r�|Stjdkr�t|�t|	|�|Sn�YnXWntjk
r�|j�YnX|S)Nz>"os.rename" and "os.unlink" are not supported on this platformz	.$extract�dirr=)�_indexr�r�r�rDr"r�r�rrr<r�r��_is_current�_mkstemp�writer�r�r�rrKr�error�isfiler rr6)
r�r�r�r �lastr�r��	real_path�outf�tmpnamrrr	r��s@$


zZipProvider._extract_resourcec	Cs�|j|j|�\}}tjj|�s2dStj|�}|j|ks_|j|krcdS|jj	|�}t
|d�}|j�}|j�||kS)zK
        Return True if the file_path is current for this zip_path
        Fr�)
r�r�r�r�r�r@�st_size�st_mtimer�r�rrr�)	r��	file_pathr�r�r�r@�zip_contents�f�
file_contentsrrr	r�&s
zZipProvider._is_currentcCsa|jdkrZg}x6dD].}|j|�r|j|j|��qqW||_n|jS)N�native_libs.txt�eager_resources.txt)r�r�)r�r�r�r�)r�r�r rrr	r�7s
z ZipProvider._get_eager_resourcescCs�y|jSWn�tk
r�i}x�|jD]y}|jtj�}x^|r�tjj|dd��}||kr�||j|d�PqF|j�g||<qFWq+W||_|SYnXdS)Nr�r�r�)	�	_dirindex�AttributeErrorr�rr�r�rDr�r�)r��indr��parts�parentrrr	r�@s
		zZipProvider._indexcCs.|j|�}||jkp-||j�kS)N)r�r�r�)r�r�r�rrr	r�QszZipProvider._hascCs|j|�|j�kS)N)r�r�)r�r�rrr	r�UszZipProvider._isdircCs%t|j�j|j|�f��S)N)r�r�r�r�)r�r�rrr	r�XszZipProvider._listdircCs|j|j|j|��S)N)r�r�r�)r�r�rrr	r�[szZipProvider._eager_to_zipcCs|j|j|j|��S)N)r�r�r�)r�r�rrr	r�^szZipProvider._resource_to_zip)r�r�r�r�r�r�r�r�r�rMr�r�r�r�r�r�r�r�r�r�rrrr	r��s 		
1	c@sFeZdZdZdd�Zdd�Zdd�Zdd	�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�)r�r�rrr	r�pszFileMetadata.__init__cCs
|dkS)NzPKG-INFOr)r�r rrr	r�sszFileMetadata.has_metadatacCsH|dkr8t|jd�}|j�}|j�|Std��dS)NzPKG-INFO�rUz(No metadata except PKG-INFO is available)rr�rr�r�)r�r r��metadatarrr	r�vs
zFileMetadata.get_metadatacCst|j|��S)N)rqr�)r�r rrr	r�~szFileMetadata.get_metadata_linesN)r�r�r�r�r�r�r�r�rrrr	r�ds

c@s"eZdZdZdd�ZdS)r�aqMetadata 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)r�r�)r�r�r�rrr	r��s	zPathMetadata.__init__N)r�r�r�r�r�rrrr	r��sc@s"eZdZdZdd�ZdS)r�z Metadata provider for .egg filescCsrt|j�|_|jtj|_||_|jrXtjj	|j|j�|_
n|j|_
|j�dS)z-Create a metadata provider from a zipimporterN)r�r�r�r�r�r�r��prefixr�rDr�r�)r��importerrrr	r��s		!zEggMetadata.__init__N)r�r�r�r�r�rrrr	r��sr�_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_type�distribution_finderrrr	r��scCs+t|�}tt|�}||||�S)z.Yield distributions accessible via `path_item`)rr�r)�	path_item�onlyr�finderrrr	r\�sccs�t|�}|jd�r2tj|d|�Vn|r<dSxf|jd�D]U}|jd�rLtjj||�}x(t	t
j|�|�D]}|Vq�WqLqLWdS)NzPKG-INFOrr�z.egg)r�r�rc�
from_filenamerVr�r�r�rD�find_in_zip�	zipimport�zipimporter)rrrr�subitem�subpathr�rrr	r�srcCsfS)Nr)rrrrrr	�find_nothing�srccst|�}tjj|�rtj|tj�r|j�jd�rwtj	|dt
|tjj|d���Vqx�tj|�D]}}|j�}|jd�s�|jd�rtjj||�}tjj|�r�t
||�}nt
|�}tj|||dt�Vq�|r]|jd�r]x�ttjj||��D]}|VqKWq�|r�|jd�r�ttjj||��}z|j�}	Wd|j�XxU|	D]J}
|
j�s�q�nx.ttjj||
j���D]}|Vq�WPq�Wq�q�WndS)	z6Yield distributions accessible on a sys.path directoryz.eggrzEGG-INFOz	.egg-infoz
.dist-info�
precedencez	.egg-linkN)�_normalize_cachedr�r�r�access�R_OKr"r�rcr
r�rDr�r��
from_locationr}r\r�	readlinesr��strip�rstrip)rrrr�r"�fullpathrr��
entry_file�entry_lines�liner�rrr	�find_on_path�s:'	 "
(	r�_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�namespace_handlerrrr	r��scCs
t|�}|dkrdS|j|�}|dkr;dStjj|�}|dkr�tj|�}tj|<g|_t|�n!t	|d�s�t
d|��ntt|�}|||||�}|dk	r	|j}|j
|�|j|�||_n|S)zEEnsure that named package includes a subpath of path_item (if needed)N�__path__zNot a package:)r�find_modulerBr�r��imp�
new_moduler!�_set_parent_nsr�r�r�rr��load_module)�packageNamerrr�r��handlerrr�rrr	�
_handle_nss*	
	

r)cCstj�z�|tkrdStjd}}d|kr�dj|jd�dd��}t|�|tkr~t|�nytj	|j
}Wq�tk
r�td|��Yq�Xntj
|g�j|�tj
|g�x|D]}t||�q�WWdtj�XdS)z9Declare that package 'packageName' is a namespace packageNr=r�zNot a package:r�)r#�acquire_lockrrBr�rDrrYr�r�r!r�r�r�r�r)�release_lock)r'r�r�rrrr	rY(s&
"



c
Csbtj�zFx?tj|f�D]+}t||�}|r t||�q q WWdtj�XdS)zDEnsure that previously-declared namespace packages include path_itemN)r#r*rr�r)r�r+)rr��packagerrrr	r�Hs
cCs`tjj||jd�d�}t|�}x+|jD]}t|�|kr8Pq8q8W|SdS)zBCompute an ns-package subpath for a filesystem or zipfile importerr=r�Nr�)r�r�rDrrr!)rrr'r�r�
normalizedr�rrr	�file_ns_handlerRs"r.cCsdS)Nr)rrr'r�rrr	�null_ns_handleresr/cCstjjtjj|��S)z1Normalize a file/dir name for comparison purposes)r�r��normcase�realpath)r#rrr	rxkscCs=y||SWn*tk
r8t|�||<}|SYnXdS)N)r�rx)r#r�r�rrr	ros

rcCsU|jd�}|j�}|rQdj|�}ttj||tj|�ndS)Nr=)rr�rD�setattrrBr�)r'r�r r�rrr	r%vs
r%ccs�t|t�rSxn|j�D]0}|j�}|r|jd�r|VqqWn-x*|D]"}xt|�D]}|VqmWqZWdS)zAYield non-empty/non-comment lines of a ``basestring`` or sequence�#N)r�r��
splitlinesrr�rq)�strsr��ssrrr	rq~s
z
\s*(#.*)?$z\s*\\\s*(#.*)?$z\s*((\w|[-.])+)z!\s*(<=?|>=?|==|!=)\s*((\w|[-.])+)z\s*,z\s*\[z\s*\]z\w+(\.\w+)*$zL(?P<name>[^-]+)( -(?P<ver>[^-]+) (-py(?P<pyver>[^-]+) (-(?P<plat>.+))? )? )?z(\d+ | [a-z]+ | \.| -)�c�pre�previewzfinal-r]�rc�@�devccs{xotj|�D]^}t||�}|s|dkr>qn|dd�dkre|jd�Vqd|VqWdVdS)Nr=r��
0123456789r��*z*final)�component_rerr��zfill)r��partrrr	�_parse_version_parts�s
rBcCs�g}x�t|j��D]�}|jd�r�|dkrdx'|r`|ddkr`|j�q=Wnx'|r�|ddkr�|j�qgWn|j|�qWt|�S)a�Convert a version string to a chronologically-sortable key

    This is a rough cross between distutils' StrictVersion and LooseVersion;
    if you give it versions that would work with StrictVersion, then it behaves
    the same; otherwise it acts like a slightly-smarter LooseVersion. It is
    *possible* to create pathological version coding schemes that will fool
    this parser, but they should be very rare in practice.

    The returned value will be a tuple of strings.  Numeric portions of the
    version are padded to 8 digits so they will compare numerically, but
    without relying on how numbers compare relative to strings.  Dots are
    dropped, but dashes are retained.  Trailing zeros between alpha segments
    or dashes are suppressed, so that e.g. "2.4.0" is considered the same as
    "2.4". Alphanumeric parts are lower-cased.

    The algorithm assumes that strings like "-" and any alpha string that
    alphabetically follows "final"  represents a "patch level".  So, "2.4-1"
    is assumed to be a branch or patch of "2.4", and therefore "2.4.1" is
    considered newer than "2.4-1", which in turn is newer than "2.4".

    Strings like "a", "b", "c", "alpha", "beta", "candidate" and so on (that
    come before "final" alphabetically) are assumed to be pre-release versions,
    so that the version "2.4" is considered newer than "2.4a1".

    Finally, to handle miscellaneous cases, the strings "pre", "preview", and
    "rc" are treated as if they were "c", i.e. as though they were release
    candidates, and therefore are not as new as a version string that does not
    contain them, and "dev" is replaced with an '@' so that it sorts lower than
    than any other pre-release tag.
    r>z*finalr�z*final-�00000000r�r�)rBr"r�r�r��tuple)r�r�rArrr	rl�sc@s�eZdZdZffddd�Zdd�Zdd�Zd	ddd
d�Zdddd
�Zddd�Z	e
e	�Z	ddd�Ze
e�Zddd�Ze
e�ZdS)rez3Object representing an advertised importable objectNcCsnt|�std|��n||_||_t|�|_tjddj|��j	|_	||_
dS)NzInvalid module namezx[%s]�,)�MODULErGr �module_namerD�attrsrdr�rDr�r�)r�r rGrHr�r�rrr	r��s		"zEntryPoint.__init__cCsfd|j|jf}|jr<|ddj|j�7}n|jrb|ddj|j�7}n|S)Nz%s = %s�:r=z [%s]rE)r rGrHrDr�)r�r�rrr	�__str__�s		zEntryPoint.__str__cCsdt|�S)NzEntryPoint.parse(%r))r�)r�rrr	r��szEntryPoint.__repr__TcCs�|r|j||�nt|jt�t�dg�}xO|jD]D}yt||�}WqDtk
r�td||f��YqDXqDW|S)Nr�z%r has no %r attribute)rKr�rGrrHr�r�r�)r�rKrrr�rkrrr	�load�s!
zEntryPoint.loadcCs]|jr%|jr%td|��ntttjtj|jj|j�||���dS)Nz&Can't require() without a distribution)	r�r�rir�rrZr�rr�)r�rrrrr	rK�szEntryPoint.requirecCsy�f}}|jdd�\}}d|krz|jdd�\}}tjd|�}|jrnt�n|j}nd|kr�|jdd�\}}t|j��s�t�n|j�jd�}nWn!tk
r�td|��Yn#X||j�|j�|||�SdS)	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
        �=r��[zx[rIr=z9EntryPoint must be in 'name=module:attrs [extras]' formatN)	rrdr��specsrGr�rFrr)�cls�srcr�rHr�r �valuer�rrr	r��s&

			
zEntryPoint.parsecCs�t|�std|��ni}xZt|�D]L}|j||�}|j|krptd||j��n|||j<q1W|S)zParse an entry point groupzInvalid group namezDuplicate entry point)rFrGrqr�r )rOrF�linesr��thisrr�rrr	�parse_groupszEntryPoint.parse_groupcCs�t|t�r|j�}nt|�}i}x~|D]v\}}|dkrj|s[q7ntd��n|j�}||kr�td|��n|j|||�||<q7W|S)z!Parse a map of entry point groupsNz%Entry points must be listed in groupszDuplicate group name)r�rr$rrrGrrT)rO�datar��mapsrFrRrrr	�	parse_map)szEntryPoint.parse_map)
r�r�r�r�r�rJr�rKrKr��classmethodrTrWrrrr	re�s	
cCsE|s
dSt|�}|djd�rAt|dd�d�S|S)Nr�r�zmd5=r�r�)r�)rr�r)r��parsedrrr	�_remove_md5_fragment>srZc	@seZdZdZdZddddededd�Zddd�Ze	e�Ze
dd	��Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Ze
e�Zdd�Ze
e�Zdd�Ze
e�Zdd�Ze
e�Zfd d!�Zd"d#�Zdd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zdd.d/�Ze	e�Zd0d1�Zd2d3�Z dd4d5�Z!d6d7�Z"dd8d9�Z#d:d;�Z$d<d=�Z%d>d?�Z&d@dA�Z'e
e'�Z'dS)Brcz5Wrap an actual or potential sys.path entry w/metadatazPKG-INFONcCsjt|pd�|_|dk	r3t|�|_n||_||_||_||_|p`t|_	dS)N�Unknown)
rmrrn�_versionrrCr�rr��	_provider)r�r�rrr�rrCrrrr	r�Ks				zDistribution.__init__cKs�dgd\}}}}tjj|�\}}	|	j�tkr�t|�}
|
r||
jdddd�\}}}}nt|	j�}n|||d|d|d|d	||�S)
Nr�r �ver�pyverrHrr�rrC)r�r��splitextr"�_distributionImpl�EGG_NAMErF)rOr�r�rr'rr�rrC�extrArrr	rXs!zDistribution.from_locationcCs7t|df�|j|jt|j�|j|jfS)N�parsed_version)r�rr6rZr�rrC)r�rrr	r
jszDistribution.<lambda>cCs
t|j�S)N)�hash�hashcmp)r�rrr	�__hash__sszDistribution.__hash__cCs|j|jkS)N)rf)r�r)rrr	�__lt__tszDistribution.__lt__cCs|j|jkS)N)rf)r�r)rrr	�__le__vszDistribution.__le__cCs|j|jkS)N)rf)r�r)rrr	�__gt__xszDistribution.__gt__cCs|j|jkS)N)rf)r�r)rrr	�__ge__zszDistribution.__ge__cCs&t||j�sdS|j|jkS)NF)r�r�rf)r�r)rrr	�__eq__|szDistribution.__eq__cCs||kS)Nr)r�r)rrr	�__ne__�szDistribution.__ne__cCs>y|jSWn,tk
r9|jj�|_}|SYnXdS)N)�_keyr�rr")r�r6rrr	r6�s

zDistribution.keycCs>y|jSWn,tk
r9t|j�|_}|SYnXdS)N)�_parsed_versionr�rlr�)r��pvrrr	rd�s

zDistribution.parsed_versioncCs�y|jSWn�tk
r�xq|j|j�D]G}|j�jd�r.t|jdd�dj��|_|jSq.Wt	d|j|��YnXdS)Nzversion:rIr�z(Missing 'Version:' header and/or %s file)
r\r��
_get_metadata�PKG_INFOr"r�rnrrrG)r�rrrr	r��s
%zDistribution.versioncCs�y|jSWn�tk
r�igd6}|_x�dD]�}x�t|j|��D]�\}}|r�d|kr�|jdd�\}}t|�r�g}q�t|�s�g}q�nt|�p�d}n|j|g�j	t
|��qRWq6W|SYnXdS)N�requires.txt�depends.txtrIr�)rsrt)�_Distribution__dep_mapr�rrrqrrurvrsr�r�rk)r��dmr r`�reqs�markerrrr	�_dep_map�s 

"	'zDistribution._dep_mapcCs�|j}g}|j|jdf��xT|D]L}y|j|t|��Wq/tk
rztd||f��Yq/Xq/W|S)z@List of Requirements needed for this distro if `extras` are usedNz%s has no such extra feature %r)ryr�r�rsr�ri)r�r�rv�depsrcrrr	r��s	

zDistribution.requiresccs5|j|�r1x|j|�D]}|VqWndS)N)r�r�)r�r rrrr	rq�szDistribution._get_metadatacCsd|dkrtj}n|j|�|tjkr`t|j�ttt|jd���ndS)z>Ensure distribution is importable on `path` (default=sys.path)Nznamespace_packages.txt)	rBr�r�r�r�r�rrYrq)r�r�rrr	�activate�s

zDistribution.activatecCsOdt|j�t|j�|jp'tf}|jrK|d|j7}n|S)z@Return what this distribution's standard .egg filename should bez
%s-%s-py%sr])rtrr�rr.rC)r�r#rrr	r��s	zDistribution.egg_namecCs(|jrd||jfSt|�SdS)Nz%s (%s))r�r�)r�rrr	r��s	zDistribution.__repr__cCsNyt|dd�}Wntk
r0d}YnX|p:d}d|j|fS)Nr�z[unknown version]z%s %s)r�rGr)r�r�rrr	rJ�s
zDistribution.__str__cCs.|jd�rt|��nt|j|�S)zADelegate all unrecognized public attributes to .metadata providerr�)r�r�r�r])r�rkrrr	�__getattr__�szDistribution.__getattr__cKs(|jt|�tjj|�||�S)N)rrr�r�r�)rOr#rr'rrr	r
�szDistribution.from_filenamecCstjd|j|jf�S)z?Return a ``Requirement`` that matches this distribution exactlyz%s==%s)rdr�rr�)r�rrr	r	�szDistribution.as_requirementcCsD|j||�}|dkr:td||ff��n|j�S)z=Return the `name` entry point of `group` or raise ImportErrorNzEntry point %r not found)rQr�rK)r�rFr r�rrr	rO	szDistribution.load_entry_pointcCsdy
|j}Wn4tk
rCtj|jd�|�}|_YnX|dk	r`|j|i�S|S)z=Return the entry point map for `group`, or the full entry mapzentry_points.txtN)�_ep_mapr�rerWrqr�)r�rF�ep_maprrr	rP		s

!zDistribution.get_entry_mapcCs|j|�j|�S)z<Return the EntryPoint object for `group`+`name`, or ``None``)rPr�)r�rFr rrr	rQ	szDistribution.get_entry_infoc	CsN|p|j}|sdSt|�}tjj|�}dd�|D�}x�t|�D]w\}}||krsPqW||krW|jtkrW|tjkr�|j	�n|j
||�|j
||�PqWqWW|tjkr�|j	�n|j|�dSxHy|j||d�}Wnt
k
r1PYqX||=||=|}qWdS)z@Insert self.location in path before its nearest parent directoryNcSs(g|]}|rt|�p!|�qSr)r)r{�prrr	r"	s	z*Distribution.insert_on.<locals>.<listcomp>r�)r�rr�r�r"�	enumeraterryrB�check_version_conflictr�r��indexrG)	r�r��loc�nloc�bdir�npathrr��nprrr	r�	s6




zDistribution.insert_oncCs�|jdkrdStj|jd��}t|j�}x�|jd�D]�}|tjksJ||ksJ|tkr}qJn|dkr�qJnt	tj|dd�}|r�t|�j
|�sJ|j
|j�r�qJntd|||jf�qJWdS)	N�
setuptoolsznamespace_packages.txtz
top_level.txt�
pkg_resources�siter�zIModule %s was already imported from %s, but %s is being added to sys.path)z
pkg_resourcesz
setuptoolszsite)r6rrrqrxr�rBr�rr�r��
issue_warning)r��nspr��modnamerrrr	r�@	s"z#Distribution.check_version_conflictcCs<y|jWn*tk
r7tdt|��dSYnXdS)NzUnbuilt egg for FT)r�rGr�r�)r�rrr	r&U	s
	zDistribution.has_versioncKsMx*d	D]"}|j|t||d��qW|jd|j�|j|�S)
z@Copy this distribution, substituting in any changed keyword argsrr�rrCr�rNr)zproject_namezversionz
py_versionzplatformzlocationz
precedence)r�r�r]r�)r�r'rkrrr	�clone]	s
 zDistribution.clonecCsdd�|jD�S)NcSsg|]}|r|�qSrr)r{�deprrr	ri	s	z'Distribution.extras.<locals>.<listcomp>)ry)r�rrr	r�h	szDistribution.extras)(r�r�r�r�rrr.ryr�rrX�propertyrfrgrhrirjrkrlrmr6rdr�ryr�rqr{r�r�rJr|r
r	rOrPrQr�r�r&r�r�rrrr	rcGsV			'c@sgeZdZdZdZejd�Zedd��Z	edd��Z
dd	�Zd
d�ZdS)
�DistInfoDistributionzGWrap an actual or potential sys.path entry w/metadata, .dist-info style�METADATAz([\(,])\s*(\d.*?)\s*([,\)])cCs\y|jSWnJtk
rWddlm}|�j|j|j��|_|jSYnXdS)zParse and cache metadatar)�ParserN)�	_pkg_infor��email.parserr��parsestrr�rr)r�r�rrr	�_parsed_pkg_infor	s
!z%DistInfoDistribution._parsed_pkg_infocCs:y|jSWn(tk
r5|j�|_|jSYnXdS)N)�_DistInfoDistribution__dep_mapr��_compute_dependencies)r�rrr	ry|	s

zDistInfoDistribution._dep_mapcCsy|jdd�dg}|dj�}|dj�}tj|jd|�}|jdd�jdd�}||fS)z�Convert 'Foobar (1); baz' to ('Foobar ==1', 'baz')
        Split environment marker, add == prefix to version specifiers as
        necessary, and remove parenthesis.
        �;r�r�rz\1==\2\3�(�))rrr^r_�EQEQr�)r��
requires_distr��distvers�markrrr	�_preparse_requirement�	sz*DistInfoDistribution._preparse_requirementc
sddlm}igd6}|_g�xc|jjd�pBgD]I}|j|�\}}tt|��}||�|_�j	|�qCW�fdd�}t
|d��}|dj|�xR|jjd�p�gD]8}	t|	j
��}	tt
||	��|�||	<q�W|S)z+Recompute this distribution's dependencies.r)rNz
Requires-Distc3s6x/�D]'}|jdi|d6�r|VqqWdS)N�overrider`)�	marker_fn)r`r�)rwrr	�reqs_for_extra�	s
zBDistInfoDistribution._compute_dependencies.<locals>.reqs_for_extrazProvides-Extra)r�rr�r��get_allr�rrkr�r��	frozensetr�rsrr�)
r��compile_markerrvr�r�r�rYr��commonr`r)rwr	r��	s$z*DistInfoDistribution._compute_dependenciesN)
r�r�r�r�rrr^rr�r�r�ryr�r�rrrr	r�m	s
r�z.eggz	.egg-infoz
.dist-infoc
Os|d}t�}y-x&tj|�j|kr:|d7}qWWntk
rPYnXddlm}|d|d||�dS)Nr�r)rE�
stacklevel)rrBr�r�rGrDrE)r;r'�levelr(rErrr	r��	s	
r�c#stt|����fdd�}x��D]�}t|�}|sUtd|��n|jd�}|j�}g}t||�}|r�|j�}|tt||dd�\}}}n|tt	||dd�\}}}dd	�|D�}t
|||�Vq+Wd
S)
z�Yield ``Requirement`` objects for each specification in `strs`

    `strs` must be an instance of ``basestring``, or a (possibly-nested)
    iterable thereof.
    csLg}x|||�st||�rayt��}d}Wqatk
r]td��YqaXn|||�}|s�td|d|d||d���n|j|j|��|j�}t||�}|r�|j�}q	|||�s	td|d||d���q	q	W|||�}|r?|j�}n|||fS)Nrz+\ must not appear on the last nonblank linez	Expected z in�atzExpected ',' or end-of-list in)�CONTINUEr�
StopIterationrGr�rF�end�COMMA)�ITEM�
TERMINATORrr�groups�	item_namer$rA)rRrr	�	scan_list�	s0

*#z%parse_requirements.<locals>.scan_listzMissing distribution specr�z'extra' namer>zversion speccSs(g|]\}}|t|�f�qSr)rn)r{r�r)rrr	r�	s	z&parse_requirements.<locals>.<listcomp>N)r�)r�r>)�iterrq�DISTROrGrFr��OBRACKET�CBRACKET�VERSION�LINE_ENDrd)r5r�rrArrr�rNr)rRr	rk�	s"!
$$cCsAdd�|D�}|j�dd�|D�|ddd�<dS)NcSsg|]}|j|f�qSr)rf)r{r�rrr	r
s	z_sort_dists.<locals>.<listcomp>cSsg|]\}}|�qSrr)r{�hc�drrr	r
s	r�r�)r)r$�tmprrr	r#�	s
r#c@speZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
e	�Z	dS)rdcCs�|t|�|_}||j�|_|_dd�|D�}|j�dd�|D�|_|ttt	|��|_
|_|jtdd�|D��t|j�f|_
t|j
�|_dS)z>DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!cSs2g|](\}}t|�t|||f�qSr)rl�
state_machine)r{r�r.rrr	r

s	z(Requirement.__init__.<locals>.<listcomp>cSs(g|]\}}}}||f�qSrr)r{rY�transr�r^rrr	r
s	cSs(g|]\}}}}||f�qSrr)r{rYr�r�r^rrr	r
s	N)rm�unsafe_namer"rr6rrNrDrrsr�r�r��hashCmpre�_Requirement__hash)r�rrNr�r�rrr	r�
s
"zRequirement.__init__cCsXdjdd�|jD��}dj|j�}|rDd|}nd|j||fS)NrEcSsg|]}dj|��qS)r�)rD)r{r�rrr	r
s	z'Requirement.__str__.<locals>.<listcomp>z[%s]z%s%s%s)rDrNr�r)r�rNr�rrr	rJ
s

zRequirement.__str__cCst|t�o|j|jkS)N)r�rdr�)r�r)rrr	rl
szRequirement.__eq__c	Cst|t�r=|j|jkr%dS|jr[|j}q[nt|t�r[t|�}nd}dd�}x�|jD]{\}}}}||||�}|dkr�dS|dkr�dS|dkr�d}qw|dks�|dkrwd}qwqwW|dkrd}n|S)	NFcSs||k||kS)Nr)�a�brrr	r
$
sz*Requirement.__contains__.<locals>.<lambda>�F�TT�+r])r�rcr6r�rdr�rl)	r�r�r��comparerYr�r�r^�actionrrr	r�
s,		
	zRequirement.__contains__cCs|jS)N)r�)r�rrr	rg1
szRequirement.__hash__cCsdt|�S)NzRequirement.parse(%r))r�)r�rrr	r�4
szRequirement.__repr__cCsWtt|��}|rDt|�dkr2|dStd|��ntd|��dS)Nr�rzExpected only one requirementzNo requirements found)r�rkr�rG)r�rwrrr	r�7
szRequirement.parseN)r�r�r�r�rJrlr�rgr�r�rMrrrr	rd
sz--T�<zT-Tz<=zF+F�>zT+Fz>=zT..z==zF++z!=cCs@t|t�s9Gdd�d|t�}|jdd�S|jS)z&Get an mro for a type or classic classc@seZdZdS)z_get_mro.<locals>.clsN)r�r�r�rrrr	rOO
srOr�N)r��type�object�__mro__)rOrrr	�_get_mroL
sr�cCsAx:tt|dt|���D]}||kr||SqWdS)z2Return an adapter factory for `ob` from `registry`r�N)r�r�r�)�registryr7r�rrr	r�S
s%r�cCs8tjj|�}tjj|�s4tj|�ndS)z1Ensure that the parent directory of `path` existsN)r�r�r"r�makedirs)r�r"rrr	rwZ
sccs�d}g}x�t|�D]|}|jd�r�|jd�rv|sI|rW||fVn|dd�j�}g}q�td|��q|j|�qW||fVdS)arSplit 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``.
    NrM�]r�zInvalid section headingr�)rqr�r�rrGr�)r��section�contentrrrr	rr`
s	cOsDddlm}tj}ztt_|||�SWd|t_XdS)Nr)�mkstemp)�tempfiler�r�r�os_open)r;r'r��old_openrrr	r�y
s		r�cCs@x9tt�D]+}|jd�s
tt|�||<q
q
WdS)Nr�)r��_managerr�r�)r(r rrr	�_initialize�
sr�r�)�__requires__cCs
|j�S)N)r{)r�rrr	r
�
s)�r�rBr�r�r^r#r�rrDr@r��pkgutilrrrr��urllib.parser�r�Zsetsrr�r�	cStringIOrrr��iorrrrrrrr��os.pathrrrf�implementationr Zimportlib._bootstrap�
_bootstrap�importlib_bootstrapr�rr%r*r/r1r3r8r9r:�
_sget_none�
_sset_nonerJ�__all__�	Exceptionrfrgrhrir�r�r.ryrzr{r|r}r�rMrEr�r?rr@r�rorprLr�rNrOrPrQr~rr�rar`r�rYrjrbr_rmrnrsrtZ
_marker_namesr�rgrjrvrurvr�rr�r�r�r��SourceFileLoaderr�r�r�r�r
r�r�r�r�r\rrr�ImpImporter�
FileFinderr�r)rYr�r.r/rxrr%rqrAr�r�r�r�r�r�r�rF�VERBOSE�
IGNORECASErbr?r�r�rBrlrerZrcr�rar�rkr#rdr�r�r�rwrrr�r�r��__main__r�rZrKrr�r�r�r�r�r�rRrr[r�rrrrr	�<module>s�




'

									1���)
	






Z	c
	!�

( 

,)n	�'?
><
	


						

?>