U l aG@sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZz ddlZWnek rddlZYnXze Wne!k r*e"Z YnXddl#m$Z$ddl%m&Z&m'Z'ddlm(Z(zddlm)Z)m*Z*m+Z+d Z,Wnek rd Z,YnXdd lm-Z.dd l/m0Z0m1Z1zddl2m3Z4e4j5Wnek rdZ4YnXd dl6m7Z7ddl#m8Z8ddl#m9Z9e:de:de:de:de:de;Zde$j?r`dZ@dZAdZBdZCdZDdZEdZFdZGdZHdZIdZJdZKdZLdZMdZNdZOdZPdZQdZRGdddeSZTddZUiZVddZWdd ZXd!d"ZYd#d$ZZd%d&Z[d'd(Z\d)d*Z]d+d,Z^Z_d-d.Z`d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNddOddPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsgGZaGdtdJdJebZcGdudKdKecZdGdvdwdwedZeGdxdLdLecZfGdydMdMecZgiZhdzjiej=Zjd{Zkd|Zld ZmdZnd}Zod~dnZpdd1ZqgfddZrddZsddZteudZveudZwetZxddSZydd0ZzezZ{dd2Z|dd3Z}ddd4Z~dd5ZGddadaZGddbdbeZGddEdEZGdddeZGddDdDZeZGddNdNe>ZGddFdFZddCZddPZddQZddVZddWZddXZdddYZGddhdhZepeeddZGddidieZGddjdjeZeGddfdfeZeZGdddeZGdddeZGddkdkeZepe jeGddcdceZGdddddeZGddedeeZeWdidddlZddd@ZdddZee jedddZeeeddZdddZddZGdddZddZddZddZdd„Zeejeee4dÃree4jeeWdidčeWdidōddmZddȄZddʄZdd=ZdddoZdd΄Zeejeee jeee4dÃr8ee4jeddЄZeeedd[ZddӄZifddՄZddׄZddلZddۄZddTZeudݡjZeudejejBjZGddIdIZddZGddGdGZGdddeÃZGdddeÃZeeedZddZGdddeȃZddOZGddHdHe9jj̃ZddZddZddZZddZddUZddZe jdeTd dddZeeՃfddZeddZGddqdqe؃ZdS(aZ Package resource API -------------------- A resource is a logical file contained within a package, or a logical subdirectory thereof. The package resource API expects resource names to have their path parts separated with ``/``, *not* whatever the local path separator is. Do not use os.path operations to manipulate resource names being passed into the API. The package resource API is designed to work with normal filesystem packages, .egg files, and unpacked .egg files. It can also work in a limited way with .zip files and with custom PEP 302 loaders that support the ``get_data()`` method. )absolute_importN) get_importer)six)mapfilter)utime)mkdirrenameunlinkTF)open)isdirsplit) py31compat)appdirs) packagingz&pkg_resources.extern.packaging.versionz)pkg_resources.extern.packaging.specifiersz+pkg_resources.extern.packaging.requirementsz&pkg_resources.extern.packaging.markerszpkg_resources.py2_warn)r)rzPython 3.5 or later is requiredc@seZdZdZdS) PEP440Warningza Used when there is an issue with a version or specifier not complying with PEP 440. N__name__ __module__ __qualname____doc__rrWC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-wx4infiz\pkg_resources\__init__.pyrysrcCs8ztj|WStjjk r2tj|YSXdSN)rversionVersionInvalidVersion LegacyVersion)vrrr parse_versionsr"cKs"t|tt||dSr)globalsupdate _state_varsdictfromkeys)vartypekwrrr_declare_states r*cCs8i}t}tD] \}}|d|||||<q|S)N_sget_)r#r%itemsstategkr!rrr __getstate__s r1cCs8t}|D]$\}}|dt|||||q|S)N_sset_)r#r,r%r-rrr __setstate__sr3cCs|Sr)copyvalrrr _sget_dictsr7cCs|||dSr)clearr$keyobr.rrr _sset_dictsr<cCs|Sr)r1r5rrr _sget_objectsr=cCs||dSr)r3r9rrr _sset_objectsr>cGsdSrrargsrrrrAcCsbt}t|}|dk r^tjdkr^z&ddtdd|df}Wntk r\YnX|S)aQReturn this platform's maximum compatible version. distutils.util.get_platform() normally reports the minimum version of macOS that would be required to *use* extensions produced by distutils. But what we want when checking compatibility is to know the version of macOS that we are *running*. To allow usage of packages that explicitly require a newer version of macOS, 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. Ndarwinz macosx-%s-%s.r) get_build_platformmacosVersionStringmatchsysplatformjoin _macos_versgroup ValueError)platmrrrget_supported_platforms  &rQrequire run_script get_providerget_distributionload_entry_point get_entry_mapget_entry_infoiter_entry_pointsresource_stringresource_streamresource_filenameresource_listdirresource_existsresource_isdirdeclare_namespace working_setadd_activation_listenerfind_distributionsset_extraction_pathcleanup_resourcesget_default_cache Environment WorkingSetResourceManager Distribution Requirement EntryPointResolutionErrorVersionConflictDistributionNotFound UnknownExtraExtractionErrorparse_requirements safe_name safe_version get_platformcompatible_platforms yield_linessplit_sections safe_extra to_filenameinvalid_markerevaluate_markerensure_directorynormalize_pathEGG_DIST BINARY_DIST SOURCE_DIST CHECKOUT_DIST DEVELOP_DISTIMetadataProviderIResourceProvider FileMetadata PathMetadata EggMetadata EmptyProviderempty_provider NullProvider EggProviderDefaultProvider ZipProviderregister_finderregister_namespace_handlerregister_loader_typefixup_namespace_packagesrPkgResourcesDeprecationWarningrun_mainAvailableDistributionsc@seZdZdZddZdS)rmz.Abstract base for dependency resolution errorscCs|jjt|jSr) __class__rreprr@selfrrr__repr__szResolutionError.__repr__N)rrrrrrrrrrmsc@s<eZdZdZdZeddZeddZddZd d Z d S) rnz An already-installed version conflicts with the requested version. Should be initialized with the installed Distribution and the requested Requirement. z3{self.dist} is installed but {self.req} is requiredcCs |jdSNrr?rrrrdist szVersionConflict.distcCs |jdSNrr?rrrrreqszVersionConflict.reqcCs|jjftSr _templateformatlocalsrrrrreportszVersionConflict.reportcCs|s|S|j|f}t|S)zt If required_by is non-empty, return a version of self that is a ContextualVersionConflict. )r@ContextualVersionConflict)r required_byr@rrr with_contexts zVersionConflict.with_contextN) rrrrrpropertyrrrrrrrrrns  c@s&eZdZdZejdZeddZdS)rz A VersionConflict that accepts a third parameter, the set of the requirements that required the installed Distribution. z by {self.required_by}cCs |jdS)NrEr?rrrrr+sz%ContextualVersionConflict.required_byN)rrrrrnrrrrrrrr#s rc@sHeZdZdZdZeddZeddZeddZd d Z d d Z d S)roz&A requested distribution was not foundzSThe '{self.req}' distribution was not found and is required by {self.requirers_str}cCs |jdSrr?rrrrr6szDistributionNotFound.reqcCs |jdSrr?rrrr requirers:szDistributionNotFound.requirerscCs|js dSd|jS)Nzthe applicationz, )rrKrrrr requirers_str>sz"DistributionNotFound.requirers_strcCs|jjftSrrrrrrrDszDistributionNotFound.reportcCs|Sr)rrrrr__str__GszDistributionNotFound.__str__N) rrrrrrrrrrrrrrrro0s   c@seZdZdZdS)rpz>Distribution doesn't have an "extra feature" of the given nameNrrrrrrpKsz{}.{}rrEcCs |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_typeprovider_factoryrrrrYscCstt|tr$t|p"tt|dSztj|}Wn&tk rXt |tj|}YnXt |dd}t t ||S)z?Return an IResourceProvider for the named module or requirementr __loader__N) isinstancerkrafindrRstrrImodulesKeyError __import__getattr _find_adapterr) moduleOrReqmoduleloaderrrrrTcs  cCsd|s\td}|dkrLd}tj|rLttdrLt|}d|krL|d}|| d|dS)Nrz0/System/Library/CoreServices/SystemVersion.plist readPlistProductVersionrD) rJmac_verospathexistshasattrplistlibrappendr )_cacherplist plist_contentrrrrLps    rLcCsddd||S)Nppc)PowerPCPower_Macintosh)get)machinerrr _macos_archsrcCs~ddlm}|}tjdkrz|dszz>t}tddd}dt |dt |d t |fWSt k rxYnX|S) zReturn 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 macOS. r)rurCzmacosx- _zmacosx-%d.%d-%sr) sysconfigrurIrJ startswithrLrunamereplaceintrrN)rurOrrrrrrFs  rFzmacosx-(\d+)\.(\d+)-(.*)zdarwin-(\d+)\.(\d+)\.(\d+)-(.*)cCs|dks|dks||krdSt|}|rt|}|st|}|rt|d}d|d|df}|dkr||dks|dkr|d krdSd S|d|dks|d |d krd St|dt|dkrd SdSd S) zCan 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. NTrz%s.%srEz10.3z10.4Fr)rGrHdarwinVersionStringrrM)providedrequiredreqMacprovMac provDarwindversion macosversionrrrrvs2   cCs<tdj}|d}|||d<t|d||dS)z@Locate distribution `dist_spec` and run its `script_name` scriptrrrNrI _getframe f_globalsr8rRrS)Z dist_spec script_namensnamerrrrSs  cCs@t|tjrt|}t|tr(t|}t|tsIs the named metadata a directory? (like ``os.path.isdir()``)Nrrrrrmetadata_isdirsz IMetadataProvider.metadata_isdircCsdS)z?List of metadata names in the directory (like ``os.listdir()``)Nrrrrrmetadata_listdirsz"IMetadataProvider.metadata_listdircCsdS)z=Execute the named script in the supplied namespace dictionaryNr)r namespacerrrrS szIMetadataProvider.run_scriptN) rrrrrrrrrSrrrrrs c@s@eZdZdZddZddZddZdd 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``Nrmanager resource_namerrrget_resource_filenamesz'IResourceProvider.get_resource_filenamecCsdS)ziReturn a readable file-like object for `resource_name` `manager` must be an ``IResourceManager``Nrrrrrget_resource_streamsz%IResourceProvider.get_resource_streamcCsdS)zmReturn a string containing the contents of `resource_name` `manager` must be an ``IResourceManager``Nrrrrrget_resource_stringsz%IResourceProvider.get_resource_stringcCsdS)z,Does the package contain the named resource?Nrrrrr has_resource szIResourceProvider.has_resourcecCsdS)z>Is the named resource a directory? (like ``os.path.isdir()``)Nrrrrrr_#sz IResourceProvider.resource_isdircCsdS)z?List of resource names in the directory (like ``os.listdir()``)Nrrrrrr]&sz"IResourceProvider.resource_listdirN) rrrrrrrrr_r]rrrrrsc@seZdZdZd'ddZeddZeddZd d Zd d Z d dZ d(ddZ ddZ ddZ d)ddZd*ddZd+ddZddZd,dd Zd!d"Zd#d$Zd%d&ZdS)-rhzDA collection of active distributions on sys.path (or a similar list)NcCs>g|_i|_i|_g|_|dkr&tj}|D]}||q*dS)z?Create working set from list of path entries (default=sys.path)N)entries entry_keysby_key callbacksrIr add_entry)rrentryrrr__init__-szWorkingSet.__init__cCsb|}zddlm}Wntk r.|YSXz||Wntk r\||YSX|S)z1 Prepare the master working set. r) __requires__)__main__r ImportErrorrRrn_build_from_requirements)clswsrrrr _build_master:s zWorkingSet._build_mastercCsf|g}t|}||t}|D]}||q"tjD]}||jkr8||q8|jtjdd<|S)zQ Build a working set from a requirement spec. Rewrites sys.path. N)rrresolvergaddrIrrr)rreq_specrreqsdistsrrrrrrNs    z#WorkingSet._build_from_requirementscCs<|j|g|j|t|dD]}|||dq$dS)aAdd 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 setdefaultrrrcr )rrrrrrrds  zWorkingSet.add_entrycCs|j|j|kS)z9True if `dist` is the active distribution for its project)rrr:rrrrr __contains__sszWorkingSet.__contains__cCs,|j|j}|dk r(||kr(t|||S)aFind 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)rrr:rn)rrrrrrrws  zWorkingSet.findcsfdd|DS)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). c3s8|]0}|D]}dks*|jkr|VqqdSr)rWvaluesr).0rrrMrrr s  z/WorkingSet.iter_entry_points..rrrMrrrrrYs zWorkingSet.iter_entry_pointscCs>tdj}|d}|||d<||d||dS)z?Locate distribution for `requires` and run `script_name` scriptrrrNr)rrequiresrrrrrrrSs  zWorkingSet.run_scriptccsLi}|jD]<}||jkrq |j|D] }||kr$d||<|j|Vq$q dS)zYield 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. rN)rrr)rseenitemr:rrr__iter__s  zWorkingSet.__iter__TFcCs|r|j|j||d|dkr$|j}|j|g}|j|jg}|sV|j|jkrVdS||j|j<|j|krx||j|j|kr||j||dS)aAdd `dist` to working set, associated with `entry` If `entry` is unspecified, it defaults to the ``.location`` of `dist`. On exit from this routine, `entry` is added to the end of the working set's ``.entries`` (if it wasn't already present). `dist` is only added to the working set if it's for a project that doesn't already have a distribution in the set, unless `replace=True`. If it's added, any callbacks registered with the ``subscribe()`` method will be called. rN) insert_onrlocationrrr:rr _added_new)rrrinsertrkeyskeys2rrrr s      zWorkingSet.addcCsxt|ddd}i}i}g}t} tt} |rt|d} | |krHq.| | |sVq.|| j} | dkr|j | j} | dks| | kr|r|} |dkr| dkrt |j }nt g}t g} |j | | ||d} || j<| dkr| | d}t| ||| | | kr$| | }t| | || | jddd}|||D] }| || j| j| |<qHd|| <q.|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``. Unless `replace_conflicting=True`, raises a VersionConflict exception if any requirements are found on the path that have the correct name but the wrong version. Otherwise, if an `installer` is supplied it will be invoked to obtain the correct version of the requirement and activate it. `extras` is a list of the extras to be used with these requirements. This is important because extra requirements may look like `my_req; extra = "my_extra"`, which would otherwise be interpreted as a purely optional requirement. Instead, we want to be able to assert that these requirements are truly required. Nrr)replace_conflictingT)list _ReqExtras collections defaultdictsetpop markers_passrr:rrgrrh best_matchrorrnrrextrasextendr  project_name)r requirementsenv installerr"r+ processedbest to_activate req_extrasrrrrr dependent_reqnew_requirementsnew_requirementrrrr sT            zWorkingSet.resolvec Cs t|}|i}i}|dkr4t|j}||7}n||}|g} tt| j||D]} || D]} | g} z| | ||} WnBt k r}z$||| <|rWYqfn WYqZW5d}~XYqfXtt| j| | t | qZqfqZt|}|||fS)asFind all activatable distributions in `plugin_env` Example usage:: distributions, errors = working_set.find_plugins( Environment(plugin_dirlist) ) # add plugins+libs to sys.path map(working_set.add, distributions) # display errors print('Could not load', errors) The `plugin_env` should be an ``Environment`` instance that contains only distributions that are in the project's "plugin directory" or directories. The `full_env`, if supplied, should be an ``Environment`` contains all currently-available distributions. If `full_env` is not supplied, one is created automatically from the ``WorkingSet`` this method is called on, which will typically mean that every directory on ``sys.path`` will be scanned for distributions. `installer` is a standard installer callback as used by the ``resolve()`` method. The `fallback` flag indicates whether we should attempt to resolve older versions of a plugin if the newest version cannot be resolved. This method returns a 2-tuple: (`distributions`, `error_info`), where `distributions` is a list of the distributions found in `plugin_env` that were loadable, along with any other distributions that are needed to resolve their dependencies. `error_info` is a dictionary mapping unloadable plugin distributions to an exception instance describing the error that occurred. Usually this will be a ``DistributionNotFound`` or ``VersionConflict`` instance. N) r#sortrgrrrr as_requirementr rmr$r&r')r plugin_envfull_envr0fallbackplugin_projects error_info distributionsr/ shadow_setr-rr resolveesr!rrr find_plugins(s4$      zWorkingSet.find_pluginscGs&|t|}|D]}||q|S)aEnsure 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. )r rrr )rr.neededrrrrrR|s  zWorkingSet.requirecCs8||jkrdS|j||s"dS|D] }||q&dS)zInvoke `callback` for all distributions If `existing=True` (default), call on all existing ones, as well. N)rr)rcallbackexistingrrrr subscribes  zWorkingSet.subscribecCs|jD] }||qdSr)r)rrrDrrrrs zWorkingSet._added_newcCs,|jdd|j|j|jddfSr)rrr4rrrrrrr1s   zWorkingSet.__getstate__cCs@|\}}}}|dd|_||_||_|dd|_dSr)rr4rrr)re_k_b_crr rrrrrr3s    zWorkingSet.__setstate__)N)N)NTF)NNFN)NNT)T)rrrrr classmethodr rrrrrYrSrr r rBrRrFrr1r3rrrrrh*s4      ] T c@seZdZdZdddZdS)r$z> Map each requirement to the extras that demanded it. Ncs2fdd|d|pdD}j p0t|S)z Evaluate markers for req against each extra that demanded it. Return False if the req has a marker and fails evaluation. Otherwise, return True. c3s|]}jd|iVqdS)extraNmarkerevaluate)rrIrrrrsz*_ReqExtras.markers_pass..rr)rrKany)rrr+ extra_evalsrrMrr)s z_ReqExtras.markers_pass)N)rrrrr)rrrrr$sr$c@sxeZdZdZdeefddZddZddZdd d Z d d Z d dZ dddZ dddZ ddZddZddZdS)rgz5Searchable snapshot of distributions on a search pathNcCs i|_||_||_||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.6'``); 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)_distmaprJpythonscan)r search_pathrJrQrrrrszEnvironment.__init__cCs2|jdkp|jdkp|j|jk}|o0t|j|jS)zIs 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)rQ py_versionrvrJ)rr py_compatrrrcan_adds   zEnvironment.can_addcCs|j|j|dS)z"Remove `dist` from the environmentN)rPr:removerrrrrWszEnvironment.removecCs4|dkrtj}|D]}t|D]}||qqdS)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)rIrrcr )rrSrrrrrrRs  zEnvironment.scancCs|}|j|gS)aReturn a newest-to-oldest list of distributions for `project_name` Uses case-insensitive `project_name` comparison, assuming all the project's distributions use their project's name converted to all lowercase as their key. )lowerrPr)rr-distribution_keyrrr __getitem__szEnvironment.__getitem__cCsL||rH|rH|j|jg}||krH|||jtddddS)zLAdd `dist` if we ``can_add()`` it and it has not already been added hashcmpTr:reverseN) rV has_versionrPrr:rr8operator attrgetter)rrrrrrr s  zEnvironment.addFcCsfz||}Wntk r,|s$d}YnX|dk r:|S||jD]}||krD|SqD|||S)aFind 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)rrnr:obtain)rrrar0r"rrrrr*s  zEnvironment.best_matchcCs|dk r||SdS)aObtain 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 requirementr0rrrra,s zEnvironment.obtainccs"|jD]}||r |Vq dS)z=Yield the unique project names of the available distributionsN)rPr rr:rrrr8szEnvironment.__iter__cCsVt|tr||ns    zEnvironment.__iadd__cCs*|jgddd}||fD] }||7}q|S)z4Add an environment or distribution to an environmentN)rJrQr)rrdnewr/rrr__add__Js  zEnvironment.__add__)N)NF)N)rrrrrQPY_MAJORrrVrWrRrZr r*rarrfrirrrrrgs"      c@seZdZdZdS)rqaTAn 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 NrrrrrrqVsc@seZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ dddZ eddZddZddZd ddZdS)!riz'Manage resource extraction and packagesNcCs i|_dSr) cached_filesrrrrrjszResourceManager.__init__cCst||S)zDoes the named resource exist?)rTrrpackage_or_requirementrrrrr^mszResourceManager.resource_existscCst||S)z,Is the named resource an existing directory?)rTr_rlrrrr_qszResourceManager.resource_isdircCst|||S)z4Return a true filesystem path for specified resource)rTrrlrrrr\wsz!ResourceManager.resource_filenamecCst|||S)z9Return a readable file-like object for specified resource)rTrrlrrrr[}szResourceManager.resource_streamcCst|||S)z%Return specified resource as a string)rTrrlrrrrZszResourceManager.resource_stringcCst||S)z1List the contents of the named resource directory)rTr]rlrrrr]sz ResourceManager.resource_listdircCsRtd}|jpt}td}t|jft }||_ ||_ ||_ |dS)z5Give an error message for problems extracting file(s)ra Can't extract file(s) to egg cache The following error occurred while trying to extract file(s) to the Python egg cache: {old_exc} The Python egg cache directory is currently set to: {cache_path} Perhaps your account does not have write access to this directory? You can change the cache directory by setting the PYTHON_EGG_CACHE environment variable to point to an accessible directory. N) rIexc_infoextraction_pathrftextwrapdedentlstriprqrrr cache_pathoriginal_error)rold_excrstmplerrrrrextraction_errors  z ResourceManager.extraction_errorrcCsf|jp t}tjj||df|}z t|Wntk rL|YnX||d|j |<|S)aReturn 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) rorfrrrK_bypass_ensure_directory Exceptionrx_warn_unsafe_extraction_pathrk)r archive_namenames extract_path target_pathrrrget_cache_paths    zResourceManager.get_cache_pathcCs\tjdkr|tjdsdSt|j}|tj@s>|tj@rXdjft }t |t dS)aN If the default extraction path is overridden and set to an insecure location, such as /tmp, it opens up an opportunity for an attacker to replace an extracted file with an unauthorized payload. Warn the user if a known insecure location is used. See Distribute #375 for more details. ntwindirNzExtraction 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).) rrrenvironstatst_modeS_IWOTHS_IWGRPrrwarningswarn UserWarning)rmodemsgrrrr{s  z,ResourceManager._warn_unsafe_extraction_pathcCs.tjdkr*t|jdBd@}t||dS)a4Perform any platform-specific postprocessing of `tempname` This is where Mac header rewrites should be done; other platforms don't have anything special they should do. Resource providers should call this method ONLY after successfully extracting a compressed resource. They must NOT call it on resources that are already in the filesystem. `tempname` is the current (temporary) name of the file, and `filename` is the name it will be renamed to by the caller after this routine returns. posiximiN)rrrrchmod)rtempnamefilenamerrrr postprocesss zResourceManager.postprocesscCs|jrtd||_dS)aSet 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)rkrNrorrrrrrds 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)rforcerrrre sz!ResourceManager.cleanup_resources)r)F)rrrrrorr^r_r\r[rZr]rxr staticmethodr{rrdrerrrrrifs   cCstjdptjddS)z Return the ``PYTHON_EGG_CACHE`` environment variable or a platform-relevant user cache dir for an app named "Python-Eggs". PYTHON_EGG_CACHEz Python-Eggs)appname)rrrruser_cache_dirrrrrrfs  cCstdd|S)zConvert an arbitrary string to a standard distribution name Any runs of non-alphanumeric/. characters are replaced with a single '-'. [^A-Za-z0-9.]+-)resubrrrrrs'scCsJzttj|WStjjk rD|dd}tdd|YSXdS)zB Convert an arbitrary string to a standard version string rrDrrN)rrrrrrrr)rrrrrt/s  cCstdd|S)zConvert 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)rrrX)rIrrrry;scCs |ddS)z|Convert a project or version name to its filename-escaped form Any '-' characters are currently replaced with '_'. rrrrrrrrzDsc CsHz t|Wn6tk rB}zd|_d|_|WYSd}~XYnXdS)zo Validate text as a PEP 508 environment marker; return an exception if invalid or False otherwise. NF)r| SyntaxErrorrlineno)texterrrr{Ls c CsJztj|}|WStjjk rD}z t|W5d}~XYnXdS)z Evaluate a PEP 508 environment marker. Return a boolean indicating the marker result in this environment. Raise SyntaxError if marker is invalid. This implementation uses the 'pyparsing' module. N)rmarkersMarkerrL InvalidMarkerr)rrIrKrrrrr|Zs   c@seZdZdZdZdZdZddZddZddZ d d Z d d Z d dZ ddZ ddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zed'd(Zd)d*ZdS)+rzETry to implement resources and metadata for arbitrary PEP 302 loadersNcCs(t|dd|_tjt|dd|_dS)Nr__file__r)rrrrdirname module_pathrrrrrrpszNullProvider.__init__cCs||j|Sr)_fnrrrrrrrrtsz"NullProvider.get_resource_filenamecCst|||Sr)ioBytesIOrrrrrrwsz NullProvider.get_resource_streamcCs|||j|Sr)_getrrrrrrrzsz NullProvider.get_resource_stringcCs|||j|Sr)_hasrrrrrrrr}szNullProvider.has_resourcecCs||j|Sr)regg_inforrrrr_get_metadata_pathszNullProvider._get_metadata_pathcCs |js |jS||}||Sr)rrrrrrrrrrs zNullProvider.has_metadatac Cst|js dS||}||}tjr(|Sz |dWStk rn}z|jd||7_W5d}~XYnXdS)Nrutf-8z in {} file at path: {}) rrrrPY2decodeUnicodeDecodeErrorreasonr)rrrvalueexcrrrrs   zNullProvider.get_metadatacCst||SrrwrrrrrrszNullProvider.get_metadata_linescCs|||j|Sr)_isdirrrrrrrr_szNullProvider.resource_isdircCs|jo|||j|Sr)rrrrrrrrszNullProvider.metadata_isdircCs|||j|Sr)_listdirrrrrrrr]szNullProvider.resource_listdircCs|jr|||j|SgSr)rrrrrrrrszNullProvider.metadata_listdirc Csd|}||s$tdjft||dd}|dd}||j|}||d<tj |rt | }t ||d}t|||n>dd lm}t|d|d|f||<t ||d} t| ||dS) Nzscripts/z