Sm@sO dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddl mZyddlmZmZWn(ek rddlmZmZYnXyeWn"ek r;ddlmZYnXy$eddZddlmZWn:ek reZdd lmZddd d Z YnXdd lm!Z!y&dd lm"Z"m#Z#m$Z$dZ%Wnek rdZ%YnXddlm&Z'ddl(m)Z)m*Z*ej+ddfko8ej,j-dkrMddl.j/Z0ndZ0yddl1Z1Wnek rwYnXdddZ2iZ3ddZ4ddZ5ddZ6ddZ7dd Z8d!d"Z9d#d$Z:d%dZ;Z<d&d'Z=d(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdlgEZ>GdmdCdCe?Z@GdndDdDe@ZAGdodEdEe@ZBGdpdFdFe@ZCiZDejEddZFdZGdqZHdrZIdZJdr ZKdsdhZLdtd*ZMgdudvZNdwdxZOdydzZPejQd{ZRejQd|ZSePZTd}dMZUd~d)ZVeVZWdd+ZXdd,ZYddd-ZZdd.Z[Gdd[d[Z\Gdd\d\e\Z]Gdd>d>e^Z_Gdd=d=e^Z`e`ZaGddGdGebZcGdd?d?Zddd<ZeddJZfddKZgddPZhddQZiGddde^ZjejjkZlejjmZmGddbdbZneLe^enGddcdcenZoGdddddeoZpeLeqdepe0dk r|eLe0jrepnGdd`d`enZsesZtddZuGddedeeoZveLejwevGdd]d]esZxGdd^d^epZyGdd_d_evZze4ddiddfZ{ddd9Z|dddZ}e{ejwe}dddZ~e{e^e~dddZe{e jee0dk re{e0jene4ddie4ddiddgZddZdd6ZdddiZddZee jeeejwee0dk rQee0jenddZee^eddUZiddZddZddNZejQdjZejQdjZejQdjZejQdjZejQdjZejQdjZejQdjZejQdjZejQdejejBjZejQdejZidd6dd6dd6dd6dd6jZddZddIZGddBdBe^ZddZGdd@d@e^ZGdddeZied6ed6ed6ZddZddHZddZGddAdAZidd6dd6dd6dd6dd6dd6ZddZddZddTZddOZddZedZddZeee_jZe4dd7eejZejZejZejVZVeVZWeddge_eeejejdS)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. N) get_importer)urlparse urlunparse) ImmutableSetcCs |jS)N)next)or//usr/lib/python3/dist-packages/pkg_resources.py-sr )StringIO)BytesIOcCsY|dkrt}n|dkr-|}nttt|j|d||dS)Nexec)globalsr compileopenread)fnZglobsZlocsrrr execfile2s     r)utime)mkdirrenameunlinkTF)r)isdirsplitZcpythonicCs^tstdnt|\}}|rZ|rZt| rZt|t||ndS)Nz*"os.mkdir" not supported on this platform.) WRITE_SUPPORTIOErrorrr_bypass_ensure_directoryr)namemodedirnamefilenamerrr rPs  rcKs-tj|tjtj||dS)N)rupdate _state_varsdictfromkeys)Zvartypekwrrr _declare_state\sr'cCsLi}t}x6tjD](\}}|d|||||Distribution doesn't have an "extra feature" of the given nameN)rrrrrrrr rfs r;cCs|t|darwinVersionStringrrC)ZprovidedZrequiredZreqMacZprovMacZ provDarwinZdversionZ macosversionrrr rms*$"*cCsNtjdj}|d}|j||dIs the named metadata a directory? (like ``os.path.isdir()``)Nr)rrrr metadata_isdirxsz IMetadataProvider.metadata_isdircCsdS)z?List of metadata names in the directory (like ``os.listdir()``)Nr)rrrr metadata_listdir{sz"IMetadataProvider.metadata_listdircCsdS)z=Execute the named script in the supplied namespace dictionaryNr)r namespacerrr rI~szIMetadataProvider.run_scriptN) rrrrrrrrrIrrrr r{js      c@s^eZdZdZddZddZddZdd Zd d Zd d Z dS)r|z3An object that provides access to package resourcescCsdS)zdReturn a true filesystem path for `resource_name` `manager` must be an ``IResourceManager``Nr)manager resource_namerrr get_resource_filenamesz'IResourceProvider.get_resource_filenamecCsdS)ziReturn a readable file-like object for `resource_name` `manager` must be an ``IResourceManager``Nr)rrrrr get_resource_streamsz%IResourceProvider.get_resource_streamcCsdS)zmReturn a string containing the contents of `resource_name` `manager` must be an ``IResourceManager``Nr)rrrrr get_resource_stringsz%IResourceProvider.get_resource_stringcCsdS)z,Does the package contain the named resource?Nr)rrrr has_resourceszIResourceProvider.has_resourcecCsdS)z>Is the named resource a directory? (like ``os.path.isdir()``)Nr)rrrr rUsz IResourceProvider.resource_isdircCsdS)z?List of resource names in the directory (like ``os.listdir()``)Nr)rrrr rSsz"IResourceProvider.resource_listdirN) rrrrrrrrrUrSrrrr r|s      c@seZdZdZdddZeddZeddZd d Zd d Z d dZ dddZ ddZ ddZ dddddZdddddZdddddZddZdd Zd!d"Zd#d$Zd%d&ZdS)'r^zDA collection of active distributions on sys.path (or a similar list)NcCs^g|_i|_i|_g|_|dkr<tj}nx|D]}|j|qCWdS)z?Create working set from list of path entries (default=sys.path)N)entries entry_keysby_key callbacksr?r add_entry)rrentryrrr __init__s       zWorkingSet.__init__cCsm|}yddlm}Wntk r5|SYnXy|j|Wntk rh|j|SYnX|S)z1 Prepare the master working set. r) __requires__)__main__rrrHrd_build_from_requirements)clswsrrrr _build_masters    zWorkingSet._build_mastercCs|g}t|}|j|t}x|D]}|j|q4Wx0tjD]%}||jkrU|j|qUqUW|jtjdd<|S)zQ Build a working set from a requirement spec. Rewrites sys.path. N)rhresolver]addr?rrr)rZreq_specrreqsdistsrrrrr rs   z#WorkingSet._build_from_requirementscCsT|jj|g|jj|x*t|dD]}|j||dq3WdS)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 setdefaultrrrYr)rrrrrr rs zWorkingSet.add_entrycCs|jj|j|kS)z9True if `dist` is the active distribution for its project)rrr3)rrrrr __contains__szWorkingSet.__contains__cCsG|jj|j}|dk r?||kr?t||n|SdS)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)rrr3rd)rreqrrrr rs zWorkingSet.findccsgx`|D]X}|j|}|dkrGx4|jD] }|Vq5Wq||kr||VqqWdS)aYield entry point objects from `group` matching `name` If `name` is None, yields all entry points in `group` from all distributions in the working set, otherwise only ones matching both `group` and `name` are yielded (in distribution order). N)rMvalues)rrCrrreprrr rOs    zWorkingSet.iter_entry_pointscCsQtjdj}|d}|j||d<|j|dj||dS)z?Locate distribution for `requires` and run `script_name` scriptrrrN)r?rrr2rHrI)rrequiresrrrrrr rI s    zWorkingSet.run_scriptccspi}xc|jD]X}||jkr+qnx:|j|D]+}||kr9d||<|j|Vq9q9WqWdS)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)rseenitemr3rrr __iter__s  zWorkingSet.__iter__TFcCs|r|j|j|n|dkr4|j}n|jj|g}|jj|jg}| r~|j|jkr~dS||j|j<|j|kr|j|jn|j|kr|j|jn|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. N) insert_onrlocationrrr3rr _added_new)rrrinsertrkeysZkeys2rrr r#s   zWorkingSet.addc Cst|ddd}i}i}g}xc|r|jd}||krUq.n|j|j} | dkr?|jj|j} | dks| |kr/|r/|} |dkr| dkrt|j}qtg}tg} n|j|| |} ||j<| dkr/t |q/n|j | n| |kr]t | |n|j | j |jdddd||gSYnX||jkrw|j|}|j|s   zEnvironment.addcCsW|j|}|dk r|Sx%||jD]}||kr-|Sq-W|j||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)rr3obtain)rrrWrrrrr rGs   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)rZ requirementrrrr r \s zEnvironment.obtainccs0x)|jjD]}||r|VqqWdS)z=Yield the unique project names of the available distributionsN)rr)rr3rrr rhs zEnvironment.__iter__cCs{t|tr|j|nXt|trdxF|D](}x||D]}|j|qFWq5Wntd|f|S)z2In-place addition of a distribution or environmentzCan't add %r to environment)rr`rr]r)rotherZprojectrrrr __iadd__ms zEnvironment.__iadd__cCs@|jgdddd}x||fD]}||7}q(W|S)z4Add an environment or distribution to an environmentr@Nr)r)rr newrrrr __add__yszEnvironment.__add__)rrrrrGPY_MAJORrrrrrrrr rr rrrrr r]s      c@seZdZdZdS)rgaTAn error occurred extracting a resource The following attributes are available from instances of this exception: manager The resource manager that raised this exception cache_path The base directory for resource extraction original_error The exception instance that caused extraction to fail N)rrrrrrrr rgs c@seZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ fddZ eddZddZddZdddZdS)r_z'Manage resource extraction and packagesNcCs i|_dS)N) cached_files)rrrr rszResourceManager.__init__cCst|j|S)zDoes the named resource exist?)rJr)rpackage_or_requirementrrrr rTszResourceManager.resource_existscCst|j|S)z,Is the named resource an existing directory?)rJrU)rrrrrr rUs zResourceManager.resource_isdircCst|j||S)z4Return a true filesystem path for specified resource)rJr)rrrrrr rRs z!ResourceManager.resource_filenamecCst|j||S)z9Return a readable file-like object for specified resource)rJr)rrrrrr rQs zResourceManager.resource_streamcCst|j||S)z%Return specified resource as a string)rJr)rrrrrr rPs zResourceManager.resource_stringcCst|j|S)z1List the contents of the named resource directory)rJrS)rrrrrr rSs z ResourceManager.resource_listdircCs]tjd}|jpt}td||f}||_||_||_|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: %s The Python egg cache directory is currently set to: %s Perhaps your account does not have write access to this directory? You can change the cache directory by setting the PYTHON_EGG_CACHE environment variable to point to an accessible directory. N)r?rextraction_pathr\rgr cache_pathZoriginal_error)rold_excrerrrrr extraction_errors   z ResourceManager.extraction_errorc Cso|jpt}tjj||d|}yt|Wn|jYnX|j|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) rr\rrrArr_warn_unsafe_extraction_pathr)rZ archive_namenamesZ extract_pathZ target_pathrrr get_cache_paths   zResourceManager.get_cache_pathcCswtjdkr*|jtjd r*dStj|j}|tj@sV|tj@rsd|}tj |t ndS)aN If the default extraction path is overridden and set to an insecure location, such as /tmp, it opens up an opportunity for an attacker to replace an extracted file with an unauthorized payload. Warn the user if a known insecure location is used. See Distribute #375 for more details. ntZwindirNz%s is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).) rrrenvironstatst_modeS_IWOTHS_IWGRPwarningswarn UserWarning)rrmsgrrr rs &z,ResourceManager._warn_unsafe_extraction_pathcCs@tjdkr<tj|jdBd@}tj||ndS)a4Perform any platform-specific postprocessing of `tempname` This is where Mac header rewrites should be done; other platforms don't have anything special they should do. Resource providers should call this method ONLY after successfully extracting a compressed resource. They must NOT call it on resources that are already in the filesystem. `tempname` is the current (temporary) name of the file, and `filename` is the name it will be renamed to by the caller after this routine returns. posiximiN)rrrrchmod)rZtempnamer!rrrr postprocess szResourceManager.postprocesscCs%|jrtdn||_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)rrDr)rrrrr rZs  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)rZforcerrr r[7sz!ResourceManager.cleanup_resources)rrrrrrrTrUrRrQrPrSrr staticmethodrr&rZr[rrrr r_s           cCsytjdSWntk r#YnXtjdkrCtjjdSd}dd|fd|fd|fdd|fg}x|D]\}}d }xn|D]5}|tjkrtjj|tj|}qPqW|rtjj||}ntjj|d SqWtddS)a Determine the default cache location This returns the ``PYTHON_EGG_CACHE`` environment variable, if set. Otherwise, on Windows, it returns a "Python-Eggs" subdirectory of the "Application Data" directory. On all other systems, it's "~/.python-eggs". ZPYTHON_EGG_CACHErz~/.python-eggszApplication DataAPPDATAN USERPROFILE HOMEDRIVEHOMEPATHHOMEWINDIRrz Python-Eggsz3Please set the PYTHON_EGG_CACHE enviroment variablezAPPDATA)r.N)r))r*r+)r+zHOME)r/N)r-)rrrrr expanduserrA RuntimeError)Zapp_dataZ app_homesrZsubdirr r3rrr r\Ds0     cCstjdd|S)zConvert an arbitrary string to a standard distribution name Any runs of non-alphanumeric/. characters are replaced with a single '-'. z[^A-Za-z0-9.]+-)resub)rrrr rjmscCs%|jdd}tjdd|S)zConvert an arbitrary string to a standard version string Spaces become dots, and all other non-alphanumeric characters become dashes, with runs of multiple dashes condensed to a single dash. rr:z[^A-Za-z0-9.]+r2)rr3r4)rrrr rkuscCstjdd|jS)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)r3r4r)extrarrr rpscCs|jddS)z|Convert a project or version name to its filename-escaped form Any '-' characters are currently replaced with '_'. r2r)r)rrrr rqsc@sIeZdZiddd6ddd6ddd6ddd 6ejd 6ejd 6ejd 6Zed dZ e ddZ eddZ eddZ eddZeddZeddZedddZeddZd ekr!eZned!d"Zed#d$ZdS)%MarkerEvaluationcCstjS)N)rrrrrr r szMarkerEvaluation.Zos_namecCstjS)N)r?r@rrrr r sZ sys_platformcCstjjdS)Nr)r?rrrrrr r sZpython_full_versioncCsdtjdtjdfS)Nz%s.%srr)r? version_inforrrr r sZpython_versionZplatform_versionZplatform_machinepython_implementationc CsAy|j|Wn)tk r<|jtjdSYnXdS)z{ Validate text as a PEP 426 environment marker; return an exception if invalid or False otherwise. rF)rs SyntaxErrornormalize_exceptionr?r)rtextrrr is_invalid_markers  z"MarkerEvaluation.is_invalid_markercCsEidd6dd6}d|_d|_|j|j|j|_|S)z Given a SyntaxError from a marker evaluation, normalize the error message: - Remove indications of filename and line number. - Replace platform-specific error messages with standard error messages. zinvalid syntaxzunexpected EOF while parsingzparenthesis is never closedN)r!linenorr#)excZsubsrrr r:s   z$MarkerEvaluation.normalize_exceptioncs;tjtjfddtdtdDS)Ncs#g|]}j|qSr) interpret).0i)rnodelistrr s z-MarkerEvaluation.and_test..rr;) functoolsreduceoperatorand_rangelen)rrBr)rrBr and_testszMarkerEvaluation.and_testcs;tjtjfddtdtdDS)Ncs#g|]}j|qSr)r?)r@rA)rrBrr rCs z)MarkerEvaluation.test..rr;)rDrErFor_rHrI)rrBr)rrBr testszMarkerEvaluation.testcCsd|dd}|tjkrT|ddtjkrCtdn|j|dStddS)Nrrr;zEmpty parenthesesz5Language feature not supported in environment markers)tokenLPARRPARr9r?)rrBtrrr atoms zMarkerEvaluation.atomc Cst|dkr!tdn|dd}|d}|dtjkrt|ddkr|dkrwd}qd }qny|j|}Wn(tk rtt|d YnX||j|d|j|dS) Nrz5Chained comparison not allowed in environment markersr;rrrnotznot inzis notz, operator not allowed in environment markers)rIr9rMNAMEget_oprrevaluate)rrBcompZcoprrr comparisons     zMarkerEvaluation.comparisoncCsi|jtj6|jtj6|jtj6|jtj6ddd6ddd6tjd6tjd6}ttdr|j|tj .znot incSs ||kS)Nr)rXrYrrr r sinz==z!=or_test) rLsymbolrJrQrWrFeqnerr[)ropZopsrrr rTs        zMarkerEvaluation.get_opNcCs#|jtj|jddS)ar Evaluate a PEP 426 environment marker on CPython 2.4+. Return a boolean indicating the marker result in this environment. Raise SyntaxError if marker is invalid. This implementation uses the 'parser' module, which is not implemented on Jython and has been superseded by the 'ast' module in Python 2.6 and later. r)r?parserexprZtotuple)rr;r5rrr rss z MarkerEvaluation.evaluate_markerc Csddl}|j}x9|jD]+}|jdd}|j|||sz"NullProvider.get_resource_filenamecCst|j||S)N)r r)rrrrrr rAsz NullProvider.get_resource_streamcCs|j|j|j|S)N)_getrlrk)rrrrrr rDsz NullProvider.get_resource_stringcCs|j|j|j|S)N)_hasrlrk)rrrrr rGszNullProvider.has_resourcecCs%|jo$|j|j|j|S)N)egg_infornrl)rrrrr rJszNullProvider.has_metadatarcCs)|js dS|j|j|j|S)Nr)rormrl)rrrrr rNs zNullProvider.get_metadatacCs2|js dS|j|j|j|jdS)Nrzutf-8)rormrldecode)rrrrr rSs cCst|j|S)N)rnr)rrrrr rXszNullProvider.get_metadata_linescCs|j|j|j|S)N)_isdirrlrk)rrrrr rU[szNullProvider.resource_isdircCs%|jo$|j|j|j|S)N)rorqrl)rrrrr r^szNullProvider.metadata_isdircCs|j|j|j|S)N)_listdirrlrk)rrrrr rSaszNullProvider.resource_listdircCs)|jr%|j|j|j|SgS)N)rorrrl)rrrrr rds zNullProvider.metadata_listdircCsd|}|j|s,td|n|j|jdd}|jdd}|j|j|}||dcCsdS)Nrr)rrrrr r scCsgS)Nr)rrrrr r sNcCsdS)Nr)rrrr rszEmptyProvider.__init__) rrrrrqrnrmrrrkrrrrr rs   c Cst}tj|}zYxR|jD]D}|jdtj}|j|||<||dk s(tq(WWd|j X|S)af This builds a similar dictionary to the zipimport directory caches. However instead of tuples, ZipInfo objects are stored. The translation of the tuple is as follows: * [0] - zipinfo.filename on stock pythons this needs "/" --> os.sep on pypy it is the same (one reason why distribute did work in some cases on pypy and win32). * [1] - zipinfo.compress_type * [2] - zipinfo.compress_size * [3] - zipinfo.file_size * [4] - len(utf-8 encoding of filename) if zipinfo & 0x800 len(ascii encoding of filename) otherwise * [5] - (zipinfo.date_time[0] - 1980) << 9 | zipinfo.date_time[1] << 5 | zipinfo.date_time[2] * [6] - (zipinfo.date_time[3] - 1980) << 11 | zipinfo.date_time[4] << 5 | (zipinfo.date_time[5] // 2) * [7] - zipinfo.CRC rxN) r$zipfileZZipFileZnamelistrrsepZgetinfoAssertionErrorr)rzipinfoZzfileZzitemZzpathrrr build_zipmanifests  rc@seZdZdZdZddZddZddZd d Ze d d Z d dZ ddZ ddZ ddZddZddZddZddZddZdS)rz"Resource support for zips and eggsNcCs?tj||t|jj|_|jjtj|_dS)N) rrrrarchiverrrzip_pre)rrrrr rszZipProvider.__init__cCsF|j|jr)|t|jdStd||jfdS)Nz%s is not a subpath of %s)rrrIr)rfspathrrr _zipinfo_nameszZipProvider._zipinfo_namecCsj|j|}|j|jtjrM|t|jddjtjStd||jfdS)Nrz%s is not a subpath of %s)rrrrrrIrr)rzip_pathrrrr _parts s  'zZipProvider._partscCs|jstdn|j|}|j}dj|j||kr~x*|D]}|j||j|qXWn|j||S)Nz5resource_filename() only supported for .egg, not .ziprx)r{rw_resource_to_zip_get_eager_resourcesrAr_extract_resource _eager_to_zip)rrrreagersrrrr rs     z!ZipProvider.get_resource_filenamecCs/|j}|jd}tj|}||fS)Nrrr)rrr)Z file_size date_timetimeZmktime)Zzip_statsizer timestamprrr _get_date_and_size"s  zZipProvider._get_date_and_sizec Cs||jkr^x9|j|D]'}|j|tjj||}q#Wtjj|S|j|j|\}}tst dny)|j |j |j |}|j ||r|Stddtjj|\}} tj||jj|tj|t| ||f|j| |yt| |Wnmtjk rtjj|r|j ||r|Stjdkrt|t| ||SnYnXWntjk r|jYnX|S)Nz>"os.rename" and "os.unlink" are not supported on this platformz .$extractdirr)_indexrrrrAr rrrrrr{r _is_current_mkstempwriterrzrrr&rerrorisfilerrr) rrrrlastrrZ real_pathZoutfZtmpnamrrr r*s@$    zZipProvider._extract_resourcec Cs|j|j|\}}tjj|s2dStj|}|j|ks_|j|krcdS|jj |}t |d}|j }|j ||kS)zK Return True if the file_path is current for this zip_path Fr) rrrrrrst_sizest_mtimerrzrrr) rZ file_pathrrrrZ zip_contentsfZ file_contentsrrr r[s  zZipProvider._is_currentcCsa|jdkrZg}x6dD].}|j|r|j|j|qqW||_n|jS)Nnative_libs.txteager_resources.txt)rr)rrrr)rrrrrr rls  z ZipProvider._get_eager_resourcesc Csy |jSWntk ri}x|jD]y}|jtj}x^|rtjj|dd}||kr||j|dPqF|jg||=?|==|!=)\s*((\w|[-.])+)z\s*,z\s*\[z\s*\]z \w+(\.\w+)*$zL(?P[^-]+)( -(?P[^-]+) (-py(?P[^-]+) (-(?P.+))? )? )?z(\d+ | [a-z]+ | \.| -)cZpreZpreviewzfinal-r2rc@Zdevccs{xotj|D]^}t||}| s|dkr>qn|dddkre|jdVqd|VqWdVdS)Nr:r 0123456789r*z*final) component_rerrzfill)ripartrrr _parse_version_partss rcCsg}xt|jD]}|jdr|dkrdx'|r`|ddkr`|jq=Wnx'|r|ddkr|jqgWn|j|qWt|S)aConvert a version string to a chronologically-sortable key This is a rough cross between distutils' StrictVersion and LooseVersion; if you give it versions that would work with StrictVersion, then it behaves the same; otherwise it acts like a slightly-smarter LooseVersion. It is *possible* to create pathological version coding schemes that will fool this parser, but they should be very rare in practice. The returned value will be a tuple of strings. Numeric portions of the version are padded to 8 digits so they will compare numerically, but without relying on how numbers compare relative to strings. Dots are dropped, but dashes are retained. Trailing zeros between alpha segments or dashes are suppressed, so that e.g. "2.4.0" is considered the same as "2.4". Alphanumeric parts are lower-cased. The algorithm assumes that strings like "-" and any alpha string that alphabetically follows "final" represents a "patch level". So, "2.4-1" is assumed to be a branch or patch of "2.4", and therefore "2.4.1" is considered newer than "2.4-1", which in turn is newer than "2.4". Strings like "a", "b", "c", "alpha", "beta", "candidate" and so on (that come before "final" alphabetically) are assumed to be pre-release versions, so that the version "2.4" is considered newer than "2.4a1". Finally, to handle miscellaneous cases, the strings "pre", "preview", and "rc" are treated as if they were "c", i.e. as though they were release candidates, and therefore are not as new as a version string that does not contain them, and "dev" is replaced with an '@' so that it sorts lower than than any other pre-release tag. rz*finalrz*final-Z00000000rr)rrrrrtuple)rirrrrr ris c@seZdZdZffdddZddZddZd ddd d Zddd d Ze dddZ e dddZ e dddZ dS)rbz3Object representing an advertised importable objectNcCsnt|std|n||_||_t||_tjddj|j |_ ||_ dS)NzInvalid module namezx[%s],) MODULErDr module_namerattrsrarrArr)rrrrrrrrr rs   "zEntryPoint.__init__cCsfd|j|jf}|jr<|ddj|j7}n|jrb|ddj|j7}n|S)Nz%s = %s:r:z [%s]r)rrrrAr)rrirrr __str__s   zEntryPoint.__str__cCsdt|S)NzEntryPoint.parse(%r))r)rrrr r#szEntryPoint.__repr__Tc Cs|r|j||nt|jttdg}xO|jD]D}yt||}WqDtk rtd||fYqDXqDW|S)Nrz%r has no %r attribute)rHrrrrrrr)rrHrrrattrrrr load&s! zEntryPoint.loadcCs]|jr%|j r%td|ntttjtj|jj|j||dS)Nz&Can't require() without a distribution) rrrfrrrWrrr)rrrrrr rH0s zEntryPoint.requirecCsyf}}|jdd\}}d|krz|jdd\}}tjd|}|jrntn|j}nd|kr|jdd\}}t|jstn|jjd}nWn!tk rtd|Yn#X||j|j|||SdS) aParse a single entry point from string `src` Entry point syntax follows the form:: name = some.module:some.attr [extra1,extra2] The entry name and module name are required, but the ``:attrs`` and ``[extras]`` parts are optional =r[zx[rr:z9EntryPoint must be in 'name=module:attrs [extras]' formatN) rrarspecsrDrrrr)rsrcrrrrvaluerrrr r6s&        zEntryPoint.parsecCst|std|ni}xZt|D]L}|j||}|j|krptd||jn|||jd?Z&e d@dAZ'dS)Br`z5Wrap an actual or potential sys.path entry w/metadatazPKG-INFONcCsjt|p d|_|dk r3t||_n||_||_||_||_|p`t|_ dS)NZUnknown) rjrrk_versionrr@rrr _provider)rrrrrrr@rrrr rs     zDistribution.__init__c Ksdgd\}}}}tjj|\}} | jtkrt|} | r|| jdddd\}}}}nt| j}n|||d|d|d|d ||S) NrrverZpyverrErrrr@)rrsplitextr_distributionImplEGG_NAMErC) rrr~rr&rrrr@extr>rrr rs !zDistribution.from_locationcCs7t|df|j|jt|j|j|jfS)Nparsed_version)rrr3rrrr@)rrrr r s  zDistribution.cCs t|jS)N)hashhashcmp)rrrr __hash__szDistribution.__hash__cCs|j|jkS)N)r)rr rrr __lt__szDistribution.__lt__cCs|j|jkS)N)r)rr rrr __le__szDistribution.__le__cCs|j|jkS)N)r)rr rrr __gt__szDistribution.__gt__cCs|j|jkS)N)r)rr rrr __ge__szDistribution.__ge__cCs&t||jsdS|j|jkS)NF)rrr)rr rrr __eq__szDistribution.__eq__cCs ||k S)Nr)rr rrr __ne__szDistribution.__ne__c Cs>y |jSWn,tk r9|jj|_}|SYnXdS)N)_keyrrr)rr3rrr r3s   zDistribution.keyc Cs>y |jSWn,tk r9t|j|_}|SYnXdS)N)Z_parsed_versionrrir)rZpvrrr rs   zDistribution.parsed_versionc Csy |jSWntk rxq|j|jD]G}|jjdr.t|jdddj|_|jSq.Wt d|j|YnXdS)Nzversion:rrz(Missing 'Version:' header and/or %s file) rr _get_metadataPKG_INFOrrrkrrrD)rrrrr rs  % zDistribution.versionc Csy |jSWntk rigd6}|_xdD]}xt|j|D]\}}|rd|kr|jdd\}}t|rg}qt|sg}qnt|pd}n|j|gj t |qRWq6W|SYnXdS)N requires.txt depends.txtrr)r r ) Z_Distribution__dep_maprrorrrrrsrprrrh)rdmrr5rZmarkerrrr _dep_maps    "     'zDistribution._dep_mapc Cs|j}g}|j|jdfxT|D]L}y|j|t|Wq/tk rztd||fYq/Xq/W|S)z@List of Requirements needed for this distro if `extras` are usedNz%s has no such extra feature %r)r rrrprrf)rrr Zdepsrrrr rs   zDistribution.requiresccs5|j|r1x|j|D] }|VqWndS)N)rr)rrrrrr rszDistribution._get_metadatacCs~|dkrtj}n|j||tjkrzt|jx6|jdD]"}|tjkrQt|qQqQWndS)z>Ensure distribution is importable on `path` (default=sys.path)Nznamespace_packages.txt)r?rrrrrrrV)rrpkgrrr activate s   zDistribution.activatecCsOdt|jt|j|jp'tf}|jrK|d|j7}n|S)z@Return what this distribution's standard .egg filename should bez %s-%s-py%sr2)rqrrrrr@)rr!rrr r{ s  zDistribution.egg_namecCs(|jrd||jfSt|SdS)Nz%s (%s))rr)rrrr r s zDistribution.__repr__c CsNyt|dd}Wntk r0d}YnX|p:d}d|j|fS)Nrz[unknown version]z%s %s)rrDr)rrrrr r s   zDistribution.__str__cCs.|jdrt|nt|j|S)zADelegate all unrecognized public attributes to .metadata providerr)rrrr)rrrrr __getattr__% szDistribution.__getattr__cKs(|jt|tjj|||S)N)rrrrr~)rr!rr&rrr r+ szDistribution.from_filenamecCstjd|j|jfS)z?Return a ``Requirement`` that matches this distribution exactlyz%s==%s)rarrr)rrrr r2 szDistribution.as_requirementcCsD|j||}|dkr:td||ffn|jS)z=Return the `name` entry point of `group` or raise ImportErrorNzEntry point %r not found)rNrr)rrCrrrrr rL6 s zDistribution.load_entry_pointc Csdy |j}Wn4tk rCtj|jd|}|_YnX|dk r`|j|iS|S)z=Return the entry point map for `group`, or the full entry mapzentry_points.txtN)Z_ep_maprrbrrr)rrCZep_maprrr rM= s  ! zDistribution.get_entry_mapcCs|j|j|S)z.r)rrrrr enumeraterrvr?check_version_conflictrrindexrD) rrlocZnlocZbdirZnpathrrZnprrr rM s6       zDistribution.insert_oncCs|jdkrdStj|jd}t|j}x|jdD]}|tjksJ||ksJ|tkr}qJn|dkrqJnt tj|dd}|rt|j |sJ|j |jrqJnt d|||jfqJWdS) N setuptoolsznamespace_packages.txtz top_level.txt pkg_resourcessiterjzIModule %s was already imported from %s, but %s is being added to sys.path)rrr) r3r$r%rrurr?rrrr issue_warning)rZnsprmodnamerrrr rt s"  z#Distribution.check_version_conflictc Cs<y |jWn*tk r7tdt|dSYnXdS)NzUnbuilt egg for FT)rrDrr)rrrr r  s    zDistribution.has_versioncKsMx*d D]"}|j|t||dqW|jd|j|j|S) z@Copy this distribution, substituting in any changed keyword argsrrrr@rrNr)z project_namezversionz py_versionzplatformzlocationz precedence)rrrr)rr&rrrr clone s   zDistribution.clonecCsdd|jDS)NcSsg|]}|r|qSrr)r@Zdeprrr rC s z'Distribution.extras..)r )rrrr r szDistribution.extras)(rrrrrrrvrrrpropertyrrrrrrrrr3rrr rrrr{rrrrrrLrMrNrrr rrrrrr r`sL                  '   c@sgeZdZdZdZejdZeddZ eddZ dd Z d d Z d S) DistInfoDistributionzGWrap an actual or potential sys.path entry w/metadata, .dist-info styleZMETADATAz([\(,])\s*(\d.*?)\s*([,\)])c Cs\y |jSWnJtk rWddlm}|j|j|j|_|jSYnXdS)zParse and cache metadatar)ParserN)Z _pkg_inforZ email.parserrZparsestrrr)rrrrr _parsed_pkg_info s   !z%DistInfoDistribution._parsed_pkg_infoc Cs:y |jSWn(tk r5|j|_|jSYnXdS)N)_DistInfoDistribution__dep_mapr_compute_dependencies)rrrr r  s   zDistInfoDistribution._dep_mapcCsy|jdddg}|dj}|dj}tj|jd|}|jddjdd}||fS)zConvert 'Foobar (1); baz' to ('Foobar ==1', 'baz') Split environment marker, add == prefix to version specifiers as necessary, and remove parenthesis. ;rrrz\1==\2\3())rrr3r4EQEQr)rZ requires_distrdistversmarkrrr _preparse_requirement s z*DistInfoDistribution._preparse_requirementc sddlm}igd6}|_gxc|jjdpBgD]I}|j|\}}tt|}|||_j |qCWfdd}t |d}|dj |xR|jjdpgD]8} t | j } tt || ||| .reqs_for_extrazProvides-Extra)rbrrrZget_allr'rrhr(r frozensetrrprr) rZcompile_markerr rr%r&rr)Zcommonr5r)rr r  s$z*DistInfoDistribution._compute_dependenciesN) rrrrrr3rr$rrr r'r rrrr r s   rz.eggz .egg-infoz .dist-infoc Os|d}t}y-x&tj|j|kr:|d7}qWWntk rPYnXddlm}|d|d||dS)Nrr)r! stacklevel)rr?rrrDr r!)r8r&levelr*r!rrr r s  rc#stt|fdd}xD]}t|}|sUtd|n|jd}|j}g}t||}|r|j}|tt||d d\}}}n|tt ||d d\}}}dd |D}t |||Vq+Wd S) zYield ``Requirement`` objects for each specification in `strs` `strs` must be an instance of ``basestring``, or a (possibly-nested) iterable thereof. csLg}x|||st||rayt}d}Wqatk r]tdYqaXn|||}|std|d|d||dn|j|j||j}t||}|r|j}q |||s td|d||dq q W|||}|r?|j}n|||fS)Nrz+\ must not appear on the last nonblank linez Expected z inatzExpected ',' or end-of-list in)CONTINUEr StopIterationrDrrCendCOMMA)ZITEMZ TERMINATORrrgroupsZ item_namer(r>)rrr scan_list s0   * #z%parse_requirements..scan_listzMissing distribution specrz 'extra' namer;z version speccSs(g|]\}}|t|fqSr)rk)r@r_r0rrr rC. s z&parse_requirements..N)r)rr;) iterrnDISTROrDrCr0OBRACKETCBRACKETVERSIONLINE_ENDra)rr3rr>rrrrr)rr rh s"!    $$cCsAdd|D}|jdd|D|ddd.cSsg|]\}}|qSrr)r@Zhcdrrr rC5 s rr)r)rZtmprrr r2 s rc@sjeZdZddZddZddZddZd d Zd d Ze d dZ dS)racCs|t||_}||j|_|_dd|D}|jdd|D|_|ttt ||_ |_ |jtdd|Dt |j f|_ t|j |_dS)z>DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!cSs2g|](\}}t|t|||fqSr)ri state_machine)r@r_r,rrr rC= s z(Requirement.__init__..cSs(g|]\}}}}||fqSrr)r@rtransr_rrrr rC? s cSs(g|]\}}}}||fqSrr)r@rr<r_rrrr rCB s N)rjZ unsafe_namerrr3rrrrrprrr*hashCmpr_Requirement__hash)rrrrrrrr r9 s "zRequirement.__init__cCsXdjdd|jD}dj|j}|rDd|}nd|j||fS)NrcSsg|]}dj|qS)r)rA)r@rirrr rCH s z'Requirement.__str__..z[%s]z%s%s%s)rArrr)rrrrrr rG s  zRequirement.__str__cCst|to|j|jkS)N)rrar=)rr rrr rM szRequirement.__eq__c Cst|tr=|j|jkr%dS|jr[|j}q[nt|tr[t|}nd}dd}x|jD]{\}}}}||||}|dkrdS|dkrdS|dkrd}qw|dks|dkrwd}qwqwW|dkr d}n|S) NFcSs||k||kS)Nr)abrrr r W sz*Requirement.__contains__..FTT+r2)rr`r3rrrri) rrrZcomparerr<r_ractionrrr rP s,        zRequirement.__contains__cCs|jS)N)r>)rrrr rd szRequirement.__hash__cCsdt|S)NzRequirement.parse(%r))r)rrrr rg szRequirement.__repr__cCsWtt|}|rDt|dkr2|dStd|ntd|dS)NrrzExpected only one requirementzNo requirements found)rrhrIrD)rirrrr ri s zRequirement.parseN) rrrrrrrrrr'rrrrr ra8 s       z--TzT+Fz>=zT..z==zF++z!=cCs@t|ts9Gddd|t}|jddS|jS)z&Get an mro for a type or classic classc@seZdZdS)z_get_mro..clsN)rrrrrrr r s rrN)rtypeobject__mro__)rrrr _get_mro} srJcCsAx:tt|dt|D]}||kr||SqWdS)z2Return an adapter factory for `ob` from `registry`rN)rJrrG)registryr4rPrrr r s% rcCs8tjj|}tjj|s4tj|ndS)z1Ensure that the parent directory of `path` existsN)rrr rmakedirs)rr rrr rt sccsd}g}xt|D]|}|jdr|jdrv|sI|rW||fVn|ddj}g}qtd|q|j|qW||fVdS)arSplit a string or iterable thereof into (section,content) pairs Each ``section`` is a stripped version of the section header ("[section]") and each ``content`` is a list of stripped lines excluding blank lines and comment-only lines. If there are any such lines before the first section header, they're returned in a first ``section`` of ``None``. Nr]rzInvalid section headingr)rnrr}rrDr)riZsectionZcontentrrrr ro s  c OsDddlm}tj}ztt_|||SWd|t_XdS)Nr)mkstemp)ZtempfilerNrros_open)r8r&rNZold_openrrr r s   rcCs@x9ttD]+}|jds tt|||r9r.r5r8r1r6r7rVERBOSE IGNORECASErrrrrrirbrr`rrrrhrrar;rJrrtrorrPrQrrrWrHrOrrXrrrrrrrrr s                      '                               1    Y )    c    !  (           , )h !?   > :