0{Ym@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)or4/tmp/pip-ok8sy_ze-build/pip/_vendor/pkg_resources.py-sr )StringIO)BytesIOcCsY|dkrt}n|dkr-|}nttt|j|d||dS)Nexec)globalsr compileopenread)fnglobslocsrrr 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)vartypekwrrr _declare_state\sr*cCsLi}t}x6tjD](\}}|d|||||Distribution doesn't have an "extra feature" of the given nameN)rrrrrrrr rks r@cCs|t|zmacosx- _zmacosx-%d.%d-%sr) sysconfigrq ImportErrordistutils.utilrDrE startswithrGrunamereplaceintrrI)rqrJrrrrr rAs    rAzmacosx-(\d+)\.(\d+)-(.*)zdarwin-(\d+)\.(\d+)\.(\d+)-(.*)cCsO|dks$|dks$||kr(dStj|}|rKtj|}|stj|}|rt|jd}d|jd|jdf}|dkr|dks|dkr|d krdSnd S|jd|jdks|jd |jd krd St|jdt|jdkrGd 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.%sr@z10.3z10.4Fr)rBrCdarwinVersionStringrrH)providedrequiredreqMacprovMac provDarwindversion macosversionrrr rrs*$"*cCsNtjdj}|d}|j||dIs the named metadata a directory? (like ``os.path.isdir()``)Nr)r rrr metadata_isdirxsz IMetadataProvider.metadata_isdircCsdS)z?List of metadata names in the directory (like ``os.listdir()``)Nr)r rrr metadata_listdir{sz"IMetadataProvider.metadata_listdircCsdS)z=Execute the named script in the supplied namespace dictionaryNr)r namespacerrr rN~szIMetadataProvider.run_scriptN) rrrrrrrrrNrrrr rjs      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``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 rZsz IResourceProvider.resource_isdircCsdS)z?List of resource names in the directory (like ``os.listdir()``)Nr)rrrr rXsz"IResourceProvider.resource_listdirN) rrrrrrrrrZrXrrrr rs      c@seZdZdZdddZeddZeddZd d Zd d Z d dZ dddZ ddZ ddZ dddddZdddddZdddddZddZdd Zd!d"Zd#d$Zd%d&ZdS)'rczDA 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 callbacksrDr 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__rrrMri_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)rmresolverbaddrDrrr)rreq_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 setdefaultrrr^r)rrrrrr rs zWorkingSet.add_entrycCs|jj|j|kS)z9True if `dist` is the active distribution for its project)rrr8)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)rrr8ri)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)rRvalues)rrHr rreprrr rTs    zWorkingSet.iter_entry_pointscCsQtjdj}|d}|j||d<|j|dj||dS)z?Locate distribution for `requires` and run `script_name` scriptrrrN)rDrrr7rMrN)rrequiresrrr rrr rN 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)rseenitemr8rrr __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_onrlocationrrr8rr _added_new)rrrinsertrkeyskeys2rrr 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)rr8obtain)rrr\rrrrr r Gs   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 requirementrrrr r1\s zEnvironment.obtainccs0x)|jjD]}||r|VqqWdS)z=Yield the unique project names of the available distributionsN)r&r)rr8rrr 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)rrerrbr)rotherprojectrrrr __iadd__ms zEnvironment.__iadd__cCs@|jgdddd}x||fD]}||7}q(W|S)z4Add an environment or distribution to an environmentrENr')r)rr3newr rrr __add__yszEnvironment.__add__)rrrrrLPY_MAJORrr+r,r(r/rr r1rr5r7rrrr rbs      c@seZdZdZdS)rlaTAn 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 rls c@seZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ fddZ eddZddZddZdddZdS)rdz'Manage resource extraction and packagesNcCs i|_dS)N) cached_files)rrrr rszResourceManager.__init__cCst|j|S)zDoes the named resource exist?)rOr)rpackage_or_requirementrrrr rYszResourceManager.resource_existscCst|j|S)z,Is the named resource an existing directory?)rOrZ)rr:rrrr rZs zResourceManager.resource_isdircCst|j||S)z4Return a true filesystem path for specified resource)rOr)rr:rrrr rWs z!ResourceManager.resource_filenamecCst|j||S)z9Return a readable file-like object for specified resource)rOr)rr:rrrr rVs zResourceManager.resource_streamcCst|j||S)z%Return specified resource as a string)rOr)rr:rrrr rUs zResourceManager.resource_stringcCst|j|S)z1List the contents of the named resource directory)rOrX)rr:rrrr rXs 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)rDrextraction_pathrarlr cache_pathoriginal_error)rold_excr<errrrr 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) r;rarrrFrr@_warn_unsafe_extraction_pathr9)r archive_namenames extract_path 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. ntwindirNz%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).) rr renvironstatst_modeS_IWOTHS_IWGRPwarningswarn UserWarning)rr!msgrrr rAs &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)rr rJrKchmod)rtempnamer#r!rrr 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)r9rIr;)rrrrr r_s  z#ResourceManager.set_extraction_pathFcCsdS)aB Delete all extracted resource files and directories, returning a list of the file and directory names that could not be successfully removed. This function does not have any concurrency protection, so it should generally only be called when the extraction path is a temporary directory exclusive to a single process. This method is not automatically called; you must call it explicitly or register it as an ``atexit`` function if you wish to ensure cleanup of a temporary directory used for extractions. Nr)rforcerrr r`7sz!ResourceManager.cleanup_resources)rrrrr;rrYrZrWrVrUrXr@rF staticmethodrArUr_r`rrrr rds           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". PYTHON_EGG_CACHErGz~/.python-eggszApplication DataAPPDATAN USERPROFILE HOMEDRIVEHOMEPATHHOMEWINDIRrz Python-Eggsz3Please set the PYTHON_EGG_CACHE enviroment variablezAPPDATA)r_N)z USERPROFILE)z HOMEDRIVEHOMEPATH)r`zHOME)raN)zWINDIR)rrIrr r expanduserrF RuntimeError)app_data app_homesrsubdirr"r8rrr raDs0     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)r rrr romscCs%|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.]+rg)rrhri)rrrr rpuscCstjdd|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)rhrir-)extrarrr ruscCs|jddS)z|Convert a project or version name to its filename-escaped form Any '-' characters are currently replaced with '_'. rgr)r)r rrr rvsc@sIeZdZiddd6ddd6ddd6ddd 6ejd 6ejd 6ejd 6Zed dZ e ddZ eddZ eddZ eddZeddZeddZedddZeddZd ekr!eZned!d"Zed#d$ZdS)%MarkerEvaluationcCstjS)N)rr rrrr r szMarkerEvaluation.os_namecCstjS)N)rDrErrrr r s sys_platformcCstjjdS)Nr)rDrrrrrr r spython_full_versioncCsdtjdtjdfS)Nz%s.%srr)rD version_inforrrr r spython_versionplatform_versionplatform_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)rx SyntaxErrornormalize_exceptionrDr)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#linenorrQ)excsubsrrr rus   z$MarkerEvaluation.normalize_exceptioncs;tjtjfddtdtdDS)Ncs#g|]}j|qSr) interpret).0i)rnodelistrr s z-MarkerEvaluation.and_test..rr@) functoolsreduceoperatorand_rangelen)rr~r)rr~r and_testszMarkerEvaluation.and_testcs;tjtjfddtdtdDS)Ncs#g|]}j|qSr)r{)r|r})rr~rr rs z)MarkerEvaluation.test..rr@)rrror_rr)rr~r)rr~r testszMarkerEvaluation.testcCsd|dd}|tjkrT|ddtjkrCtdn|j|dStddS)Nrrr@zEmpty parenthesesz5Language feature not supported in environment markers)tokenLPARRPARrtr{)rr~trrr 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)rrtrNAMEget_oprrevaluate)rr~compcoprrr comparisons     zMarkerEvaluation.comparisoncCsi|jtj6|jtj6|jtj6|jtj6ddd6ddd6tjd6tjd6}ttdr|j|tj .znot incSs ||kS)Nr)rrrrr r sinz==z!=or_test) rsymbolrrrreqnerr)ropopsrrr rs        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{parserexprtotuple)rrvrjrrr rxs z MarkerEvaluation.evaluate_markerc Csddlm}|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)_getrr)rrrrrr rDsz NullProvider.get_resource_stringcCs|j|j|j|S)N)_hasrr)rrrrr rGszNullProvider.has_resourcecCs%|jo$|j|j|j|S)N)egg_inforr)rr rrr rJszNullProvider.has_metadatarcCs)|js dS|j|j|j|S)Nr)rrr)rr rrr rNs zNullProvider.get_metadatacCs2|js dS|j|j|j|jdS)Nrzutf-8)rrrdecode)rr rrr rSs cCst|j|S)N)rsr)rr rrr rXszNullProvider.get_metadata_linescCs|j|j|j|S)N)_isdirrr)rrrrr rZ[szNullProvider.resource_isdircCs%|jo$|j|j|j|S)N)rrr)rr rrr r^szNullProvider.metadata_isdircCs|j|j|j|S)N)_listdirrr)rrrrr rXaszNullProvider.resource_listdircCs)|jr%|j|j|j|SgS)N)rrr)rr rrr 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__) rrrrrrrrrrrrrr 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 rN) r&zipfileZipFilenamelistrrsepgetinfoAssertionErrorr)rzipinfozfilezitemzpathrrr 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)rrrr)rfspathrrr _zipinfo_nameszZipProvider._zipinfo_namecCsj|j|}|j|jtjrM|t|jddjtjStd||jfdS)Nrz%s is not a subpath of %s)rrrrrrrr)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 .zipr)rr_resource_to_zip_get_eager_resourcesrFr_extract_resource _eager_to_zip)rrrreagersr rrr rs     z!ZipProvider.get_resource_filenamecCs/|j}|jd}tj|}||fS)Nrrr)rrr) file_size date_timetimemktime)zip_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 .$extractdirrG)_indexrrrrFr"rrrrrFrr _is_current_mkstempwriterrrrrUrerrorisfiler rr@) rrrr lastrr real_pathoutftmpnamrrr 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) rrrrrrJst_sizest_mtimerrrrr) r file_pathrrrrJ zip_contentsf file_contentsrrr r[s  zZipProvider._is_currentcCsa|jdkrZg}x6dD].}|j|r|j|j|qqW||_n|jS)Nnative_libs.txteager_resources.txt)rr)rrr r)rrr rrr 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]+ | \.| -)cprepreviewzfinal-rgrc@devccs{xotj|D]^}t||}| s|dkr>qn|dddkre|jdVqd|VqWdVdS)Nr?r 0123456789r*z*final) component_rerrzfill)rpartrrr _parse_version_partss rDcCsg}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. r@z*finalrz*final-00000000rr)rDr-rrrtuple)rrrCrrr rns c@seZdZdZffdddZddZddZd ddd d Zddd d Ze dddZ e dddZ e dddZ dS)rgz3Object representing an advertised importable objectNcCsnt|std|n||_||_t||_tjddj|j |_ ||_ dS)NzInvalid module namezx[%s],) MODULErIr module_namerFattrsrfrrFr r)rr rIrJr rrrr rs   "zEntryPoint.__init__cCsfd|j|jf}|jr<|ddj|j7}n|jrb|ddj|j7}n|S)Nz%s = %s:r?z [%s]rG)r rIrJrFr )rrrrr __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)rMrrIrrJrrr)rrMr rrattrrrr load&s! zEntryPoint.loadcCs]|jr%|j r%td|ntttjtj|jj|j||dS)Nz&Can't require() without a distribution) r rrkrrr\rrr)rr rrrr rM0s 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[rKr?z9EntryPoint must be in 'name=module:attrs [extras]' formatN) rrfrspecsrIr rHrr)rsrcrrJr r valuerrrr r6s&        zEntryPoint.parsecCst|std|ni}xZt|D]L}|j||}|j|krptd||jn|||jd?Z&e d@dAZ'dS)Brez5Wrap an actual or potential sys.path entry w/metadatazPKG-INFONcCsjt|p d|_|dk r3t||_n||_||_||_||_|p`t|_ dS)NUnknown) rorrp_versionr*rErrr _provider)rrrrrr*rErrrr rs     zDistribution.__init__c Ksdgd\}}}}tjj|\}} | jtkrt|} | r|| jdddd\}}}}nt| j}n|||d|d|d|d ||S) Nrr verpyverrJrrr*rE)rrsplitextr-_distributionImplEGG_NAMErH) rrrrr)rrr*rEextrCrrr rs !zDistribution.from_locationcCs7t|df|j|jt|j|j|jfS)Nparsed_version)rrr8r[rr*rE)rrrr r s  zDistribution.cCs t|jS)N)hashhashcmp)rrrr __hash__szDistribution.__hash__cCs|j|jkS)N)rg)rr3rrr __lt__szDistribution.__lt__cCs|j|jkS)N)rg)rr3rrr __le__szDistribution.__le__cCs|j|jkS)N)rg)rr3rrr __gt__szDistribution.__gt__cCs|j|jkS)N)rg)rr3rrr __ge__szDistribution.__ge__cCs&t||jsdS|j|jkS)NF)rrrg)rr3rrr __eq__szDistribution.__eq__cCs ||k S)Nr)rr3rrr __ne__szDistribution.__ne__c Cs>y |jSWn,tk r9|jj|_}|SYnXdS)N)_keyrrr-)rr8rrr r8s   zDistribution.keyc Cs>y |jSWn,tk r9t|j|_}|SYnXdS)N)_parsed_versionrrnr)rpvrrr res   zDistribution.parsed_versionc Csy |jSWntk rxq|j|jD]G}|jjdr.t|jdddj|_|jSq.Wt d|j|YnXdS)Nzversion:rKrz(Missing 'Version:' header and/or %s file) r]r _get_metadataPKG_INFOr-rrprrrI)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.txtrKr)rtru) _Distribution__dep_maprrtrrrrwrxrurr rm)rdmr rjrmarkerrrr _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)ryr rrurrk)rr rwdepsrdrrr rs   zDistribution.requiresccs5|j|r1x|j|D] }|VqWndS)N)rr)rr rrrr rrszDistribution._get_metadatacCs~|dkrtj}n|j||tjkrzt|jx6|jdD]"}|tjkrQt|qQqQWndS)z>Ensure distribution is importable on `path` (default=sys.path)Nznamespace_packages.txt)rDrrrrrrrr[)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%srg)rvrrr*r8rE)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)rrIr)rrrrr rL s   zDistribution.__str__cCs.|jdrt|nt|j|S)zADelegate all unrecognized public attributes to .metadata providerr)rrrr^)rrMrrr __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)rfrrr)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)rSrrN)rrHr rrrr rQ6 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)_ep_maprrgrYrrr)rrHep_maprrr rR= s  ! zDistribution.get_entry_mapcCs|j|j|S)z.r)rrrrr" enumeraterr{rDcheck_version_conflictrrindexrI) rrlocnlocbdirnpathrrnprrr 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_resourcessiterzIModule %s was already imported from %s, but %s is being added to sys.path)z pkg_resourcesz setuptoolszsite) r8r&r'rrrzrrDrr!rr issue_warning)rnsprmodnamerrrr rt s"  z#Distribution.check_version_conflictc Cs<y |jWn*tk r7tdt|dSYnXdS)NzUnbuilt egg for FT)rrIrr)rrrr r0 s    zDistribution.has_versioncKsMx*d D]"}|j|t||dqW|jd|j|j|S) z@Copy this distribution, substituting in any changed keyword argsrrr*rErrNr)z project_namezversionz py_versionzplatformzlocationz precedence)rrr^r)rr)rMrrr clone s   zDistribution.clonecCsdd|jDS)NcSsg|]}|r|qSrr)r|deprrr r s z'Distribution.extras..)ry)rrrr r  szDistribution.extras)(rrrrrsr8r{rr%rpropertyrgrhrirjrkrlrmrnr8rerryrrrr|rrrLr}r rrQrRrSrrr0rr rrrr resL                  '   c@sgeZdZdZdZejdZeddZ eddZ dd Z d d Z d S) DistInfoDistributionzGWrap an actual or potential sys.path entry w/metadata, .dist-info styleMETADATAz([\(,])\s*(\d.*?)\s*([,\)])c Cs\y |jSWnJtk rWddlm}|j|j|j|_|jSYnXdS)zParse and cache metadatar)ParserN) _pkg_infor email.parserrparsestrrrs)rrrrr _parsed_pkg_info s   !z%DistInfoDistribution._parsed_pkg_infoc Cs:y |jSWn(tk r5|j|_|jSYnXdS)N)_DistInfoDistribution__dep_mapr_compute_dependencies)rrrr ry 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())rrrhriEQEQr)r 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)pip._vendor._markerlibrrrget_allrrrmrr frozensetr rurr) rcompile_markerrwrrrrZrcommonrjr)rr r s$z*DistInfoDistribution._compute_dependenciesN) rrrrrsrhrrrrryrrrrrr r s   rz.eggz .egg-infoz .dist-infoc Os|d}t}y-x&tj|j|kr:|d7}qWWntk rPYnXddlm}|d|d||dS)Nrr)rO stacklevel)rrDrrrIrNrO)r=r)levelr.rOrrr 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 StopIterationrIrrHendCOMMA)ITEM TERMINATORrrgroups item_namer,rC)rTrr scan_list s0   * #z%parse_requirements..scan_listzMissing distribution specrz 'extra' namer@z version speccSs(g|]\}}|t|fqSr)rp)r|rr5rrr r. s z&parse_requirements..N)r)rr@) iterrsDISTROrIrHrOBRACKETCBRACKETVERSIONLINE_ENDrf)r7rrrCrrr rQr)rTr rm s"!    $$cCsAdd|D}|jdd|D|ddd.cSsg|]\}}|qSrr)r|hcdrrr r5 s rr)r)rtmprrr r.2 s r.c@sjeZdZddZddZddZddZd d Zd d Ze d dZ dS)rfcCs|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)rn state_machine)r|rr0rrr r= s z(Requirement.__init__..cSs(g|]\}}}}||fqSrr)r|rZtransrr_rrr r? s cSs(g|]\}}}}||fqSrr)r|rZrrr_rrr rB s N)ro unsafe_namer-rr8rrQrFrrurr rhashCmprf_Requirement__hash)rrrQr rrrr r9 s "zRequirement.__init__cCsXdjdd|jD}dj|j}|rDd|}nd|j||fS)NrGcSsg|]}dj|qS)r)rF)r|rrrr rH s z'Requirement.__str__..z[%s]z%s%s%s)rFrQr r)rrQr rrr rLG s  zRequirement.__str__cCst|to|j|jkS)N)rrfr)rr3rrr rmM 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+rg)rrer8rrerrn) rrrcomparerZrrr_actionrrr rP s,        zRequirement.__contains__cCs|jS)N)r)rrrr rhd szRequirement.__hash__cCsdt|S)NzRequirement.parse(%r))r)rrrr rg szRequirement.__repr__cCsWtt|}|rDt|dkr2|dStd|ntd|dS)NrrzExpected only one requirementzNo requirements found)rrmrrI)rrrrr ri s zRequirement.parseN) rrrrrLrmrrhrrWrrrrr rf8 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} srcCsAx:tt|dt|D]}||kr||SqWdS)z2Return an adapter factory for `ob` from `registry`rN)rrr)registryr9rrrr r s% rcCs8tjj|}tjj|s4tj|ndS)z1Ensure that the parent directory of `path` existsN)rrr"rmakedirs)rr"rrr ry 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``. NrP]rzInvalid section headingr)rsrrrrIr)rsectioncontentrrrr rt s  c OsDddlm}tj}ztt_|||SWd|t_XdS)Nr)mkstemp)tempfilerrros_open)r=r)rold_openrrr r s   rcCs@x9ttD]+}|jds tt|||s                      '                               1    Y )    c    !  (           , )h !?   > :