/ lib / pkg_resources / __init__.pyc
__init__.pyc
   1  o

   2  6�Hc��@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
   3  Z
   4  ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZzddlZWn
eyddlZYnwzeWne y�e!ZYnwddlm"Z"zddlm#Z#m$Z$m%Z%dZ&Wney�dZ&Ynwddlm'Z(dd	l)m*Z*m+Z+zddl,m-Z.e.j/Wney�dZ.Ynwdd
   5  l0m1Z1m2Z2m3Z3ddl4m5Z5ddl4m6Z6e7d
�e7d�e7d�e7d�e7d�ej8dk�r	e9d��dZ:dZ;dZ<dZ=dZ>dZ?dZ@dZAdZBdZCdZDdZEdZFdZGdZHdZIdZJGdd�deK�ZLdd�ZMiZNdd�ZOdd�ZPdd�ZQdd�ZRd d!�ZSd"d#�ZTd$d%�ZUd&d'�ZVZWd(d)�ZXgd*�ZYGd+d,�d,eZ�Z[Gd-d.�d.e[�Z\Gd/d0�d0e\�Z]Gd1d2�d2e[�Z^Gd3d4�d4e[�Z_iZ`d5jaej8�Zbd6Zcd7Zdd8ZedZfd9Zgd:d;�Zhd<d=�Zigfd>d?�Zjd@dA�ZkdBdC�Zle�mdD�Zne�mdE�ZoelZpdFdG�ZqdHdI�ZrerZsdJdK�ZtdLdM�Zud�dNdO�ZvdPdQ�ZwGdRdS�dS�ZxGdTdU�dUex�ZyGdVdW�dW�ZzGdXdY�dYe{�Z|GdZd[�d[�Z}e}Z~Gd\d]�d]e9�ZGd^d_�d_�Z�d`da�Z�dbdc�Z�ddde�Z�dfdg�Z�dhdi�Z�djdk�Z�d�dldm�Z�Gdndo�do�Z�ehe�e��dpdq�Z�Gdrds�dse��Z�Gdtdu�due��Z�e����Gdvdw�dwe��Z�e��Z�Gdxdy�dye{�Z�Gdzd{�d{e��Z�Gd|d}�d}e��Z�ehej�e��Gd~d�de��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�eOd�id��d�d��Z�d�d�d��Z�d�d�d��Z�e�ej�e��d�d�d��Z�e�e�e��d�d��Z�d�d�d��Z�d�d��Z�Gd�d��d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�e�ej�e��e�e.d���r�e�e.j�e��eOd�id��eOd�id��d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d�d��Z�d�d��Z�e�ej�e��e�ej�e��e�e.d���r)e�e.j�e��d�d��Z�e�e�e��d�d��Z�d�d��Z�ifd�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�e�md��j�Z�e�md�ej�ej�B�j�Z�Gd�d��d��Z�d�d„Z�Gd�dĄdăZ�Gd�dƄd�e��Z�Gd�dȄd�e��Z�e�e�e�dɜZ�d�d˄Z�d�d̈́Z�Gd�dτd�e6j�jƒZ�Gd�dфd�e6j�jăZ�d�dӄZ�d�dՄZ�d�dׄZ�d�dلZ�d�dۄZ�d�d݄Z�e	j�d�eLddߍd�d�Z�e�e̓fd�d��Z�Gd�d�d�eσZ�e�d�d��Z�dS)�aZ
   6  Package resource API
   7  --------------------
   8  
   9  A resource is a logical file contained within a package, or a logical
  10  subdirectory thereof.  The package resource API expects resource names
  11  to have their path parts separated with ``/``, *not* whatever the local
  12  path separator is.  Do not use os.path operations to manipulate resource
  13  names being passed into the API.
  14  
  15  The package resource API is designed to work with normal filesystem packages,
  16  .egg files, and unpacked .egg files.  It can also work in a limited way with
  17  .zip files and with custom PEP 302 loaders that support the ``get_data()``
  18  method.
  19  �N)�get_importer)�utime)�mkdir�rename�unlinkTF)�open)�isdir�split)�yield_lines�drop_comment�join_continuation)�appdirs)�	packagingz&pkg_resources.extern.packaging.versionz)pkg_resources.extern.packaging.specifiersz+pkg_resources.extern.packaging.requirementsz&pkg_resources.extern.packaging.markersz$pkg_resources.extern.packaging.utils)��zPython 3.5 or later is requiredc@�eZdZdZdS)�
PEP440Warningza
  20      Used when there is an issue with a version or specifier not complying with
  21      PEP 440.
  22      N��__name__�
  23  __module__�__qualname__�__doc__�rr��C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\site-packages\pkg_resources\__init__.pyrp�rcCsDztj�|�WStjjy!t�|�d�t�tj�|�YSw)NzD is an invalid version and will not be supported in a future release)r�version�Version�InvalidVersion�warnings�warn�PkgResourcesDeprecationWarning�
LegacyVersion)�vrrr�
parse_versionws��r#cKs"t��|�t�t�||��dS�N)�globals�update�_state_vars�dict�fromkeys)�vartype�kwrrr�_declare_state�sr,cCs8i}t�}t��D]\}}|d|||�||<q	|S)N�_sget_)r%r'�items��state�g�kr"rrr�__getstate__�s
  24  r3cCs8t�}|��D]\}}|dt|||||�q|S)N�_sset_)r%r.r'r/rrr�__setstate__�sr5cC�|��Sr$)�copy��valrrr�
  25  _sget_dict��r:cCs|��|�|�dSr$)�clearr&��key�obr0rrr�
  26  _sset_dict�sr@cCr6r$)r3r8rrr�_sget_object�r;rAcCs|�|�dSr$)r5r=rrr�_sset_object��rBcG�dSr$r��argsrrr�<lambda>��rGcCsdt�}t�|�}|dur0tjdkr0zdd�t�dd��|�d�f}W|Sty/Y|Sw|S)aQReturn this platform's maximum compatible version.
  27  
  28      distutils.util.get_platform() normally reports the minimum version
  29      of macOS that would be required to *use* extensions produced by
  30      distutils.  But what we want when checking compatibility is to know the
  31      version of macOS that we are *running*.  To allow usage of packages that
  32      explicitly require a newer version of macOS, we must also know the
  33      current version of the OS.
  34  
  35      If this condition occurs for any other platform with a version in its
  36      platform strings, this function should be extended accordingly.
  37      N�darwinzmacosx-%s-%s�.�r)	�get_build_platform�macosVersionString�match�sys�platform�join�_macos_vers�group�
  38  ValueError)�plat�mrrr�get_supported_platform�s
  39  $��rW)G�require�
  40  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�
  41  WorkingSet�ResourceManager�Distribution�Requirement�
  42  EntryPoint�ResolutionError�VersionConflict�DistributionNotFound�UnknownExtra�ExtractionErrorr�parse_requirementsr#�	safe_name�safe_version�get_platform�compatible_platformsr
  43  �split_sections�
  44  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_packagesrr �run_main�AvailableDistributionsc@�eZdZdZdd�ZdS)rsz.Abstract base for dependency resolution errorscCs|jjt|j�Sr$)�	__class__r�reprrF��selfrrr�__repr__��zResolutionError.__repr__N)rrrrr�rrrrrs��rsc@s<eZdZdZdZedd��Zedd��Zdd�Zd	d
  45  �Z	dS)rtz�
  46      An already-installed version conflicts with the requested version.
  47  
  48      Should be initialized with the installed Distribution and the requested
  49      Requirement.
  50      z3{self.dist} is installed but {self.req} is requiredcC�
  51  |jdS�NrrEr�rrr�dist	�
  52  zVersionConflict.distcCr��N�rEr�rrr�req
r�zVersionConflict.reqcC�|jjdit���S�Nr��	_template�format�localsr�rrr�report�zVersionConflict.reportcCs|s|S|j|f}t|�S)zt
  53          If required_by is non-empty, return a version of self that is a
  54          ContextualVersionConflict.
  55          )rF�ContextualVersionConflict)r��required_byrFrrr�with_contextszVersionConflict.with_contextN)
  56  rrrrr��propertyr�r�r�r�rrrrrt�s
  57  
  58  rtc@s&eZdZdZejdZedd��ZdS)r�z�
  59      A VersionConflict that accepts a third parameter, the set of the
  60      requirements that required the installed Distribution.
  61      z by {self.required_by}cCr�)NrKrEr�rrrr�'r�z%ContextualVersionConflict.required_byN)rrrrrtr�r�r�rrrrr�s
  62  
  63  r�c@sHeZdZdZdZedd��Zedd��Zedd��Zd	d
  64  �Z	dd�Z
  65  d
S)ruz&A requested distribution was not foundzSThe '{self.req}' distribution was not found and is required by {self.requirers_str}cCr�r�rEr�rrrr�2r�zDistributionNotFound.reqcCr�r�rEr�rrr�	requirers6r�zDistributionNotFound.requirerscCs|jsdSd�|j�S)Nzthe applicationz, )r�rQr�rrr�
requirers_str:sz"DistributionNotFound.requirers_strcCr�r�r�r�rrrr�@r�zDistributionNotFound.reportcCr6r$)r�r�rrr�__str__Cr;zDistributionNotFound.__str__N)rrrrr�r�r�r�r�r�r�rrrrru,s
  66  
  67  
  68  ruc@r)rvz>Distribution doesn't have an "extra feature" of the given nameNrrrrrrvGrrvz{}.{}rrKr������cC�|t|<dS)aRegister `provider_factory` to make providers for `loader_type`
  69  
  70      `loader_type` is the type or class of a PEP 302 ``module.__loader__``,
  71      and `provider_factory` is a function that, passed a *module* object,
  72      returns an ``IResourceProvider`` for that module.
  73      N)�_provider_factories)�loader_type�provider_factoryrrrr�U�r�cCsrt|t�rt�|�ptt|��dSztj|}Wnty+t	|�tj|}Ynwt
  74  |dd�}tt|�|�S)z?Return an IResourceProvider for the named module or requirementr�
  75  __loader__N)
�
  76  isinstancerqrg�findrX�strrO�modules�KeyError�
  77  __import__�getattr�
_find_adapterr�)�moduleOrReq�module�loaderrrrrZ_s
  78  �rZcCsd|s.t��d}|dkr&d}tj�|�r&ttd�r&t�|�}d|vr&|d}|�|�	d��|dS)Nr�z0/System/Library/CoreServices/SystemVersion.plist�	readPlist�ProductVersionrJ)
  79  rP�mac_ver�os�path�exists�hasattr�plistlibr��appendr	)�_cacher�plist�
plist_contentrrrrRls
  80  
  81  rRcCsddd��||�S)N�ppc)�PowerPC�Power_Macintosh)�get)�machinerrr�_macos_arch|r�r�cCs~ddlm}|�}tjdkr=|�d�s=zt�}t��d�dd�}dt	|d�t	|d	�t
  82  |�fWSty<Y|Sw|S)
  83  z�Return this platform's string for platform-specific distributions
  84  
  85      XXX Currently this is the same as ``distutils.util.get_platform()``, but it
  86      needs some hacks for Linux and macOS.
  87      r)r{rIzmacosx-�� �_zmacosx-%d.%d-%sr�)�	sysconfigr{rOrP�
  88  startswithrRr��uname�replace�intr�rT)r{rUrr�rrrrL�s��rLzmacosx-(\d+)\.(\d+)-(.*)zdarwin-(\d+)\.(\d+)\.(\d+)-(.*)cCs�|dus|dus||krdSt�|�}|rrt�|�}|sJt�|�}|rHt|�d��}d|�d�|�d�f}|dkr>|dksF|dkrH|d	krHdSd
  89  S|�d�|�d�ks^|�d�|�d�kr`d
  90  St|�d��t|�d��krpd
  91  SdSd
  92  S)z�Can code for the `provided` platform run on the `required` platform?
  93  
  94      Returns true if either platform is ``None``, or the platforms are equal.
  95  
  96      XXX Needs compatibility checks for Linux and other unixy OSes.
  97      NTr�z%s.%srK�z10.3�z10.4Fr)rMrN�darwinVersionStringr�rS)�provided�required�reqMac�provMac�
  98  provDarwin�dversion�macosversionrrrr|�s*
  99  
 100  
 101  r|cCs<t�d�j}|d}|��||d<t|�d�||�dS)z@Locate distribution `dist_spec` and run its `script_name` scriptr�rrN�rO�	_getframe�	f_globalsr<rXrY)Z	dist_spec�script_name�ns�namerrrrY�s
 102  rYcCs>t|t�r
 103  t�|�}t|t�rt|�}t|t�std|��|S)z@Return a current distribution object for a Requirement or stringz-Expected string, Requirement, or Distribution)r�r�rq�parserZrp�	TypeError�r�rrrr[�s
 104  
 105  
 106  
 107  
 108  r[cC�t|��||�S)zDReturn `name` entry point of `group` for `dist` or raise ImportError)r[r\�r�rSr�rrrr\��r\cCst|��|�S)�=Return the entry point map for `group`, or the full entry map)r[r])r�rSrrrr]��r]cCr��z<Return the EntryPoint object for `group`+`name`, or ``None``)r[r^r�rrrr^�r�r^c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
 109  �Zdd�Zd
S)r�cC�dS)z;Does the package's distribution contain the named metadata?Nr�r�rrr�has_metadata�rHzIMetadataProvider.has_metadatacCr�)z'The named metadata resource as a stringNrr�rrr�get_metadata�rHzIMetadataProvider.get_metadatacCr�)z�Yield named metadata resource as list of non-blank non-comment lines
 110  
 111         Leading and trailing whitespace is stripped from each line, and lines
 112         with ``#`` as the first non-blank character are omitted.Nrr�rrr�get_metadata_lines�rHz$IMetadataProvider.get_metadata_linescCr�)z>Is the named metadata a directory?  (like ``os.path.isdir()``)Nrr�rrr�metadata_isdirrHz IMetadataProvider.metadata_isdircCr�)z?List of metadata names in the directory (like ``os.listdir()``)Nrr�rrr�metadata_listdirrHz"IMetadataProvider.metadata_listdircCr�)z=Execute the named script in the supplied namespace dictionaryNr)r��	namespacerrrrYrHzIMetadataProvider.run_scriptN)	rrrrrrrrrYrrrrr��sr�c@�@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
 113  d�Zdd
�Z	dS)r�z3An object that provides access to package resourcescCr�)zdReturn a true filesystem path for `resource_name`
 114  
 115          `manager` must be an ``IResourceManager``Nr��manager�
resource_namerrr�get_resource_filename
rHz'IResourceProvider.get_resource_filenamecCr�)ziReturn a readable file-like object for `resource_name`
 116  
 117          `manager` must be an ``IResourceManager``Nrrrrr�get_resource_streamrHz%IResourceProvider.get_resource_streamcCr�)zmReturn a string containing the contents of `resource_name`
 118  
 119          `manager` must be an ``IResourceManager``Nrrrrr�get_resource_stringrHz%IResourceProvider.get_resource_stringcCr�)z,Does the package contain the named resource?Nr�r	rrr�has_resourcerHzIResourceProvider.has_resourcecCr�)z>Is the named resource a directory?  (like ``os.path.isdir()``)Nrr
rrrrerHz IResourceProvider.resource_isdircCr�)z?List of resource names in the directory (like ``os.listdir()``)Nrr
rrrrc"rHz"IResourceProvider.resource_listdirN)
 120  rrrrr
 121  rrrrercrrrrr�
 122  sr�c@s�eZdZdZd'dd�Zedd��Zedd��Zd	d
 123  �Zdd�Z	d
d�Z
 124  d'dd�Zdd�Zdd�Z
d(dd�Z		d)dd�Z	d*dd�Zdd�Zd+dd �Zd!d"�Zd#d$�Zd%d&�ZdS),rnzDA collection of active distributions on sys.path (or a similar list)NcCsDg|_i|_i|_i|_g|_|durtj}|D]}|�|�qdS)z?Create working set from list of path entries (default=sys.path)N)�entries�
 125  entry_keys�by_key�normalized_to_canonical_keys�	callbacksrOr��	add_entry)r�r�entryrrr�__init__)s�zWorkingSet.__init__cCs\|�}zddlm}Wnty|YSwz|�|�W|Sty-|�|�YSw)z1
 126          Prepare the master working set.
 127          r)�__requires__)�__main__r�ImportErrorrXrt�_build_from_requirements)�cls�wsrrrr�
_build_master7s���zWorkingSet._build_mastercCsf|g�}t|�}|�|t��}|D]}|�|�qtjD]}||jvr(|�|�q|jtjdd�<|S)zQ
 128          Build a working set from a requirement spec. Rewrites sys.path.
 129          N)rx�resolverm�addrOr�rr)r�req_specr�reqs�distsr�rrrrrKs
 130  
 131  
 132  �z#WorkingSet._build_from_requirementscCs<|j�|g�|j�|�t|d�D]	}|�||d�qdS)a�Add a path item to ``.entries``, finding any distributions on it
 133  
 134          ``find_distributions(entry, True)`` is used to find distributions
 135          corresponding to the path entry, and they are added.  `entry` is
 136          always appended to ``.entries``, even if it is already present.
 137          (This is because ``sys.path`` can contain the same value more than
 138          once, and the ``.entries`` of the ``sys.path`` WorkingSet should always
 139          equal ``sys.path``.)
 140          TFN)r�
 141  setdefaultrr�rir)r�rr�rrrras
 142  
 143  �zWorkingSet.add_entrycCs|j�|j�|kS)z9True if `dist` is the active distribution for its project)rr�r>�r�r�rrr�__contains__pszWorkingSet.__contains__cCs\|j�|j�}|dur|j�|j�}|dur||_|j�|�}|dur,||vr,t||��|S)a�Find a distribution matching requirement `req`
 144  
 145          If there is an active distribution for the requested project, this
 146          returns it as long as it meets the version requirement specified by
 147          `req`.  But, if there is an active distribution for the project and it
 148          does *not* meet the `req` requirement, ``VersionConflict`` is raised.
 149          If there is no active distribution for the requested project, ``None``
 150          is returned.
 151          N)rr�r>rrt)r�r�r��
canonical_keyrrrr�ts
 152  
 153  zWorkingSet.findcs��fdd�|D�S)aYield entry point objects from `group` matching `name`
 154  
 155          If `name` is None, yields all entry points in `group` from all
 156          distributions in the working set, otherwise only ones matching
 157          both `group` and `name` are yielded (in distribution order).
 158          c3s:�|]}|�����D]}�dus�|jkr|VqqdSr$)r]�valuesr�)�.0r�r�rSr�rr�	<genexpr>�s����z/WorkingSet.iter_entry_points.<locals>.<genexpr>r�r�rSr�rr)rr_�s�zWorkingSet.iter_entry_pointscCs>t�d�j}|d}|��||d<|�|�d�||�dS)z?Locate distribution for `requires` and run `script_name` scriptr�rrNr�)r��requiresr�r�r�rrrrY�s
 159  zWorkingSet.run_scriptccsN�i}|jD]}||jvrq|j|D]}||vr#d||<|j|VqqdS)z�Yield distributions for non-duplicate projects in the working set
 160  
 161          The yield order is the order in which the items' path entries were
 162          added to the working set.
 163          r�N)rrr)r��seen�itemr>rrr�__iter__�s�
 164  
 165  ���zWorkingSet.__iter__TFcCs�|r|j|j||d�|dur|j}|j�|g�}|j�|jg�}|s+|j|jvr+dS||j|j<tj�	|j�}|j|j
 166  |<|j|vrI|�|j�|j|vrT|�|j�|�|�dS)aAdd `dist` to working set, associated with `entry`
 167  
 168          If `entry` is unspecified, it defaults to the ``.location`` of `dist`.
 169          On exit from this routine, `entry` is added to the end of the working
 170          set's ``.entries`` (if it wasn't already present).
 171  
 172          `dist` is only added to the working set if it's for a project that
 173          doesn't already have a distribution in the set, unless `replace=True`.
 174          If it's added, any callbacks registered with the ``subscribe()`` method
 175          will be called.
 176          �r�N)
�	insert_onr�locationrr#r>rr�utils�canonicalize_namerr��
 177  _added_new)r�r�r�insertr��keys�keys2�normalized_namerrrr�s 
 178  
 179  zWorkingSet.addcCsrt|�ddd�}i}i}g}t�}	t�t�}
 180  |r�|�d�}||vr#q|	�||�s*q|�|j�}|dur|j	�|j�}|dusE||vrz|rz|}
|dur]|durUt
 181  |j�}nt
 182  g�}tg�}
|j
||
||d�}||j<|durz|
 183  �|d�}t||��|�|�||vr�|
 184  |}t||��|��|�|j�ddd�}|�|�|D]}|
 185  |�|j�|j|	|<q�d||<|s|S)a�List all distributions needed to (recursively) meet `requirements`
 186  
 187          `requirements` must be a sequence of ``Requirement`` objects.  `env`,
 188          if supplied, should be an ``Environment`` instance.  If
 189          not supplied, it defaults to all distributions available within any
 190          entry or distribution in the working set.  `installer`, if supplied,
 191          will be invoked with each requirement that cannot be met by an
 192          already-installed distribution; it should return a ``Distribution`` or
 193          ``None``.
 194  
 195          Unless `replace_conflicting=True`, raises a VersionConflict exception
 196          if
 197          any requirements are found on the path that have the correct name but
 198          the wrong version.  Otherwise, if an `installer` is supplied it will be
 199          invoked to obtain the correct version of the requirement and activate
 200          it.
 201  
 202          `extras` is a list of the extras to be used with these requirements.
 203          This is important because extra requirements may look like `my_req;
 204          extra = "my_extra"`, which would otherwise be interpreted as a purely
 205          optional requirement.  Instead, we want to be able to assert that these
 206          requirements are truly required.
 207          Nr�r)�replace_conflictingT)�list�
 208  _ReqExtras�collections�defaultdict�set�pop�markers_passr�r>rrmrrn�
 209  best_matchrur�rtr�r,�extras�extendr�project_name)r��requirements�env�	installerr:rC�	processed�best�to_activate�
 210  req_extrasr�r�r�rr��
dependent_req�new_requirements�new_requirementrrrr�sR
 211  
 212  �
 213  
 214  
 215  �2zWorkingSet.resolvecCst|�}|��i}i}|durt|j�}||7}n||}|�g�}	tt|	j|��|D]G}
 216  ||
 217  D]@}|��g}z	|	�|||�}
Wnt	yb}z|||<|rWWYd}~q3WYd}~nd}~wwtt|	j|
��|�
 218  t�|
��q-t|�}|��||fS)asFind all activatable distributions in `plugin_env`
 219  
 220          Example usage::
 221  
 222              distributions, errors = working_set.find_plugins(
 223                  Environment(plugin_dirlist)
 224              )
 225              # add plugins+libs to sys.path
 226              map(working_set.add, distributions)
 227              # display errors
 228              print('Could not load', errors)
 229  
 230          The `plugin_env` should be an ``Environment`` instance that contains
 231          only distributions that are in the project's "plugin directory" or
 232          directories. The `full_env`, if supplied, should be an ``Environment``
 233          contains all currently-available distributions.  If `full_env` is not
 234          supplied, one is created automatically from the ``WorkingSet`` this
 235          method is called on, which will typically mean that every directory on
 236          ``sys.path`` will be scanned for distributions.
 237  
 238          `installer` is a standard installer callback as used by the
 239          ``resolve()`` method. The `fallback` flag indicates whether we should
 240          attempt to resolve older versions of a plugin if the newest version
 241          cannot be resolved.
 242  
 243          This method returns a 2-tuple: (`distributions`, `error_info`), where
 244          `distributions` is a list of the distributions found in `plugin_env`
 245          that were loadable, along with any other distributions that are needed
 246          to resolve their dependencies.  `error_info` is a dictionary mapping
 247          unloadable plugin distributions to an exception instance describing the
 248          error that occurred. Usually this will be a ``DistributionNotFound`` or
 249          ``VersionConflict`` instance.
 250          N)
r;�sortrmrr��mapr�as_requirementrrsr&r(r))r��
 251  plugin_env�full_envrH�fallback�plugin_projects�
 252  error_info�
distributionsrG�
 253  shadow_setrEr�r��	resolveesr"rrr�find_plugins0s:$
 254  
 255  
 256  
 257  ���zWorkingSet.find_pluginscGs&|�t|��}|D]}|�|�q	|S)a�Ensure that distributions matching `requirements` are activated
 258  
 259          `requirements` must be a string or a (possibly-nested) sequence
 260          thereof, specifying the distributions and versions required.  The
 261          return value is a sequence of the distributions that needed to be
 262          activated to fulfill the requirements; all relevant distributions are
 263          included, even if they were already activated in this working set.
 264          )rrxr)r�rF�neededr�rrrrX�s	zWorkingSet.requirecCs8||jvrdS|j�|�|sdS|D]}||�qdS)z�Invoke `callback` for all distributions
 265  
 266          If `existing=True` (default),
 267          call on all existing ones, as well.
 268          N)rr�)r��callback�existingr�rrr�	subscribe�s
 269  
 270  �zWorkingSet.subscribecCs|jD]}||�qdSr$)r)r�r�r]rrrr5�s
 271  
 272  �zWorkingSet._added_newcCs4|jdd�|j��|j��|j��|jdd�fSr$)rrr7rrrr�rrrr3�s�zWorkingSet.__getstate__cCsL|\}}}}}|dd�|_|��|_|��|_|��|_|dd�|_dSr$)rr7rrrr)r��	e_k_b_n_crr7rrrrrrr5�s
 273  
 274  
 275  zWorkingSet.__setstate__r$)NTF)NNFN)NNT�T)rrrrr�classmethodrrrr%r�r_rYr/rrr[rXr_r5r3r5rrrrrn&s0
 276  
 277  
 278  
 279  
 280  !
 281  �]
 282  �T
 283  rnc@seZdZdZddd�ZdS)r<z>
 284      Map each requirement to the extras that demanded it.
 285      Ncs2�fdd�|��d�|p
dD�}�jpt|�S)z�
 286          Evaluate markers for req against each extra that
 287          demanded it.
 288  
 289          Return False if the req has a marker and fails
 290          evaluation. Otherwise, return True.
 291          c3s �|]}�j�d|i�VqdS)�extraN��marker�evaluate)r(rc�r�rrr*�s
 292  ��
 293  �z*_ReqExtras.markers_pass.<locals>.<genexpr>rr$)r�re�any)r�r�rC�extra_evalsrrgrrA�s
 294  �z_ReqExtras.markers_passr$)rrrrrArrrrr<�sr<c@szeZdZdZde�efdd�Zdd�Zdd�Zdd	d
 295  �Z	dd�Z
 296  d
d�Z	ddd�Zddd�Z
dd�Zdd�Zdd�ZdS)rmz5Searchable snapshot of distributions on a search pathNcCs i|_||_||_|�|�dS)a!Snapshot distributions available on a search path
 297  
 298          Any distributions found on `search_path` are added to the environment.
 299          `search_path` should be a sequence of ``sys.path`` items.  If not
 300          supplied, ``sys.path`` is used.
 301  
 302          `platform` is an optional string specifying the name of the platform
 303          that platform-specific distributions must be compatible with.  If
 304          unspecified, it defaults to the current platform.  `python` is an
 305          optional string naming the desired version of Python (e.g. ``'3.6'``);
 306          it defaults to the current version.
 307  
 308          You may explicitly set `platform` (and/or `python`) to ``None`` if you
 309          wish to map *all* distributions, not just those compatible with the
 310          running platform or Python version.
 311          N)�_distmaprP�python�scan)r��search_pathrPrkrrrr�szEnvironment.__init__cCs2|jdup|jdup|j|jk}|ot|j|j�S)z�Is distribution `dist` acceptable for this environment?
 312  
 313          The distribution must match the platform and python version
 314          requirements specified when this environment was created, or False
 315          is returned.
 316          N)rk�
 317  py_versionr|rP)r�r��	py_compatrrr�can_add�s
 318  �
 319  �zEnvironment.can_addcCs|j|j�|�dS)z"Remove `dist` from the environmentN)rjr>�remover$rrrrq�szEnvironment.removecCs4|durtj}|D]}t|�D]}|�|�qq	dS)adScan `search_path` for distributions usable in this environment
 320  
 321          Any distributions found are added to the environment.
 322          `search_path` should be a sequence of ``sys.path`` items.  If not
 323          supplied, ``sys.path`` is used.  Only distributions conforming to
 324          the platform/python version defined at initialization are added.
 325          N)rOr�rir)r�rmr.r�rrrrl�s��zEnvironment.scancCs|��}|j�|g�S)aReturn a newest-to-oldest list of distributions for `project_name`
 326  
 327          Uses case-insensitive `project_name` comparison, assuming all the
 328          project's distributions use their project's name converted to all
 329          lowercase as their key.
 330  
 331          )�lowerrjr�)r�rE�distribution_keyrrr�__getitem__szEnvironment.__getitem__cCsX|�|�r&|��r(|j�|jg�}||vr*|�|�|jt�d�dd�dSdSdSdS)zLAdd `dist` if we ``can_add()`` it and it has not already been added
 332          �hashcmpT�r>�reverseN)	rp�has_versionrjr#r>r�rP�operator�
 333  attrgetter)r�r�r"rrrrs
 334  �zEnvironment.addFcCsdz|�|�}Wnty|s�d}Ynw|dur|S||jD]
 335  }||vr+|Sq!|�||�S)a�Find distribution best matching `req` and usable on `working_set`
 336  
 337          This calls the ``find(req)`` method of the `working_set` to see if a
 338          suitable distribution is already active.  (This may raise
 339          ``VersionConflict`` if an unsuitable version of the project is already
 340          active in the specified `working_set`.)  If a suitable distribution
 341          isn't active, this method returns the newest distribution in the
 342          environment that meets the ``Requirement`` in `req`.  If no suitable
 343          distribution is found, and `installer` is supplied, then the result of
 344          calling the environment's ``obtain(req, installer)`` method will be
 345          returned.
 346          N)r�rtr>�obtain)r�r�rgrHr:r�rrrrBs��zEnvironment.best_matchcCs|dur||�SdS)a�Obtain a distribution matching `requirement` (e.g. via download)
 347  
 348          Obtain a distro that matches requirement (e.g. via download).  In the
 349          base ``Environment`` class, this routine just returns
 350          ``installer(requirement)``, unless `installer` is None, in which case
 351          None is returned instead.  This method is a hook that allows subclasses
 352          to attempt other ways of obtaining a distribution before falling back
 353          to the `installer` argument.Nr)r��requirementrHrrrr{5s	�zEnvironment.obtainccs$�|j��D]	}||r|VqdS)z=Yield the unique project names of the available distributionsN)rjr7�r�r>rrrr/As���zEnvironment.__iter__cCsVt|t�r|�|�|St|t�r$|D]}||D]}|�|�qq|Std|f��)z2In-place addition of a distribution or environmentzCan't add %r to environment)r�rprrmr�)r��other�projectr�rrr�__iadd__Gs
 354  
 355  
 356  ���zEnvironment.__iadd__cCs*|jgddd�}||fD]}||7}q|S)z4Add an environment or distribution to an environmentN)rPrk�r�)r�r~�newrGrrr�__add__Ss
 357  zEnvironment.__add__r$�NF)rrrrrW�PY_MAJORrrprqrlrtrrBr{r/r�r�rrrrrm�s 
 358  �
 359  
 360  
 361 362  rmc@r)rwaTAn error occurred extracting a resource
 363  
 364      The following attributes are available from instances of this exception:
 365  
 366      manager
 367          The resource manager that raised this exception
 368  
 369      cache_path
 370          The base directory for resource extraction
 371  
 372      original_error
 373          The exception instance that caused extraction to fail
 374      Nrrrrrrw_rrwc@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
 375  �Zdd�Z	d
d�Z
 376  dd�Zdd�Zddd�Z
edd��Zdd�Zdd�Zd dd�ZdS)!roz'Manage resource extraction and packagesNcCs
 377  i|_dSr$)�cached_filesr�rrrrs�
 378  zResourceManager.__init__cC�t|��|�S)zDoes the named resource exist?)rZr�r��package_or_requirementr	rrrrdvr�zResourceManager.resource_existscCr�)z,Is the named resource an existing directory?)rZrer�rrrrez��zResourceManager.resource_isdircC�t|��||�S)z4Return a true filesystem path for specified resource)rZr
 379  r�rrrrb���z!ResourceManager.resource_filenamecCr�)z9Return a readable file-like object for specified resource)rZrr�rrrra�r�zResourceManager.resource_streamcCr�)z%Return specified resource as a string)rZrr�rrrr`�r�zResourceManager.resource_stringcCr�)z1List the contents of the named resource directory)rZrcr�rrrrc�r�z ResourceManager.resource_listdircCsRt��d}|jpt�}t�d���}t|jdit	����}||_
 380  ||_||_|�)z5Give an error message for problems extracting file(s)r�a
 381              Can't extract file(s) to egg cache
 382  
 383              The following error occurred while trying to extract file(s)
 384              to the Python egg cache:
 385  
 386                {old_exc}
 387  
 388              The Python egg cache directory is currently set to:
 389  
 390                {cache_path}
 391  
 392              Perhaps your account does not have write access to this directory?
 393              You can change the cache directory by setting the PYTHON_EGG_CACHE
 394              environment variable to point to an accessible directory.
 395              Nr)
rO�exc_info�extraction_pathrl�textwrap�dedent�lstriprwr�r�r�
 396  cache_path�original_error)r��old_excr��tmpl�errrrr�extraction_error�s�z ResourceManager.extraction_errorrcCsf|jpt�}tjj||dg|�R�}zt|�Wn
ty&|��Ynw|�|�d|j	|<|S)a�Return absolute location in cache for `archive_name` and `names`
 397  
 398          The parent directory of the resulting path will be created if it does
 399          not already exist.  `archive_name` should be the base filename of the
 400          enclosing egg (which may not be the name of the enclosing zipfile!),
 401          including its ".egg" extension.  `names`, if provided, should be a
 402          sequence of path name parts "under" the egg's extraction location.
 403  
 404          This method should only be called by resource providers that need to
 405          obtain an extraction location, and only for names they intend to
 406          extract, as it tracks the generated names for possible cleanup later.
 407          z-tmpr�)
 408  r�rlr�r�rQ�_bypass_ensure_directory�	Exceptionr��_warn_unsafe_extraction_pathr�)r��archive_name�names�extract_path�target_pathrrr�get_cache_path�s
�
 409  
 410  zResourceManager.get_cache_pathcCsdtjdkr|�tjd�sdSt�|�j}|tj@s|tj@r0djdit	���}t
 411  �|t�dSdS)aN
 412          If the default extraction path is overridden and set to an insecure
 413          location, such as /tmp, it opens up an opportunity for an attacker to
 414          replace an extracted file with an unauthorized payload. Warn the user
 415          if a known insecure location is used.
 416  
 417          See Distribute #375 for more details.
 418          �nt�windirNz�Extraction path is writable by group/others and vulnerable to attack when used with get_resource_filename ({path}). Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).r)
r�r�r��environ�stat�st_mode�S_IWOTH�S_IWGRPr�r�rr�UserWarning)r��mode�msgrrrr��s
 419  ���z,ResourceManager._warn_unsafe_extraction_pathcCs2tjdkrt�|�jdBd@}t�||�dSdS)a4Perform any platform-specific postprocessing of `tempname`
 420  
 421          This is where Mac header rewrites should be done; other platforms don't
 422          have anything special they should do.
 423  
 424          Resource providers should call this method ONLY after successfully
 425          extracting a compressed resource.  They must NOT call it on resources
 426          that are already in the filesystem.
 427  
 428          `tempname` is the current (temporary) name of the file, and `filename`
 429          is the name it will be renamed to by the caller after this routine
 430          returns.
 431          �posiximi�N)r�r�r�r��chmod)r��tempname�filenamer�rrr�postprocess�s
 432  �zResourceManager.postprocesscCs|jrtd��||_dS)a�Set the base path where resources will be extracted to, if needed.
 433  
 434          If you do not call this routine before any extractions take place, the
 435          path defaults to the return value of ``get_default_cache()``.  (Which
 436          is based on the ``PYTHON_EGG_CACHE`` environment variable, with various
 437          platform-specific fallbacks.  See that routine's documentation for more
 438          details.)
 439  
 440          Resources are extracted to subdirectories of this path based upon
 441          information given by the ``IResourceProvider``.  You may set this to a
 442          temporary directory, but then you must call ``cleanup_resources()`` to
 443          delete the extracted files when done.  There is no guarantee that
 444          ``cleanup_resources()`` will be able to remove all extracted files.
 445  
 446          (Note: you may not change the extraction path for a given resource
 447          manager once resources have been extracted, unless you first call
 448          ``cleanup_resources()``.)
 449          z5Can't change extraction path, files already extractedN)r�rTr��r�r�rrrrj�s
 450  �
 451  z#ResourceManager.set_extraction_pathFcCr�)aB
 452          Delete all extracted resource files and directories, returning a list
 453          of the file and directory names that could not be successfully removed.
 454          This function does not have any concurrency protection, so it should
 455          generally only be called when the extraction path is a temporary
 456          directory exclusive to a single process.  This method is not
 457          automatically called; you must call it explicitly or register it as an
 458          ``atexit`` function if you wish to ensure cleanup of a temporary
 459          directory used for extractions.
 460          Nr)r��forcerrrrkrHz!ResourceManager.cleanup_resources�r�F)rrrrr�rrdrerbrar`rcr�r��staticmethodr�r�rjrkrrrrroos"
 461  
 462  rocCstj�d�ptjdd�S)z�
 463      Return the ``PYTHON_EGG_CACHE`` environment variable
 464      or a platform-relevant user cache dir for an app
 465      named "Python-Eggs".
 466      �PYTHON_EGG_CACHEzPython-Eggs)�appname)r�r�r�r
�user_cache_dirrrrrrl$s
 467  �rlcCst�dd|�S)z�Convert an arbitrary string to a standard distribution name
 468  
 469      Any runs of non-alphanumeric/. characters are replaced with a single '-'.
 470      �[^A-Za-z0-9.]+�-)�re�subr�rrrry0srycCsDz	ttj�|��WStjjy!|�dd�}t�dd|�YSw)zB
 471      Convert an arbitrary string to a standard version string
 472      r�rJr�r�)r�rrrrr�r�r�)rrrrrz8s�rzcCst�dd|���S)z�Convert an arbitrary string to a standard 'extra' name
 473  
 474      Any runs of non-alphanumeric characters are replaced with a single '_',
 475      and the result is always lowercased.
 476      z[^A-Za-z0-9.-]+r�)r�r�rr)rcrrrr~Dsr~cCs|�dd�S)z|Convert a project or version name to its filename-escaped form
 477  
 478      Any '-' characters are currently replaced with '_'.
 479      r�r�r0r�rrrrMsrc
 480  CsDzt|�WdSty!}zd|_d|_|WYd}~Sd}~ww)zo
 481      Validate text as a PEP 508 environment marker; return an exception
 482      if invalid or False otherwise.
 483      NF)r��SyntaxErrorr��lineno)�text�errrr�Us
 484  ���r�c
 485  Cs>ztj�|�}|��WStjjy}zt|�|�d}~ww)z�
 486      Evaluate a PEP 508 environment marker.
 487      Return a boolean indicating the marker result in this environment.
 488      Raise SyntaxError if marker is invalid.
 489  
 490      This implementation uses the 'pyparsing' module.
 491      N)r�markers�Markerrf�
InvalidMarkerr�)r�rcrer�rrrr�cs
 492  
 493  ��r�c@s�eZdZdZdZdZdZdd�Zdd�Zdd�Z	d	d
 494  �Z
 495  dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zed'd(��Zd)d*�ZdS)+r�zETry to implement resources and metadata for arbitrary PEP 302 loadersNcCs(t|dd�|_tj�t|dd��|_dS)Nr��__file__r�)r�r�r�r��dirname�module_path�r�r�rrrryszNullProvider.__init__cCs|�|j|�Sr$)�_fnr��r�rr	rrrr
 496  }rCz"NullProvider.get_resource_filenamecCst�|�||��Sr$)�io�BytesIOrr�rrrr�r�z NullProvider.get_resource_streamcCs|�|�|j|��Sr$)�_getr�r�r�rrrr�r�z NullProvider.get_resource_stringcC�|�|�|j|��Sr$)�_hasr�r��r�r	rrrr�r�zNullProvider.has_resourcecCs|�|j|�Sr$)r��egg_info�r�r�rrr�_get_metadata_path�rCzNullProvider._get_metadata_pathcCs |js|jS|�|�}|�|�Sr$)r�r�r��r�r�r�rrrr�s
 497  
 498  zNullProvider.has_metadatac
 499  Cs\|jsdS|�|�}|�|�}z|�d�WSty-}z|jd�||�7_�d}~ww)Nr��utf-8z in {} file at path: {})r�r�r��decode�UnicodeDecodeError�reasonr�)r�r�r��value�excrrrr�s
 500  
 501  ��zNullProvider.get_metadatacC�t|�|��Sr$�r
 502  rr�rrrr�rCzNullProvider.get_metadata_linescCr�r$)�_isdirr�r�r�rrrre�r�zNullProvider.resource_isdircCs|jo|�|�|j|��Sr$)r�r�r�r�rrrr��zNullProvider.metadata_isdircCr�r$)�_listdirr�r�r�rrrrc�r�zNullProvider.resource_listdircCs|jr
|�|�|j|��SgSr$)r�r�r�r�rrrr�szNullProvider.metadata_listdircCs�d|}|�|�stdjd
 503  it�����|�|��dd�}|�dd�}|�|j|�}||d<tj	�
 504  |�rZt|��}|��}Wd�n1sGwYt
||d�}t|||�dSdd	lm}	t|�d|�d�|f|	|<t
||d�}
 505  t|
 506  ||�dS)Nzscripts/z<Script {script!r} not found in metadata at {self.egg_info!r}z
 507  �
 508  �
r��execr)�cacher)rrsr�r�rr�r�r�r�r�r�r�read�compiler��	linecacher��lenr	)r�r�r�script�script_text�script_filename�fid�source�coder��script_coderrrrY�s0
 509  ���
 510  
 511  ��zNullProvider.run_scriptcC�td���Nz9Can't perform this operation for unregistered loader type��NotImplementedErrorr�rrrr����zNullProvider._hascCr�r�r�r�rrrr��r�zNullProvider._isdircCr�r�r�r�rrrr��r�zNullProvider._listdircCs,|�|�|rtjj|g|�d��R�S|S)N�/)�_validate_resource_pathr�r�rQr	)r��baser	rrrr��s
 512  zNullProvider._fncCsptjj|�tj�vpt�|�pt�|�}|sdSd}t�|�r(t�|�s(t|��t	j
 513  |dd�dtdd�dS)aH
 514          Validate the resource paths according to the docs.
 515          https://setuptools.pypa.io/en/latest/pkg_resources.html#basic-resource-access
 516  
 517          >>> warned = getfixture('recwarn')
 518          >>> warnings.simplefilter('always')
 519          >>> vrp = NullProvider._validate_resource_path
 520          >>> vrp('foo/bar.txt')
 521          >>> bool(warned)
 522          False
 523          >>> vrp('../foo/bar.txt')
 524          >>> bool(warned)
 525          True
 526          >>> warned.clear()
 527          >>> vrp('/foo/bar.txt')
 528          >>> bool(warned)
 529          True
 530          >>> vrp('foo/../../bar.txt')
 531          >>> bool(warned)
 532          True
 533          >>> warned.clear()
 534          >>> vrp('foo/f../bar.txt')
 535          >>> bool(warned)
 536          False
 537  
 538          Windows path separators are straight-up disallowed.
 539          >>> vrp(r'\foo/bar.txt')
 540          Traceback (most recent call last):
 541          ...
 542          ValueError: Use of .. or absolute path in a resource path is not allowed.
 543  
 544          >>> vrp(r'C:\foo/bar.txt')
 545          Traceback (most recent call last):
 546          ...
 547          ValueError: Use of .. or absolute path in a resource path is not allowed.
 548  
 549          Blank values are allowed
 550  
 551          >>> vrp('')
 552          >>> bool(warned)
 553          False
 554  
 555          Non-string values are not.
 556  
 557          >>> vrp(None)
 558          Traceback (most recent call last):
 559          ...
 560          AttributeError: ...
 561          Nz=Use of .. or absolute path in a resource path is not allowed.r�z/ and will raise exceptions in a future release.r���
 562  stacklevel)r�r��pardirr	�	posixpath�sep�isabs�ntpathrTrr�DeprecationWarning)r��invalidr�rrrr��s6��
 563  �z$NullProvider._validate_resource_pathcCs t|jd�r|j�|�Std��)N�get_dataz=Can't perform this operation for loaders without 'get_data()')r�r�r�r�r�rrrr�)s
 564  �zNullProvider._get)rrrr�egg_namer�r�rr
 565  rrrr�rrrrerrcrrYr�r�r�r�r�r�r�rrrrr�rs4

 566  Jr�ccs8�d}||kr|V|}tj�|�\}}||ksdSdS)z2
 567      yield all parents of path including path
 568      N)r�r�r	)r��lastr�rrr�_parents4s��rcs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)r�z&Provider based on a virtual filesystemcst��|�|��dSr$)�superr�
_setup_prefixr�r�rrrBszEggProvider.__init__cCs2ttt|j��}t|d�}|o|�|�dSdSr$)�filter�_is_egg_pathrr��next�_set_egg)r��eggs�eggrrrrFs
 569  zEggProvider._setup_prefixcCs(tj�|�|_tj�|d�|_||_dS)N�EGG-INFO)r�r��basenamer�rQr��egg_rootr�rrrrMs
 570  zEggProvider._set_egg)rrrrrrr�
__classcell__rrr�rr�?s
 571  r�c@sDeZdZdZdd�Zdd�Zdd�Zdd	�Zd
 572  d�Ze	dd
��Z
 573  dS)r�z6Provides access to package resources in the filesystemcC�tj�|�Sr$)r�r�r�r�rrrr�V�zDefaultProvider._hascCrr$)r�r�rr�rrrr�YrzDefaultProvider._isdircCs
 574  t�|�Sr$)r��listdirr�rrrr�\r�zDefaultProvider._listdircCst|�|j|�d�S�N�rb)rr�r�r�rrrr_r�z#DefaultProvider.get_resource_streamcCs6t|d��}|��Wd�S1swYdSr)rr�)r�r��streamrrrr�bs$�zDefaultProvider._getcCs,d}|D]}tt|td��}t||�qdS)N)�SourceFileLoader�SourcelessFileLoader)r��importlib_machinery�typer�)r�loader_namesr��
 575  loader_clsrrr�	_registerfs
 576  �zDefaultProvider._registerN)rrrrr�r�r�rr�rbrrrrrr�Ssr�c@s8eZdZdZdZdd�ZZdd�Zdd�Zd	d
 577  �Z	dS)r�z.Provider that returns nothing for all requestsNcCr�r�rr�rrrrGvrHzEmptyProvider.<lambda>cCr��Nr�rr�rrrr�x�zEmptyProvider._getcCsgSr$rr�rrrr�{rzEmptyProvider._listdircCrDr$rr�rrrr~rzEmptyProvider.__init__)
 578  rrrrr�r�r�r�r�rrrrrr�qsr�c@s eZdZdZedd��ZeZdS)�ZipManifestsz
 579      zip manifest builder
 580      csLt�|����fdd����D�}t|�Wd�S1swYdS)a
 581          Build a dictionary similar to the zipimport directory
 582          caches, except instead of tuples, store ZipInfo objects.
 583  
 584          Use a platform-specific path separator (os.sep) for the path keys
 585          for compatibility with pypy on Windows.
 586          c3s(�|]}|�dtj���|�fVqdS)r�N)r�r�r��getinfo�r(r���zfilerrr*�s���
 587  �z%ZipManifests.build.<locals>.<genexpr>N)�zipfile�ZipFile�namelistr()rr�r.rr r�build�s	
 588  �$�zZipManifests.buildN)rrrrrbr%�loadrrrrr�s
 589  
 590  rc@s$eZdZdZe�dd�Zdd�ZdS)�MemoizedZipManifestsz%
 591      Memoized zipfile manifests.
 592      �manifest_modzmanifest mtimecCsRtj�|�}t�|�j}||vs||j|kr$|�|�}|�||�||<||jS)zW
 593          Load a manifest at path or return a suitable manifest already loaded.
 594          )	r�r��normpathr��st_mtime�mtimer%r(�manifest)r�r�r+r,rrrr&�s
 595  
 596  zMemoizedZipManifests.loadN)rrrrr=�
 597  namedtupler(r&rrrrr'�sr'cs�eZdZdZdZe�Z�fdd�Zdd�Zdd�Z	e
 598  d	d
 599  ��Zdd�Ze
d
d��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Z�ZS)!r�z"Resource support for zips and eggsNcs t��|�|jjtj|_dSr$)rrr��archiver�r��zip_prer�r�rrr�szZipProvider.__init__cCsL|�tj�}||jjkrdS|�|j�r|t|j�d�Std||jf��)Nr��%s is not a subpath of %s)	�rstripr�r�r�r.r�r/r��AssertionError�r��fspathrrr�
_zipinfo_name�s�zZipProvider._zipinfo_namecCsL|j|}|�|jtj�r|t|j�dd��tj�Std||jf��)Nr�r0)r/r�rr�r�r�r	r2)r��zip_pathr4rrr�_parts�s
 600  �zZipProvider._partscCs|j�|jj�Sr$)�_zip_manifestsr&r�r.r�rrr�zipinfo�r�zZipProvider.zipinfocCs\|jstd��|�|�}|��}d�|�|��|vr(|D]}|�||�|��q|�||�S)Nz5resource_filename() only supported for .egg, not .zipr�)r�r��_resource_to_zip�_get_eager_resourcesrQr7�_extract_resource�
_eager_to_zip)r�rr	r6�eagersr�rrrr
 601  �s�
 602  z!ZipProvider.get_resource_filenamecCs"|j}|jd}t�|�}||fS)N)rrr�)�	file_size�	date_time�time�mktime)�zip_stat�sizer@�	timestamprrr�_get_date_and_size�s
 603  
 604  zZipProvider._get_date_and_sizec
 605  Csd||��vr |��|D]
}|�|tj�||��}qtj�|�S|�|j|�\}}ts0t	d��zr|�
 606  |j|�|��}|�
||�rD|WStdtj�|�d�\}}	t�||j�|��t�|�t|	||f�|�|	|�z	t|	|�WW|Stjy�tj�|�r�|�
||�r�|YWStjdkr�t|�t|	|�|YWS�wtjy�|��Y|Sw)Nz>"os.rename" and "os.unlink" are not supported on this platformz	.$extract)�dirr�)�_indexr<r�r�rQr�rFr9�
WRITE_SUPPORT�IOErrorr�r�r7�_is_current�_mkstemp�writer�r��closerr�r�error�isfiler�rr�)
 607  r�rr6r�rrErD�	real_path�outf�tmpnamrrrr<�sP��
 608  
 609  �
 610  �
 611  
 612  
 613  
 614  �
 615  �zZipProvider._extract_resourcec	Cs�|�|j|�\}}tj�|�sdSt�|�}|j|ks!|j|kr#dS|j�	|�}t
 616  |d��}|��}Wd�||kS1s@wY||kS)zK
 617          Return True if the file_path is current for this zip_path
 618          FrN)rFr9r�r�rPr��st_sizer*r�r�rr�)	r��	file_pathr6rErDr��zip_contents�f�
file_contentsrrrrK&s
 619  
 620  
 621  ��zZipProvider._is_currentcCs>|jdurg}dD]}|�|�r|�|�|��q	||_|jS)N)znative_libs.txtzeager_resources.txt)r>rrDr)r�r>r�rrrr;6s
 622  
 623  �z ZipProvider._get_eager_resourcesc	Cs�z|jWStyCi}|jD]+}|�tj�}|r;tj�|dd��}||vr2||�|d�n	|��g||<|sq||_|YSw)Nr�)	�	_dirindex�AttributeErrorr9r	r�r�rQr�r@)r��indr��parts�parentrrrrH?s"
 624  ���zZipProvider._indexcCs |�|�}||jvp||��vSr$)r5r9rH)r�r4r6rrrr�Ps
 625  zZipProvider._hascCs|�|�|��vSr$)r5rHr3rrrr�Tr�zZipProvider._isdircCst|���|�|�d��Sr�)r;rHr�r5r3rrrr�Wr�zZipProvider._listdircCr�r$)r5r�rr�rrrr=Zr�zZipProvider._eager_to_zipcCr�r$)r5r�r�r�rrrr:]r�zZipProvider._resource_to_zip)rrrrr>r'r8rr5r7r�r9r
 626  r�rFr<rKr;rHr�r�r�r=r:r
rrr�rr��s*
 627  
 628  
 629  	7	r�c@r)r�a*Metadata handler for standalone PKG-INFO files
 630  
 631      Usage::
 632  
 633          metadata = FileMetadata("/path/to/PKG-INFO")
 634  
 635      This provider rejects all data and metadata requests except for PKG-INFO,
 636      which is treated as existing, and will be the contents of the file at
 637      the provided location.
 638      cCs
 639  ||_dSr$�r�r�rrrrpr�zFileMetadata.__init__cC�|jSr$r^r�rrrr�s�zFileMetadata._get_metadata_pathcCs|dko
 640  tj�|j�S)N�PKG-INFO)r�r�rPr�rrrrvszFileMetadata.has_metadatacCsX|dkrtd��tj|jddd��}|��}Wd�n1s wY|�|�|S)Nraz(No metadata except PKG-INFO is availabler�r�)�encoding�errors)r�r�rr�r��_warn_on_replacement)r�r�rW�metadatarrrrys
 641  �
 642  zFileMetadata.get_metadatacCs4d}||vrd}|jdit���}t�|�dSdS)Nu�z2{self.path} could not be properly decoded in UTF-8r)r�r�rr)r�re�replacement_charr�r�rrrrd�s�z!FileMetadata._warn_on_replacementcCr�r$r�r�rrrr�rCzFileMetadata.get_metadata_linesN)
 643  rrrrrr�rrrdrrrrrr�ds	r�c@r�)r�asMetadata provider for egg directories
 644  
 645      Usage::
 646  
 647          # Development eggs:
 648  
 649          egg_info = "/path/to/PackageName.egg-info"
 650          base_dir = os.path.dirname(egg_info)
 651          metadata = PathMetadata(base_dir, egg_info)
 652          dist_name = os.path.splitext(os.path.basename(egg_info))[0]
 653          dist = Distribution(basedir, project_name=dist_name, metadata=metadata)
 654  
 655          # Unpacked egg directories:
 656  
 657          egg_path = "/path/to/PackageName-ver-pyver-etc.egg"
 658          metadata = PathMetadata(egg_path, os.path.join(egg_path,'EGG-INFO'))
 659          dist = Distribution.from_filename(egg_path, metadata=metadata)
 660      cCs||_||_dSr$)r�r�)r�r�r�rrrr�s
 661  zPathMetadata.__init__N�rrrrrrrrrr��sr�c@r�)r�z Metadata provider for .egg filescCsD|jtj|_||_|jrtj�|j|j�|_n|j|_|�	�dS)z-Create a metadata provider from a zipimporterN)
 662  r.r�r�r/r��prefixr�rQr�r)r��importerrrrr�szEggMetadata.__init__Nrgrrrrr��r�r�r(��_distribution_finderscCr�)axRegister `distribution_finder` to find distributions in sys.path items
 663  
 664      `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
 665      handler), and `distribution_finder` is a callable that, passed a path
 666      item and the importer instance, yields ``Distribution`` instances found on
 667      that path item.  See ``pkg_resources.find_on_path`` for an example.Nrj)�
importer_type�distribution_finderrrrr��r�r�cCst|�}tt|�}||||�S)z.Yield distributions accessible via `path_item`)rr�rk)�	path_item�onlyri�finderrrrri�s
 668  ric	cs��|j�d�r	dSt|�}|�d�rtj||d�V|rdS|�d�D]>}t|�rAtj	�
 669  ||�}tt�
|�|�}|D]}|Vq:q#|���d�ratj	�
 670  ||�}tt�
|��}||_t�|||�Vq#dS)z@
 671      Find eggs in zip files; possibly multiple nested eggs.
 672      z.whlNra�rer�)�
 673  .dist-info�	.egg-info)r.�endswithr�rrp�
from_filenamercrr�r�rQ�find_eggs_in_zip�	zipimport�zipimporterrrr��
from_location)	rirnrore�subitem�subpathr"r��submetarrrrv�s,�
 674  ���rvcCr�r�r)rirnrorrr�find_nothing�rr}cs"dd���fdd�}t||dd�S)aL
 675      Given a list of filenames, return them in descending order
 676      by version number.
 677  
 678      >>> names = 'bar', 'foo', 'Python-2.7.10.egg', 'Python-2.7.2.egg'
 679      >>> _by_version_descending(names)
 680      ['Python-2.7.10.egg', 'Python-2.7.2.egg', 'bar', 'foo']
 681      >>> names = 'Setuptools-1.2.3b1.egg', 'Setuptools-1.2.3.egg'
 682      >>> _by_version_descending(names)
 683      ['Setuptools-1.2.3.egg', 'Setuptools-1.2.3b1.egg']
 684      >>> names = 'Setuptools-1.2.3b1.egg', 'Setuptools-1.2.3.post1.egg'
 685      >>> _by_version_descending(names)
 686      ['Setuptools-1.2.3.post1.egg', 'Setuptools-1.2.3b1.egg']
 687      cSs.ztj�|�WStytj�d�YSw)zI
 688          Attempt to parse as a version or return a null version.
 689          �0)rrrr�r�rrr�	try_parse�s
 690  �z)_by_version_descending.<locals>.try_parsecs6tj�|�\}}t�|�d�|g�}�fdd�|D�S)z6
 691          Parse each component of the filename
 692          r�csg|]}�|��qSrr)r(�part�rrr�
 693  <listcomp>�z?_by_version_descending.<locals>._by_version.<locals>.<listcomp>)r�r��splitext�	itertools�chainr	)r��extr\r�rr�_by_versionsz+_by_version_descending.<locals>._by_versionTrv)�sorted)r�r�rr�r�_by_version_descending�s	r�c
 694  #s��t���t��rtj�t�tj��d��d�VdS�fdd�t��D�}��fdd�|D�}t	|�}|D]}tj��|�}t
 695  �|��}||�D]}	|	VqIq6dS)z6Yield distributions accessible on a sys.path directoryr
 696  rqNc3s�|]
 697  }tj��|�VqdSr$)r�r�rQ)r(�child)rnrrr*s
 698  ��
 699  �zfind_on_path.<locals>.<genexpr>c3s �|]}t�|��r|VqdSr$)�dist_factory)r(r�rornrrr*%s�
 700  �
 701  �)�_normalize_cached�_is_unpacked_eggrprur�r�r�rQ�safe_listdirr�r�)
 702  rirnror�filtered�path_item_entriesr�fullpath�factoryr�rr�r�find_on_paths.���
 703  ����r�cCsj|��}|�d�}|�d�otj�tj�||��}|p|}|r!tS|s)t|�r)tS|s2|�d�r2t	St
 704  �S)z*Return a dist_factory for the given entry.rsrrz	.egg-link)rrrtr�r�rrQ�distributions_from_metadatarri�resolve_egg_link�NoDists)rnrrorr�is_egg_info�is_dist_info�is_metarrrr�4s*
 705  
 706  ����������r�c@s eZdZdZdd�Zdd�ZdS)r�zS
 707      >>> bool(NoDists())
 708      False
 709  
 710      >>> list(NoDists()('anything'))
 711      []
 712      cCr�r�rr�rrr�__bool__PrzNoDists.__bool__cCstd�Sr�)�iter)r�r�rrr�__call__Sr;zNoDists.__call__N)rrrrr�r�rrrrr�Hsr�c
 713  Csbzt�|�WSttfyYdSty0}z|jtjtjtjfvr%�WYd}~dSd}~ww)zI
 714      Attempt to list contents of path, but suppress some exceptions.
 715      Nr)	r�r�PermissionError�NotADirectoryError�OSError�errno�ENOTDIR�EACCES�ENOENT)r�r�rrrr�Ws�
 716  ���r�ccsh�tj�|�}tj�|�rtt�|��dkrdSt||�}nt|�}tj�|�}t	j
 717  |||td�VdS)Nr)�
 718  precedence)r�r�r�rr�rr�r�rrpryr�)r��rootrerrrrr�gs��r�ccsL�t|��}|D]}|��}|r|VqWd�dS1swYdS)z1
 719      Yield non-empty lines from file at path
 720      N)r�strip)r�rW�linerrr�non_empty_linesvs�
 721  ��"�r�cs.t��}�fdd�|D�}tt|�}t|d�S)za
 722      Given a path to an .egg-link, resolve distributions
 723      present in the referenced path.
 724      c3s&�|]}tj�tj���|�VqdSr$)r�r�rQr�)r(�refr^rrr*�s
 725  ��
 726  �z#resolve_egg_link.<locals>.<genexpr>r)r�rQrir)r��referenced_paths�resolved_paths�dist_groupsrr^rr��s
 727  �
 728  
 729  r��
 730  FileFinder��_namespace_handlers)�_namespace_packagescCr�)a�Register `namespace_handler` to declare namespace packages
 731  
 732      `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
 733      handler), and `namespace_handler` is a callable like this::
 734  
 735          def namespace_handler(importer, path_entry, moduleName, module):
 736              # return a path_entry to use for child packages
 737  
 738      Namespace handlers are only called if the importer object has already
 739      agreed that it can handle the relevant path item, and they should only
 740      return a subpath if the module __path__ does not already contain an
 741      equivalent subpath.  For an example namespace handler, see
 742      ``pkg_resources.file_ns_handler``.
 743      Nr�)rl�namespace_handlerrrrr��sr�c	Cs"t|�}|dur
 744  dSz|�|�}Wn'ty8t���t�d�|�|�}Wd�n1s1wYYnw|r>|jnd}|durFdStj	�
 745  |�}|durbt�|�}tj	|<g|_
t|�n
 746  t|d�sltd|��tt|�}|||||�}|dur�|j
}|�|�t�|�t|||�|S)zEEnsure that named package includes a subpath of path_item (if needed)N�ignore�__path__�Not a package:)r�	find_specrZr�catch_warnings�simplefilter�find_moduler�rOr�r��types�
 747  ModuleTyper��_set_parent_nsr�r�r�r�r��	importlib�
import_module�_rebuild_mod_path)	�packageNamernri�specr�r��handlerr{r�rrr�
 748  _handle_ns�s<
 749  
 750  ���
 751  
 752  
 753  
 754  
 755  
 756  r�csldd�tjD���fdd����fdd�}t||d�}dd�|D�}t|jt�r1||jd	d	�<d	S||_d	S)
 757  zq
 758      Rebuild module.__path__ ensuring that all entries are ordered
 759      corresponding to their sys.path order
 760      cS�g|]}t|��qSr�r��r(�prrrr��r�z%_rebuild_mod_path.<locals>.<listcomp>cs(z��|�WStytd�YSw)z/
 761          Workaround for #520 and #513.
 762          �inf)�indexrT�float)r)�sys_pathrr�safe_sys_path_index�s
 763  �z._rebuild_mod_path.<locals>.safe_sys_path_indexcs<|�tj�}��d�d}|d|�}�ttj�|���S)zR
 764          Return the ordinal of the path based on its position in sys.path
 765          rJr�N)r	r�r��countr�rQ)r��
 766  path_parts�module_partsr\)�package_namer�rr�position_in_sys_path�sz/_rebuild_mod_path.<locals>.position_in_sys_path)r>cSr�rr�r�rrrr��r�N)rOr�r�r�r�r;)�	orig_pathr�r�r��new_pathr)r�r�r�rr��s		
 767  r�c
 768  Cs�t��za|tvrWt��dStj}|�d�\}}}|rDt|�|tvr)t|�ztj	|j
 769  }WntyC}ztd|�|�d}~wwt�
|pIdg��|�t�
|g�|D]}t||�qWWt��dSt��w)z9Declare that package 'packageName' is a namespace packageNrJr�)�_imp�acquire_lockr��release_lockrOr��
 770  rpartitionrfr�r�r�rZr�r#r�r�)r�r�r]r�r�rnrrrrf�s.����rfcCsLt��zt�|d�D]}t||�}|rt||�qWt��dSt��w)zDEnsure that previously-declared namespace packages include path_itemrN)r�r�r�r�r�r�r�)rnr]�packager{rrrr�	s
 771  
 772  ��r�cCsBtj�||�d�d�}t|�}|jD]}t|�|krdSq|S)zBCompute an ns-package subpath for a filesystem or zipfile importerrJr�N)r�r�rQr	r�r�)rirnr�r�r{�
 773  normalizedr.rrr�file_ns_handler	s
 774  �r�cCrDr$r)rirnr�r�rrr�null_ns_handler3	rr�cCs tj�tj�tj�t|����S)z1Normalize a file/dir name for comparison purposes)r�r��normcase�realpathr)�
_cygwin_patch�r�rrrr�:	s�r�cCstjdkrtj�|�S|S)a
 775      Contrary to POSIX 2008, on Cygwin, getcwd (3) contains
 776      symlink components. Using
 777      os.path.abspath() works around this limitation. A fix in os.getcwd()
 778      would probably better, in Cygwin even more so, except
 779      that this seems to be by design...
 780      �cygwin)rOrPr�r��abspathr�rrrr�@	sr�cCs2z||WStyt|�||<}|YSwr$)r�r�)r�r��resultrrrr�K	s
 781  �r�cCst|�pt|�S)z7
 782      Determine if given path appears to be an egg.
 783      )�_is_zip_eggr�r^rrrrS	srcCs$|���d�otj�|�ot�|�S)N�.egg)rrrtr�r�rPr"�
 784  is_zipfiler^rrrr�Z	s
 785  
 786  ��r�cCs&|���d�otj�tj�|dd��S)z@
 787      Determine if given path appears to be an unpacked egg.
 788      r�r
 789  ra)rrrtr�r�rPrQr^rrrr�b	s�r�cCs@|�d�}|��}|rd�|�}ttj||tj|�dSdS)NrJ)r	r@rQ�setattrrOr�)r�r\r�r]rrrr�l	s
 790  
 791  �r�z\w+(\.\w+)*$z�
 792      (?P<name>[^-]+) (
 793          -(?P<ver>[^-]+) (
 794              -py(?P<pyver>[^-]+) (
 795                  -(?P<plat>.+)
 796              )?
 797          )?
 798      )?
 799      c@s�eZdZdZddd�Zdd�Zdd	�Zddd�Zd
d�Zddd�Z	e
 800  �d�Ze
ddd��Ze
dd��Ze
ddd��Ze
ddd��ZdS)rrz3Object representing an advertised importable objectrNcCs<t|�s	td|��||_||_t|�|_t|�|_||_dS)NzInvalid module name)�MODULErTr��module_name�tuple�attrsrCr�)r�r�r�r�rCr�rrrr�	s
 801  
 802  
 803  
 804  zEntryPoint.__init__cCsHd|j|jf}|jr|dd�|j�7}|jr"|dd�|j�7}|S)Nz%s = %s�:rJz [%s]�,)r�r�r�rQrC)r��srrrr��	szEntryPoint.__str__cC�dt|�S)NzEntryPoint.parse(%r)�r�r�rrrr��	rzEntryPoint.__repr__TcOs8|r|s|rtjdtdd�|r|j|i|��|��S)zH
 805          Require packages for this EntryPoint, then resolve it.
 806          zJParameters to load are deprecated.  Call .resolve and .require separately.rKr�)rrr rXr)r�rXrF�kwargsrrrr&�	s�zEntryPoint.loadc
 807  CsLt|jdgdd�}z	t�t|j|�WSty%}ztt|��|�d}~ww)zD
 808          Resolve the entry point from its module and attrs.
 809          rr)�fromlist�levelN)	r�r��	functools�reducer�r�rZrr�)r�r�r�rrrr�	s��zEntryPoint.resolvecCsL|jr|jstd|��|j�|j�}tj||||jd�}tttj|��dS)Nz&Can't require() without a distribution)rC)	rCr�rvr,rgrr;rQr)r�rGrHr!r.rrrrX�	s
 810  
 811  zEntryPoint.requirez]\s*(?P<name>.+?)\s*=\s*(?P<module>[\w.]+)\s*(:\s*(?P<attr>[\w.]+))?\s*(?P<extras>\[.*\])?\s*$cCsf|j�|�}|sd}t||��|��}|�|d�}|dr%|d�d�nd}||d|d|||�S)aParse a single entry point from string `src`
 812  
 813          Entry point syntax follows the form::
 814  
 815              name = some.module:some.attr [extra1, extra2]
 816  
 817          The entry name and module name are required, but the ``:attrs`` and
 818          ``[extras]`` parts are optional
 819          z9EntryPoint must be in 'name=module:attrs [extras]' formatrC�attrrJrr�r�)�patternrNrT�	groupdict�
_parse_extrasr	)r�srcr�rVr��resrCr�rrrr��	s
 820  zEntryPoint.parsecCs(|sdSt�d|�}|jrt��|jS)Nr�x)rqr��specsrTrC)r�extras_specr�rrrr��	szEntryPoint._parse_extrascCsVt|�s	td|��i}t|�D]}|�||�}|j|vr#td||j��|||j<q|S)zParse an entry point groupzInvalid group namezDuplicate entry point)r�rTr
 821  r�r�)rrS�linesr��thisr��eprrr�parse_group�	s
 822  
 823  zEntryPoint.parse_groupcCstt|t�r
 824  |��}nt|�}i}|D]%\}}|dur!|sqtd��|��}||vr.td|��|�|||�||<q|S)z!Parse a map of entry point groupsNz%Entry points must be listed in groupszDuplicate group name)r�r(r.r}rTr�r)r�datar��mapsrSr�rrr�	parse_map�	s
 825  
 826  
 827  zEntryPoint.parse_map)rrNra)NNr$)rrrrrr�r�r&rrXr�r�r�rbr�r�rrrrrrrr�	s&
 828  	
 829  
 830  
 831  
�	
 832  rrcCs@dd�}t||�}tt|�d�}|�d�\}}}t|���pdS)z�
 833      Given an iterable of lines from a Metadata file, return
 834      the value of the Version field, if present, or None otherwise.
 835      cSs|���d�S)Nzversion:)rrr�)r�rrr�is_version_line
 836  rCz+_version_from_file.<locals>.is_version_liner�r�N)rrr��	partitionrzr�)r�r�
version_linesr�r�r�rrr�_version_from_file
 837  s
 838  
 839  r	cs�eZdZdZdZddddedefdd�ZedRdd��Z	dd	�Z
 840  ed
 841  d��Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zedd��Zedd��Zdd�Zed d!��Zed"d#��Zed$d%��Zd&d'�ZdSd)d*�Zd+d,�Zd-d.�Zd/d0�ZdTd2d3�Z d4d5�Z!d6d7�Z"d8d9�Z#d:d;�Z$�fd<d=�Z%edRd>d?��Z&d@dA�Z'dBdC�Z(dRdDdE�Z)dFdG�Z*dTdHdI�Z+dJdK�Z,dLdM�Z-dNdO�Z.edPdQ��Z/�Z0S)Urpz5Wrap an actual or potential sys.path entry w/metadataraNcCsFt|pd�|_|durt|�|_||_||_||_||_|pt|_	dS)N�Unknown)
 842  ryrErz�_versionrnrPr2r�r��	_provider)r�r2rerErrnrPr�rrrr
 843  s
 844  zDistribution.__init__cKs~dgd\}}}}tj�|�\}}	|	��tvr/t|	��}t|�}
 845  |
 846  r/|
 847  �dddd�\}}}}|||f||||d�|����S)Nr�r��ver�pyverrU)rErrnrP)r�r�r�rr�_distributionImpl�EGG_NAMErS�_reload_version)rr2rrer+rErrnrPr�rNrrrry%
 848  s&�����zDistribution.from_locationcCs|Sr$rr�rrrr6
 849  rzDistribution._reload_versioncCs$|j|j|j|j|jpd|jpdfSr)�parsed_versionr�r>r2rnrPr�rrrru9
 850  s�zDistribution.hashcmpcCs
 851  t|j�Sr$)�hashrur�rrr�__hash__D
 852  r�zDistribution.__hash__cCs|j|jkSr$�ru�r�r~rrr�__lt__G
 853  rzDistribution.__lt__cCs|j|jkSr$rrrrr�__le__J
 854  rzDistribution.__le__cCs|j|jkSr$rrrrr�__gt__M
 855  rzDistribution.__gt__cCs|j|jkSr$rrrrr�__ge__P
 856  rzDistribution.__ge__cCst||j�sdS|j|jkSr�)r�r�rurrrr�__eq__S
 857  szDistribution.__eq__cC�
 858  ||kSr$rrrrr�__ne__Y
 859  r�zDistribution.__ne__cCs0z|jWSty|j��|_}|YSwr$)�_keyrZrErrr}rrrr>`
 860  s�zDistribution.keycCst|d�st|j�|_|jS)N�_parsed_version)r�r#rrr�rrrrh
 861  s
 862  zDistribution.parsed_versioncCs\tjj}t|j|�}|sdS|jsdSt�d����dd�}t	�
 863  |jdit|���t
�dS)Na>
 864              '{project_name} ({version})' is being parsed as a legacy,
 865              non PEP 440,
 866              version. You may find odd behavior and sort order.
 867              In particular it will be sorted as less than 0.0. It
 868              is recommended to migrate to PEP 440 compatible
 869              versions.
 870              r�r�r)rrr!r�rr�r�r�r�rrr��varsr)r��LV�	is_legacyr�rrr�_warn_legacy_versiono
 871  s� 	z!Distribution._warn_legacy_versionc
 872  Cshz|jWSty3}z#|��}|dur'|�|j�}d�|j|�}t||�|�|WYd}~Sd}~ww)Nz4Missing 'Version:' header and/or {} file at path: {})rrZ�_get_version�_get_metadata_path_for_display�PKG_INFOr�rT)r�r�rr�r�rrrr�
 873  s
 874  ���zDistribution.versioncCs0z|jWSty|�|���|_Y|jSw)z~
 875          A map of extra to its list of (direct) requirements
 876          for this distribution, including the null extra.
 877          )�_Distribution__dep_maprZ�_filter_extras�_build_dep_mapr�rrr�_dep_map�
 878  s�zDistribution._dep_mapcCsrttd|��D]/}|}|�|�}|�d�\}}}|o"t|�p"t|�}|r'g}t|�p,d}|�|g��|�q|S)z�
 879          Given a mapping of extras to dependencies, strip off
 880          environment markers and filter out any dependencies
 881          not matching the markers.
 882          Nr�)	r;rr@rr�r�r~r#rD)�dmrc�	new_extrar!r�re�fails_markerrrrr(�
 883  s
 884  �zDistribution._filter_extrascCs@i}dD]}t|�|��D]\}}|�|g��t|��q
q|S)N)zrequires.txtzdepends.txt)r}�
_get_metadatar#rDrx)r�r+r�rcr!rrrr)�
 885  s�zDistribution._build_dep_maprcCsj|j}g}|�|�dd��|D]"}z|�|t|��Wqty2}z	td||f�|�d}~ww|S)z@List of Requirements needed for this distro if `extras` are usedNrz%s has no such extra feature %r)r*rDr�r~r�rv)r�rCr+�depsr�r�rrrr,�
 886  s
 887  ����zDistribution.requirescCs(z	|j�|�}W|StyYdSw)zK
 888          Return the path to the given metadata file, if available.
 889          z[could not detect])rr�r�r�rrrr%�
 890  s��z+Distribution._get_metadata_path_for_displayccs*�|�|�r|�|�D]}|VqdSdSr$)rr)r�r�r�rrrr.�
 891  s�
 892  �zDistribution._get_metadatacCs|�|j�}t|�}|Sr$)r.r&r	)r�r�rrrrr$�
 893  szDistribution._get_versionFcCsZ|durtj}|j||d�|tjur)t|j�|�d�D]
}|tjvr(t|�qdSdS)z>Ensure distribution is importable on `path` (default=sys.path)Nr0�namespace_packages.txt)rOr�r1r�r2r.r�rf)r�r�r��pkgrrr�activate�
 894  s
 895  
 896  
 897  ��zDistribution.activatecCs8dt|j�t|j�|jp
tf}|jr|d|j7}|S)z@Return what this distribution's standard .egg filename should bez
 898  %s-%s-py%sr�)rrErrnr�rP)r�r�rrrr��
 899  s�zDistribution.egg_namecCs|jr
 900  d||jfSt|�S)Nz%s (%s))r2r�r�rrrr�szDistribution.__repr__cCs>zt|dd�}Wntyd}Ynw|pd}d|j|fS)Nrz[unknown version]z%s %s)r�rTrE)r�rrrrr�s�zDistribution.__str__cCs|�d�r	t|��t|j|�S)zADelegate all unrecognized public attributes to .metadata providerr�)r�rZr�r)r�r�rrr�__getattr__s
 901  zDistribution.__getattr__cs.tttt|����tdd�|j��D��B�S)Ncss�|]
 902  }|�d�s|VqdS�r�N)r�)r(r�rrrr*s��
 903  �z'Distribution.__dir__.<locals>.<genexpr>)r;r?rrp�__dir__rr�r�rrr5s���zDistribution.__dir__cKs"|jt|�tj�|�|fi|��Sr$)ryr�r�r�r)rr�rer+rrrrus
 904  ��zDistribution.from_filenamecCs<t|jtjj�rd|j|jf}nd|j|jf}t�|�S)z?Return a ``Requirement`` that matches this distribution exactlyz%s==%sz%s===%s)r�rrrrrErqr�)r�r�rrrrR%s
 905  zDistribution.as_requirementcCs.|�||�}|durtd||ff��|��S)z=Return the `name` entry point of `group` or raise ImportErrorNzEntry point %r not found)r^rr&)r�rSr�rrrrr\.szDistribution.load_entry_pointcCsNz|j}Wntyt�|�d�|�}|_Ynw|dur%|�|i�S|S)r�zentry_points.txtN)�_ep_maprZrrrr.r�)r�rS�ep_maprrrr]5s
 906  
 907  ��zDistribution.get_entry_mapcCs|�|��|�Sr�)r]r�r+rrrr^Ar�zDistribution.get_entry_infoc
 908  Cs(|p|j}|s	dSt|�}tj�|�}dd�|D�}t|�D]<\}}||kr-|r*nKdS||krZ|jtkrZ|sC|||d�vrCdS|tjurL|�	�|�
 909  ||�|�
 910  ||�nq|tjurd|�	�|rn|�
 911  d|�dS|�|�dS	z
 912  |�||d�}	Wn
 913  t
y�YdSw||	=||	=|	}qv)a�Ensure self.location is on path
 914  
 915          If replace=False (default):
 916              - If location is already in path anywhere, do nothing.
 917              - Else:
 918                - If it's an egg and its parent directory is on path,
 919                  insert just ahead of the parent.
 920                - Else: add to the end of path.
 921          If replace=True:
 922              - If location is already on path anywhere (not eggs)
 923                or higher priority than its parent (eggs)
 924                do nothing.
 925              - Else:
 926                - If it's an egg and its parent directory is on path,
 927                  insert just ahead of the parent,
 928                  removing any lower-priority entries.
 929                - Else: add it to the front of path.
 930          NcSsg|]
 931  }|r
 932  t|�p|�qSrr�r�rrrr�`sz*Distribution.insert_on.<locals>.<listcomp>rTr�)r2r�r�r�r��	enumerater�r�rO�check_version_conflictr6r�r�rT)
 933  r�r��locr��nloc�bdir�npathr�r.�nprrrr1FsJ
 934  
 935  �
 936  
 937  ���zDistribution.insert_oncCs�|jdkrdSt�|�d��}t|j�}|�d�D]8}|tjvs(||vs(|tvr)q|dvr.qt	tj|dd�}|rGt|��
 938  |�sF|�
 939  |j�rGqtd|||jf�qdS)N�
 940  setuptoolsr0z
top_level.txt)�
pkg_resourcesr?�siter�zIModule %s was already imported from %s, but %s is being added to sys.path)r>r(r)r.r�r2rOr�r�r�r��
issue_warning)r��nspr:�modname�fnrrrr9�s*
 941  
 942  
 943  �
 944  ���z#Distribution.check_version_conflictcCs2z|jWdStytdt|��YdSw)NzUnbuilt egg for FT)rrTrBr�r�rrrrx�s��zDistribution.has_versioncKsDd}|��D]}|�|t||d��q|�d|j�|jdi|��S)z@Copy this distribution, substituting in any changed keyword argsz<project_name version py_version platform location precedenceNrer)r	r#r�rr�)r�r+r�r�rrr�clone�s
 945  zDistribution.clonecCsdd�|jD�S)NcSsg|]}|r|�qSrr)r(�deprrrr��r�z'Distribution.extras.<locals>.<listcomp>)r*r�rrrrC�r�zDistribution.extrasr$r�r�)1rrrrr&r�r�rrbryrr�rurrrrrrrr>rr#rr*r�r(r)r,r%r.r$r2r�r�r�r3r5rurRr\r]r^r1r9rxrFrCr
rrr�rrp
 946  sj
 947  �

 948  
 949  
 950  
 951  
 952  
 953  
 954  
 955  
 956  		
 957  
 958  Drpc@seZdZdd�ZdS)�EggInfoDistributioncCs|��}|r	||_|S)a�
 959          Packages installed by distutils (e.g. numpy or scipy),
 960          which uses an old safe_version, and so
 961          their version numbers can get mangled when
 962          converted to filenames (e.g., 1.11.0.dev0+2329eae to
 963          1.11.0.dev0_2329eae). These distributions will not be
 964          parsed properly
 965          downstream by Distribution and safe_version, so
 966          take an extra step and try to get the version number from
 967          the metadata file itself instead of the filename.
 968          )r$r)r��
 969  md_versionrrrr�sz#EggInfoDistribution._reload_versionN)rrrrrrrrrH�srHc@s>eZdZdZdZe�d�Zedd��Z	edd��Z
 970  dd	�Zd
 971  S)�DistInfoDistributionzV
 972      Wrap an actual or potential sys.path entry
 973      w/metadata, .dist-info style.
 974      �METADATAz([\(,])\s*(\d.*?)\s*([,\)])cCs@z|jWSty|�|j�}tj���|�|_|jYSw)zParse and cache metadata)�	_pkg_inforZrr&�email�parser�Parser�parsestr)r�rerrr�_parsed_pkg_info�s
 975  �z%DistInfoDistribution._parsed_pkg_infocCs,z|jWSty|��|_|jYSwr$)�_DistInfoDistribution__dep_maprZ�_compute_dependenciesr�rrrr*�s
 976  
 977  �zDistInfoDistribution._dep_mapcs�dgi}|_g�|j�d�pgD]	}��t|��q�fdd�}t�t�|d����|d���|j�d�p9gD]}t	|�
 978  ��}�fdd�||�D�||<q:|S)z+Recompute this distribution's dependencies.Nz
Requires-Distc3s,��D]}|jr|j�d|i�r|VqdS)Nrcrd)rcr�)r!rr�reqs_for_extra�s���zBDistInfoDistribution._compute_dependencies.<locals>.reqs_for_extrazProvides-Extracsg|]}|�vr|�qSrr)r(�r)�commonrrr��sz>DistInfoDistribution._compute_dependencies.<locals>.<listcomp>)rRrQ�get_allrDrxr��MappingProxyTyper(r)r~r�)r�r+r�rTrc�s_extrar)rVr!rrS�sz*DistInfoDistribution._compute_dependenciesN)rrrrr&r�r��EQEQr�rQr*rSrrrrrJ�s
 979  
 980  	
 981  rJ)r�rsrrcOsfd}t�}zt�|�j|ur|d7}t�|�j|usWn	ty$Ynwtj|d|di|��dS)Nr�r�)r%rOr�r�rTrr)rFr+r�r1rrrrBs���rBcCstttttt|����S)z�
 982      Yield ``Requirement`` objects for each specification in `strs`.
 983  
 984      `strs` must be a string, or a (possibly-nested) iterable thereof.
 985      )rQrqrrr
 986  )�strsrrrrxsrxc@r)�RequirementParseErrorz,Compatibility wrapper for InvalidRequirementNrrrrrr\rr\csPeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
 987  �Zdd�Ze	d
d��Z
 988  �ZS)rqcs�tt|��|�|j|_t|j�}||��|_|_dd�|j	D�|_
 989  ttt
|j��|_|j|j|j	t|j�|jr>t|j�ndf|_t|j�|_dS)z>DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!cSsg|]}|j|jf�qSr)ryr)r(r�rrrr�"s�z(Requirement.__init__.<locals>.<listcomp>N)rrqrr��unsafe_nameryrrrEr>�	specifierr�r�rQr~rC�url�	frozensetrer��hashCmpr�_Requirement__hash)r��requirement_stringrEr�rrrs
 990  ��zRequirement.__init__cCst|t�o
 991  |j|jkSr$)r�rqrarrrrr.s
 992  
 993  �zRequirement.__eq__cCrr$rrrrrr4r�zRequirement.__ne__cCs0t|t�r|j|jkr
dS|j}|jj|dd�S)NFT)�prereleases)r�rpr>rr^�contains)r�r.rrrr%7s
 994  
 995  zRequirement.__contains__cCr_r$)rbr�rrrrCr`zRequirement.__hash__cCr�)NzRequirement.parse(%r)r�r�rrrr�FrzRequirement.__repr__cCst|�\}|Sr$)rx)r�r�rrrr�Is
 996  zRequirement.parse)rrrrrrr%rr�r�r�r
rrr�rrqsrqcCst|vr	|tfS|S)zJ
 997      Ensure object appears in the mro even
 998      for old-style classes.
 999      )�object)�classesrrr�_always_objectOs
1000  rhcCs<tt�t|dt|����}|D]}||vr||SqdS)z2Return an adapter factory for `ob` from `registry`r�N)rh�inspect�getmror�r)�registryr?r��trrrr�Ys��r�cCstj�|�}tj|dd�dS)z1Ensure that the parent directory of `path` existsT)�exist_okN)r�r�r��makedirs)r�r�rrrr�asr�cCsbtstd��t|�\}}|r+|r-t|�s/t|�zt|d�WdSty*YdSwdSdSdS)z/Sandbox-bypassing version of ensure_directory()z*"os.mkdir" not supported on this platform.i�N)rIrJr	rr�r�FileExistsError)r�r�r�rrrr�gs��r�ccsv�d}g}t|�D]*}|�d�r.|�d�r)|s|r||fV|dd���}g}q	td|��|�|�q	||fVdS)asSplit a string or iterable thereof into (section, content) pairs
1001  
1002      Each ``section`` is a stripped version of the section header ("[section]")
1003      and each ``content`` is a list of stripped lines excluding blank lines and
1004      comment-only lines.  If there are any such lines before the first section
1005      header, they're returned in a first ``section`` of ``None``.
1006      N�[�]r�r�zInvalid section heading)r
1007  r�rtr�rTr�)r��section�contentr�rrrr}ts�
1008  
1009  
1010  
1011  r}cOs.tj}ztt_tj|i|��W|t_S|t_wr$)r�r�os_open�tempfile�mkstemp)rFr+�old_openrrrrL�s
1012  rLr�)�categoryr�cOs||i|��|Sr$r)rWrFr�rrr�_call_aside�srycs.t���|d<|��fdd�t��D��dS)z=Set up global resource manager (deliberately not state-saved)�_managerc3s(�|]}|�d�s|t�|�fVqdSr4)r�r�r�rrrr*�s��
1013  �z_initialize.<locals>.<genexpr>N)ror&rG)r1rr{r�_initialize�s
1014  �r|c@r)r z�
1015      Base class for warning about deprecations in ``pkg_resources``
1016  
1017      This class is not derived from ``DeprecationWarning``, and as such is
1018      visible by default.
1019      Nrrrrrr �rr cCs|t��}td|d�|j}|j}|j}|j}|}tdd�|D��|dd�dd�g|_t	t
1020  |jtj
��t��t��d	S)
1021  aE
1022      Prepare the master working set and make the ``require()``
1023      API available.
1024  
1025      This function has explicit effects on the global state
1026      of pkg_resources. It is intended to be invoked once at
1027      the initialization of this module.
1028  
1029      Invocation by other packages is unsupported and done
1030      at their own risk.
1031      rf)rgcss�|]	}|jdd�VqdS)Fr0N�r2)r(r�rrrr*�s
1032  �
10331034  �z1_initialize_master_working_set.<locals>.<genexpr>cSs|jdd�S)NTr0r}r�rrrrG�sz0_initialize_master_working_set.<locals>.<lambda>F)r^N)rnrr,rXr_r_rYr�rr;rQrrOr�r%r&r�)rgrXr_rhrYr�rrr�_initialize_master_working_set�s"
��r~r$r�)�rrOr�r�rAr�r�r"rwrr�r��pkgutilryrPr=r��email.parserrMr�rur�r�rir�r�r�rr�r�impro�	NameErrorr�rrrrrIrrt�os.pathrr	�importlib.machinery�	machineryrr� pkg_resources.extern.jaraco.textr
1035  rrZpkg_resources.externr
rr��version_info�RuntimeErrorrXrgrh�resources_streamrk�resource_dirrarjrer`r_rcrbrdrkr�r��RuntimeWarningrr#r'r,r3r5r:r@rArB�
1036  _sget_none�
1037  _sset_nonerW�__all__r�rsrtr�rurvr�r�r�r�r�r�r�r�r�rZrRr�rLr�rMr�r{r|rYr�r[r\r]r^r�r�rnr(r<rmr�rwrorlryrzr~rr�r�r�rfrr�r�rr�r�rr'r�rxr�r�r�r�rirvr}r�r�r�r�r�r�r�r��ImpImporterr�r�r�r�r�rfr�r�r�r�r�r�rr�r�r�rNr��VERBOSE�
1038  IGNORECASErrrr	rprHrJrrBrxrF�InvalidRequirementr\rqrhr�r�r�r}rL�filterwarningsryr%r|�Warningr r~rrrr�<module>s����
1039  �2 

1040  

1041  
1042  .
1043  
1044  6	
1045  
1046  @.)
1047  
1048  
1049  
1050  
1051  
1052  ##%"
1053  "

1054  
1055  
1056  	��
$3�
	4
1057