File "pkg_resources.cpython-34.pyc"

Full Path: /home/attunedd/public_html/byp/izo/con7ext_sym404/rintoar.txt/opt/alt/python34/lib/python3.4/site-packages/__pycache__/pkg_resources.cpython-34.pyc
File size: 93.81 KB
MIME-type: text/x-bytecode.python
Charset: 8 bit


MRe_m@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZyddl
m
Z
mZWn(ek
rddlm
Z
mZYnXyeWn"ek
rddlmZYnXy$eddZddlmZWn:ek
rleZdd	lmZddd
dZYnXddlmZy&dd
lmZmZm Z dZ!Wnek
rdZ!YnXddlm"Z#ddl$m%Z%m&Z&ej'ddfkoej(j)dkrddl*j+Z,ndZ,yddl-Z-Wnek
rGYnXdddZ.iZ/ddZ0ddZ1ddZ2ddZ3dd Z4d!d"Z5d#d$Z6d%dZ7Z8d&d'Z9d(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdlgEZ:GdmdCdCe;Z<GdndDdDe<Z=GdodEdEe<Z>GdpdFdFe<Z?iZ@ejAddZBdZCdqZDdrZEdZFdrZGdsdhZHdtd*ZIgdudvZJdwdxZKdydzZLejMd{ZNejMd|ZOeLZPd}dMZQd~d)ZReRZSdd+ZTdd,ZUddd-ZVdd.ZWGdd[d[ZXGdd\d\eXZYGdd>d>eZZ[Gdd=d=eZZ\e\Z]GddGdGe^Z_Gdd?d?Z`dd<ZaddJZbddKZcddPZdddQZeidgd6dgd6dddgd6gd6gd6gd6Zfiddd6ddd6ddd6ddd6ddd6ddd6ddd6ZgddZhddZiddZjddRZkdiddSZlddZmdenkremZlnGddbdbZoeHeZeoGddcdceoZpGdddddepZqeHerdeqe,dk	r*eHe,jseqnGdd`d`eoZtetZuddZvGddedeepZweHejxewGdd]d]etZyGdd^d^eqZzGdd_d_ewZ{e0ddiddfZ|ddd9Z}dddZ~e|ejxe~dddZe|eZedddZe|ejee,dk	rae|e,jene0ddie0ddiddgZddZdd6ZdddiZddZeejeeejxee,dk	ree,jenddZeeZeddUZiddZddZddNZejMdjZejMdjZejMdjZejMdjZejMdjZejMdjZejMdjZejMdjZejMdejejBjZejMdejZidd6dd6dd6dd6dd6jZddZddIZGddBdBeZZddZGdd@d@eZZGdddeZied6ed6ed6ZddZddHZddZGddAdAZidd6dd6dd6dd6dd6dd6ZddZddZddTZddOZd	d
Ze`ZddZeene0d
d7e[yddlmZWnek
rYnXyejeWne=k
rje[gZx0ejeee\D]ZejeqWx0ejD]%ZeejkrLejenq'Wejejdd<YnXejZejZejZejRZReRZSeddge_eeejejdS(aYPackage resource API
--------------------

A resource is a logical file contained within a package, or a logical
subdirectory thereof.  The package resource API expects resource names
to have their path parts separated with ``/``, *not* whatever the local
path separator is.  Do not use os.path operations to manipulate resource
names being passed into the API.

The package resource API is designed to work with normal filesystem packages,
.egg files, and unpacked .egg files.  It can also work in a limited way with
.zip files and with custom PEP 302 loaders that support the ``get_data()``
method.
N)get_importer)urlparse
urlunparse)ImmutableSetcCs
|jS)N)next)or(/tmp/pip-l4uy7dan-build/pkg_resources.py<lambda>(sr
)StringIO)BytesIOcCsY|dkrt}n|dkr-|}nttt|j|d||dS)Nexec)globalsr
compileopenread)fnglobslocsrrr	execfile-s
	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	rKs
rcKs>t}x.|jD] \}}|||<|t|<qWdS)N)ritems_state_vars)vartypekwgr valrrr	_declare_stateWs	
r*cCsLi}t}x6tjD](\}}|d|||||<qW|S)N_sget_)rr%r$)stater(kvrrr	__getstate__]s
	 r/cCsJt}x:|jD],\}}|dt|||||qW|S)N_sset_)rr$r%)r,r(r-r.rrr	__setstate__ds	$r1cCs
|jS)N)copy)r)rrr	
_sget_dictjsr3cCs|j|j|dS)N)clearupdate)keyobr,rrr	
_sset_dictms
r8cCs
|jS)N)r/)r)rrr	_sget_objectqsr9cCs|j|dS)N)r1)r6r7r,rrr	_sset_objecttsr:cGsdS)Nr)argsrrr	r
wscCst}tj|}|dk	r~tjdkr~y3ddjtdd|jdf}Wq~tk
rzYq~Xn|S)aZReturn this platform's maximum compatible version.

    distutils.util.get_platform() normally reports the minimum version
    of Mac OS X that would be required to *use* extensions produced by
    distutils.  But what we want when checking compatibility is to know the
    version of Mac OS X that we are *running*.  To allow usage of packages that
    explicitly require a newer version of Mac OS X, we must also know the
    current version of the OS.

    If this condition occurs for any other platform with a version in its
    platform strings, this function should be extended accordingly.
    Ndarwinzmacosx-%s-%s.r)	get_build_platformmacosVersionStringmatchsysplatformjoin_macosx_versgroup
ValueError)platmrrr	get_supported_platformzs
	3
rJrequire
run_scriptget_providerget_distributionload_entry_point
get_entry_mapget_entry_infoiter_entry_pointsresource_stringresource_streamresource_filenameresource_listdirresource_existsresource_isdirdeclare_namespaceworking_setadd_activation_listenerfind_distributionsset_extraction_pathcleanup_resourcesget_default_cacheEnvironment
WorkingSetResourceManagerDistributionRequirement
EntryPointResolutionErrorVersionConflictDistributionNotFoundUnknownExtraExtractionErrorparse_requirements
parse_version	safe_namesafe_versionget_platformcompatible_platformsyield_linessplit_sections
safe_extrato_filenameinvalid_markerevaluate_markerensure_directorynormalize_pathEGG_DISTBINARY_DISTSOURCE_DIST
CHECKOUT_DISTDEVELOP_DISTIMetadataProviderIResourceProviderFileMetadataPathMetadataEggMetadata
EmptyProviderempty_providerNullProviderEggProviderDefaultProviderZipProviderregister_finderregister_namespace_handlerregister_loader_typefixup_namespace_packagesrrun_mainAvailableDistributionsc@s"eZdZdZddZdS)rfz.Abstract base for dependency resolution errorscCs|jjt|jS)N)	__class____name__reprr;)selfrrr	__repr__szResolutionError.__repr__N)r
__module____qualname____doc__rrrrr	rfsc@seZdZdZdS)rgzAAn already-installed version conflicts with the requested versionN)rrrrrrrr	rgsc@seZdZdZdS)rhz&A requested distribution was not foundN)rrrrrrrr	rhsc@seZdZdZdS)riz>Distribution doesn't have an "extra feature" of the given nameN)rrrrrrrr	risr>cCs|t|<dS)aRegister `provider_factory` to make providers for `loader_type`

    `loader_type` is the type or class of a PEP 302 ``module.__loader__``,
    and `provider_factory` is a function that, passed a *module* object,
    returns an ``IResourceProvider`` for that module.
    N)_provider_factories)loader_typeprovider_factoryrrr	rscCst|tr2tj|p1tt|dSytj|}Wn)tk
rnt	|tj|}YnXt
|dd}tt||S)z?Return an IResourceProvider for the named module or requirementr
__loader__N)
isinstancerdrZfindrKstrrBmodulesKeyError
__import__getattr
_find_adapterr)moduleOrReqmoduleloaderrrr	rMs#

cCs|sddl}|jd}|dkrddl}d}tjj|rt|dr|j|}d|kr|d}qqqn|j|j	dn|dS)Nrz0/System/Library/CoreServices/SystemVersion.plist	readPlistProductVersionr=)
rCmac_verplistlibospathexistshasattrrappendr)_cacherCversionrplist
plist_contentrrr	rEsrEcCsidd6dd6j||S)NppcPowerPCPower_Macintosh)get)machinerrr	_macosx_archsrcCsyddlm}Wn"tk
r8ddlm}YnX|}tjdkr|jdryTt}tj	dj
dd}dt|dt|d	t|fSWqt
k
rYqXn|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 Mac OS X.
    r)ror<zmacosx- _zmacosx-%d.%d-%sr)	sysconfigroImportErrordistutils.utilrBrC
startswithrErunamereplaceintrrG)rorHrrrrr	r?s
		
r?zmacosx-(\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|jdkrd
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)r@rAdarwinVersionStringrrF)providedrequiredreqMacprovMac
provDarwindversionmacosversionrrr	rps*$"*cCsNtjdj}|d}|j||d<t|dj||dS)z@Locate distribution `dist_spec` and run its `script_name` scriptrrrN)rB	_getframe	f_globalsr4rKrL)Z	dist_specscript_namensr rrr	rLHs



cCsdt|tr!tj|}nt|tr?t|}nt|ts`td|n|S)z@Return a current distribution object for a Requirement or stringz-Expected string, Requirement, or Distribution)r
basestringrdparserMrc	TypeError)distrrr	rNRscCst|j||S)zDReturn `name` entry point of `group` for `dist` or raise ImportError)rNrO)rrFr rrr	rOZscCst|j|S)z=Return the entry point map for `group`, or the full entry map)rNrP)rrFrrr	rP^scCst|j||S)z<Return the EntryPoint object for `group`+`name`, or ``None``)rNrQ)rrFr rrr	rQbsc@sXeZdZddZddZddZddZd	d
ZddZd
S)r~cCsdS)z;Does the package's distribution contain the named metadata?Nr)r rrr	has_metadataiszIMetadataProvider.has_metadatacCsdS)z'The named metadata resource as a stringNr)r rrr	get_metadatalszIMetadataProvider.get_metadatacCsdS)zYield named metadata resource as list of non-blank non-comment lines

       Leading and trailing whitespace is stripped from each line, and lines
       with ``#`` as the first non-blank character are omitted.Nr)r rrr	get_metadata_linesosz$IMetadataProvider.get_metadata_linescCsdS)z>Is the named metadata a directory?  (like ``os.path.isdir()``)Nr)r rrr	metadata_isdirusz IMetadataProvider.metadata_isdircCsdS)z?List of metadata names in the directory (like ``os.listdir()``)Nr)r rrr	metadata_listdirxsz"IMetadataProvider.metadata_listdircCsdS)z=Execute the named script in the supplied namespace dictionaryNr)r	namespacerrr	rL{szIMetadataProvider.run_scriptN)	rrrrrrrrrLrrrr	r~gsc@s^eZdZdZddZddZddZdd	Zd
dZd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	rXsz IResourceProvider.resource_isdircCsdS)z?List of resource names in the directory (like ``os.listdir()``)Nr)rrrr	rVsz"IResourceProvider.resource_listdirN)
rrrrrrrrrXrVrrrr	rsc@seZdZdZdddZddZddZd	d
ZdddZd
dZ	ddZ
ddddZddddZdddddZ
ddZddZddZddZd d!ZdS)"razDA collection of active distributions on sys.path (or a similar list)NcCs^g|_i|_i|_g|_|dkr<tj}nx|D]}|j|qCWdS)z?Create working set from list of path entries (default=sys.path)N)entries
entry_keysby_key	callbacksrBr	add_entry)rrentryrrr	__init__s				
zWorkingSet.__init__cCsT|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\add)rrrrrr	rs
zWorkingSet.add_entrycCs|jj|j|kS)z9True if `dist` is the active distribution for its project)rrr6)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)rrr6rg)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)rPvalues)rrFr rreprrr	rRs
zWorkingSet.iter_entry_pointscCsQtjdj}|d}|j||d<|j|dj||dS)z?Locate distribution for `requires` and run `script_name` scriptrrrN)rBrrr4rKrL)rrequiresrrr rrr	rLs



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)rseenitemr6rrr	__iter__s
zWorkingSet.__iter__TcCs|r|j|j|n|dkr4|j}n|jj|g}|jj|jg}|j|jkrwdS||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.  If it's added, any
        callbacks registered with the ``subscribe()`` method will be called.
        N)		insert_onrlocationrrr6rr
_added_new)rrrinsertkeyskeys2rrr	rszWorkingSet.addc	CsVt|ddd}i}i}g}x$|rQ|jd}||krUq.n|j|j}|dkr|jj|j}|dkr|dkrt|j}n|j|||}||j<|dkrt|qn|j	|n||krt
||n|j|j|j
dddd||<q.W|S)aList all distributions needed to (recursively) meet `requirements`

        `requirements` must be a sequence of ``Requirement`` objects.  `env`,
        if supplied, should be an ``Environment`` instance.  If
        not supplied, it defaults to all distributions available within any
        entry or distribution in the working set.  `installer`, if supplied,
        will be invoked with each requirement that cannot be met by an
        already-installed distribution; it should return a ``Distribution`` or
        ``None``.
        NrrTr)listpoprr6rr`r
best_matchrhrrgextendrextras)	rrequirementsenv	installer	processedbestto_activaterrrrr	resolves.	 &zWorkingSet.resolvecCsPt|}|ji}i}|dkrJt|j}||7}n
||}|jg}	tt|	j|x|D]}
x||
D]}|jg}y|	j|||}
Wn9t	k
rt
jd}|||<|rwnPYqXtt|	j|
|jt
j|
PqWqWt|}|j||fS)abFind all activatable distributions in `plugin_env`

        Example usage::

            distributions, errors = working_set.find_plugins(
                Environment(plugin_dirlist)
            )
            map(working_set.add, distributions)  # add plugins+libs to sys.path
            print 'Could not load', errors        # display errors

        The `plugin_env` should be an ``Environment`` instance that contains
        only distributions that are in the project's "plugin directory" or
        directories. The `full_env`, if supplied, should be an ``Environment``
        contains all currently-available distributions.  If `full_env` is not
        supplied, one is created automatically from the ``WorkingSet`` this
        method is called on, which will typically mean that every directory on
        ``sys.path`` will be scanned for distributions.

        `installer` is a standard installer callback as used by the
        ``resolve()`` method. The `fallback` flag indicates whether we should
        attempt to resolve older versions of a plugin if the newest version
        cannot be resolved.

        This method returns a 2-tuple: (`distributions`, `error_info`), where
        `distributions` is a list of the distributions found in `plugin_env`
        that were loadable, along with any other distributions that are needed
        to resolve their dependencies.  `error_info` is a dictionary mapping
        unloadable plugin distributions to an exception instance describing the
        error that occurred. Usually this will be a ``DistributionNotFound`` or
        ``VersionConflict`` instance.
        Nr)rsortr`rrmapras_requirementrrfrBexc_infor5dictfromkeys)r
plugin_envfull_envrfallbackplugin_projects
error_info
distributionsr
shadow_setproject_namerr	resolveesr.rrr	find_pluginsAs6"





	
zWorkingSet.find_pluginscGs7|jt|}x|D]}|j|qW|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.
        )rrkr)rrneededrrrr	rKs	
zWorkingSet.requirecCsB||jkrdS|jj|x|D]}||q*WdS)zAInvoke `callback` for all distributions (including existing ones)N)rr)rcallbackrrrr		subscribes

zWorkingSet.subscribecCs"x|jD]}||q
WdS)N)r)rrrrrr	rszWorkingSet._added_newcCs<|jdd|jj|jj|jddfS)N)rrr2rr)rrrr	r/s(zWorkingSet.__getstate__cCsZ|\}}}}|dd|_|j|_|j|_|dd|_dS)N)rr2rrr)re_k_b_crrrrrrr	r1s
zWorkingSet.__setstate__)rrrrrrrrrRrLrrrrrKrrr/r1rrrr	ras"
/Mc@seZdZdZdeeddZddZddZdd	d
Z	ddZ
d
dZdddZdddZ
ddZddZddZdS)r`z5Searchable snapshot of distributions on a search pathNcCs5i|_i|_||_||_|j|dS)a!Snapshot distributions available on a search path

        Any distributions found on `search_path` are added to the environment.
        `search_path` should be a sequence of ``sys.path`` items.  If not
        supplied, ``sys.path`` is used.

        `platform` is an optional string specifying the name of the platform
        that platform-specific distributions must be compatible with.  If
        unspecified, it defaults to the current platform.  `python` is an
        optional string naming the desired version of Python (e.g. ``'3.3'``);
        it defaults to the current version.

        You may explicitly set `platform` (and/or `python`) to ``None`` if you
        wish to map *all* distributions, not just those compatible with the
        running platform or Python version.
        N)_distmaprrCpythonscan)rsearch_pathrCrrrr	rs
				zEnvironment.__init__cCsC|jdks0|jdks0|j|jkoBt|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)r
py_versionrprC)rrrrr	can_addszEnvironment.can_addcCs|j|jj|dS)z"Remove `dist` from the environmentN)rr6remove)rrrrr	r!szEnvironment.removecCsQ|dkrtj}nx2|D]*}x!t|D]}|j|q2WqWdS)adScan `search_path` for distributions usable in this environment

        Any distributions found are added to the environment.
        `search_path` should be a sequence of ``sys.path`` items.  If not
        supplied, ``sys.path`` is used.  Only distributions conforming to
        the platform/python version defined at initialization are added.
        N)rBrr\r)rrrrrrr	rs

zEnvironment.scancCsy|j|SWn1tk
rB|j}||jkr>gSYnX||jkrw|j|}|j|<t|n|j|S)zKReturn a newest-to-oldest list of distributions for `project_name`
        )rrlowerr_sort_dists)rrdistsrrr	__getitem__s
	
zEnvironment.__getitem__cCs|j|r{|jr{|jj|jg}||kr{|j||j|jkrxt|j|jqxq{ndS)z<Add `dist` if we ``can_add()`` it and it isn't already addedN)r has_versionrrr6rrr#)rrr$rrr	rs
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)rr6obtain)rrrZrrrrr	r
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)rrequirementrrrr	r's	zEnvironment.obtainccs0x)|jjD]}||r|VqqWdS)z=Yield the unique project names of the available distributionsN)rr)rr6rrr	r+s
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)rrcrr`r)rotherprojectrrrr	__iadd__0s
zEnvironment.__iadd__cCs@|jgdddd}x||fD]}||7}q(W|S)z4Add an environment or distribution to an environmentrCNr)r)rr)newrrrr	__add__<szEnvironment.__add__)rrrrrJPY_MAJORrr r!rr%rrr'rr+r-rrrr	r`s	c@seZdZdZdS)rjaTAn error occurred extracting a resource

    The following attributes are available from instances of this exception:

    manager
        The resource manager that raised this exception

    cache_path
        The base directory for resource extraction

    original_error
        The exception instance that caused extraction to fail
    N)rrrrrrrr	rjGs
c@seZdZdZdZddZddZddZd	d
ZddZ	d
dZ
ddZddZfddZ
eddZddZddZdddZdS)rbz'Manage resource extraction and packagesNcCs
i|_dS)N)cached_files)rrrr	r[szResourceManager.__init__cCst|j|S)zDoes the named resource exist?)rMr)rpackage_or_requirementrrrr	rW^szResourceManager.resource_existscCst|j|S)z,Is the named resource an existing directory?)rMrX)rr0rrrr	rXbszResourceManager.resource_isdircCst|j||S)z4Return a true filesystem path for specified resource)rMr)rr0rrrr	rUhsz!ResourceManager.resource_filenamecCst|j||S)z9Return a readable file-like object for specified resource)rMr)rr0rrrr	rTnszResourceManager.resource_streamcCst|j||S)z%Return specified resource as a string)rMr)rr0rrrr	rStszResourceManager.resource_stringcCst|j|S)z1List the contents of the named resource directory)rMrV)rr0rrrr	rVzs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)rBr
extraction_pathr_rjr
cache_pathoriginal_error)rold_excr2errrrr	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)	r1r_rrrDrr6_warn_unsafe_extraction_pathr/)rarchive_namenamesextract_pathtarget_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_IWGRPwarningswarnUserWarning)rr!msgrrr	r7s
&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 r@rAchmod)rtempnamer#r!rrr	postprocessszResourceManager.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)r/rGr1)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^sz!ResourceManager.cleanup_resources)rrrrr1rrWrXrUrTrSrVr6r<staticmethodr7rKr]r^rrrr	rbWs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_CACHEr=z~/.python-eggszApplication DataAPPDATANUSERPROFILE	HOMEDRIVEHOMEPATHHOMEWINDIRrzPython-Eggsz3Please set the PYTHON_EGG_CACHE enviroment variablezAPPDATA)rUN)zUSERPROFILE)z	HOMEDRIVEHOMEPATH)rVzHOME)rWN)zWINDIR)rr?rr r
expanduserrDRuntimeError)app_data	app_homesrsubdirr"r6rrr	r_s0
			
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	rm0scCs%|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.]+r])rr^r_)rrrr	rn8scCstjdd|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)r^r_r")extrarrr	rsBscCs|jddS)z|Convert a project or version name to its filename-escaped form

    Any '-' characters are currently replaced with '_'.
    r]r)r)r rrr	rtKsr rrCrBrrpython_implementationpython_versionpython_full_versionr`cCstjS)N)rr rrrr	r
Ysos_namecCstjS)N)rBrCrrrr	r
Zssys_platformcCstjjdS)Nr)rBrrrrrr	r
[scCsdtjdtjdfS)Nz%s.%srr)rBversion_inforrrr	r
\scCs
tdS)Nr)	_platinforrrr	r
]splatform_versioncCs
tdS)Nr)rgrrrr	r
^splatform_machinecCstdptS)Nra)rg_pyimprrrr	r
_sc
CsByddl}Wntk
r(dSYnXt||ddS)NrrcSsdS)Nrrrrrr	r
gsz_platinfo.<locals>.<lambda>)rCrr)attrrCrrr	rgbs

	rgcCsDtjdkrdStjjdr)dSdtjkr<dSdSdS)Ncli
IronPythonjavaJythonZ__pypy__PyPyCPython)rBrCrbuiltin_module_namesrrrr	rjisrjcCsEidd6dd6}d|_d|_|j|j|j|_|S)z
    Given a SyntaxError from a marker evaluation, normalize the error message:
     - Remove indications of filename and line number.
     - Replace platform-specific error messages with standard error messages.
    zinvalid syntaxzunexpected EOF while parsingzparenthesis is never closedN)r#linenorrG)excsubsrrr	normalize_exceptionss
		rvcCs;yt|Wn&tk
r6ttjdSYnXdS)zHValidate text as a PEP 426 environment marker; return exception or FalserF)rvSyntaxErrorrvrBr
)textrrr	rus

csfsddlmmddlddlddlfdd}fdd}fdd	}fd
d}ji|j6|j6|j6|j	6dd
d6dd
d6j
d6jd6tdr|j
<qnfddfddtj|jddS)aV
    Evaluate a PEP 426 environment marker on CPython 2.4+.
    Return a boolean indicating the marker result in this environment.
    Raise SyntaxError if marker is invalid.

    This implementation uses the 'parser' module, which is not implemented on
    Jython and has been superseded by the 'ast' module in Python 2.6 and
    later.
    r)NAMESTRINGNcs;tjjfddtdtdDS)Ncs g|]}|qSrr).0i)	interpretnodelistrr	
<listcomp>s	z5evaluate_marker.<locals>.and_test.<locals>.<listcomp>rr>)	functoolsreduceand_rangelen)r~)r}operator)r~r	and_testsz!evaluate_marker.<locals>.and_testcs;tjjfddtdtdDS)Ncs g|]}|qSrr)r{r|)r}r~rr	rs	z1evaluate_marker.<locals>.test.<locals>.<listcomp>rr>)rror_rr)r~)r}r)r~r	testszevaluate_marker.<locals>.testcsa|dd}|jkrQ|ddjkrCtdn|dStddS)Nrrr>zEmpty parenthesesz5Language feature not supported in environment markers)LPARRPARrw)r~t)r}tokenrr	atomszevaluate_marker.<locals>.atomc
st|dkr!tdn|dd}|d}|dkrt|ddkr|dkrtd}q}d	}qny|}Wn(tk
rtt|d
YnX||d|dS)Nrz5Chained comparison not allowed in environment markersr>rrrnotznot inzis notz, operator not allowed in environment markers)rrwrr)r~compcop)ry_opsevaluaterr	
comparisons
	
z#evaluate_marker.<locals>.comparisoncSs
||kS)Nr)xyrrr	r
sz!evaluate_marker.<locals>.<lambda>znot incSs
||kS)Nr)rrrrr	r
sinz==z!=or_testcs{x t|dkr"|d}qWy|d}Wn9tk
rptdtdj|dYnX||S)Nr>rrz)Comparison or logical expression expectedz7Language feature not supported in environment markers: )rrrwsym_name)r~op)rsymbolrr	r}s
 z"evaluate_marker.<locals>.interpretcsx t|dkr"|d}qW|d}|d}|kr}yt|}Wn"tk
rutd|YnX|S|kr|d}|dddks|jds|jdsd|krtd	n|ddStd
dS)Nr>rrzUnknown name %rz'"z"""z'''\z1Only plain strings allowed in environment markersz5Language feature not supported in environment markersr)r_marker_valuesrrwr)r~kindr rs)ryrzrr	rs$



4z!evaluate_marker.<locals>.evaluater)rryrzrrr5rrrreqnerrparserexprtotuple)rxr`rrrrrr)ryrzrrr}rrrr	rvs$	%	cCsddl}|j}x9|jD]+}|jdd}|j|||<q%Wy|j||}Wn5tk
rtjd}t	|j
dYnX|S)z
    Evaluate a PEP 426 environment marker using markerlib.
    Return a boolean indicating the marker result in this environment.
    Raise SyntaxError if marker is invalid.
    rNr=rr)
_markerlibdefault_environmentrrrr}	NameErrorrBr
rwr;)rxrrr6new_keyresulterrr	_markerlib_evaluates
rrc@seZdZdZdZdZdZddZddZddZ	d	d
Z
ddZd
dZe
jd)krddZnddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(ZdS)*rzETry to implement resources and metadata for arbitrary PEP 302 loadersNcCs:t|dd|_tjjt|dd|_dS)Nr__file__r)rrrrr"module_path)rrrrr	rszNullProvider.__init__cCs|j|j|S)N)_fnr)rrrrrr	r	sz"NullProvider.get_resource_filenamecCst|j||S)N)rr)rrrrrr	rsz NullProvider.get_resource_streamcCs|j|j|j|S)N)_getrr)rrrrrr	rsz NullProvider.get_resource_stringcCs|j|j|j|S)N)_hasrr)rrrrr	rszNullProvider.has_resourcecCs%|jo$|j|j|j|S)N)egg_inforr)rr rrr	rszNullProvider.has_metadatarcCs)|js
dS|j|j|j|S)Nr)rrr)rr rrr	rs	zNullProvider.get_metadatacCs2|js
dS|j|j|j|jdS)Nrzutf-8)rrrdecode)rr rrr	rs	cCst|j|S)N)rqr)rr rrr	r#szNullProvider.get_metadata_linescCs|j|j|j|S)N)_isdirrr)rrrrr	rX&szNullProvider.resource_isdircCs%|jo$|j|j|j|S)N)rrr)rr rrr	r)szNullProvider.metadata_isdircCs|j|j|j|S)N)_listdirrr)rrrrr	rV,szNullProvider.resource_listdircCs)|jr%|j|j|j|SgS)N)rrr)rr rrr	r/s	zNullProvider.metadata_listdircCsd|}|j|s,td|n|j|jdd}|jdd}|j|j|}||d<tjj|rt	|||nWddl
m}t|d|j
d|f||<t||d	}t|||dS)
Nzscripts/zNo script named %rz


rr)cacher
)rrfrrrrrrrr	linecacherrrrr
)rrrscriptscript_textscript_filenamerscript_coderrr	rL4s

%zNullProvider.run_scriptcCstddS)Nz9Can't perform this operation for unregistered loader type)NotImplementedError)rrrrr	rFszNullProvider._hascCstddS)Nz9Can't perform this operation for unregistered loader type)r)rrrrr	rKszNullProvider._isdircCstddS)Nz9Can't perform this operation for unregistered loader type)r)rrrrr	rPszNullProvider._listdircCs&|r"tjj||jdS|S)N/)rrrDr)rbaserrrr	rUszNullProvider._fncCs2t|jdr"|jj|StddS)Nget_dataz=Can't perform this operation for loaders without 'get_data()')rrrr)rrrrr	rZszNullProvider._get)r)rrrregg_namerrrrrrrrrBrfrrrXrrVrrLrrrrrrrrr	rs0c@s.eZdZdZddZddZdS)rz&Provider based on a virtual filesystemcCstj|||jdS)N)rr
_setup_prefix)rrrrr	rgszEggProvider.__init__cCs|j}d}x}||kr|jjdrmtjj||_tjj|d|_||_	Pn|}tjj
|\}}qWdS)Nz.eggzEGG-INFO)rr"endswithrrbasenamerrDregg_rootr)rroldrrrr	rks		zEggProvider._setup_prefixN)rrrrrrrrrr	rdsc@sReZdZdZddZddZddZdd	Zd
dZdS)
rz6Provides access to package resources in the filesystemcCstjj|S)N)rrr)rrrrr	r|szDefaultProvider._hascCstjj|S)N)rrr)rrrrr	rszDefaultProvider._isdircCs
tj|S)N)rlistdir)rrrrr	rszDefaultProvider._listdircCst|j|j|dS)Nrb)rrr)rrrrrr	rsz#DefaultProvider.get_resource_streamc
Cs/t|d}z|jSWd|jXdS)Nr)rrclose)rrstreamrrr	rszDefaultProvider._getN)	rrrrrrrrrrrrr	rysc@sPeZdZdZddZZddZddZdZddZ	dS)	rz.Provider that returns nothing for all requestscCsdS)NFr)rrrrr	r
szEmptyProvider.<lambda>cCsdS)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)
rzipfileZipFilenamelistrrsepgetinfoAssertionErrorr)rzipinfozfilezitemzpathrrr	build_zipmanifests	rc@seZdZdZdZddZddZddZd	d
Ze	ddZ
d
dZddZ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	_partss

'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_resourcesrDr_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_sizes	
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=)_indexrrrrDr"rrrrr<rr_is_current_mkstempwriterrrrrKrerrorisfiler rr6)
rrrr lastrr	real_pathoutftmpnamrrr	rs@$


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)
rrrrrr@st_sizest_mtimerrrrr)	r	file_pathrrrr@zip_contentsf
file_contentsrrr	r&s
zZipProvider._is_currentcCsa|jdkrZg}x6dD].}|j|r|j|j|qqW||_n|jS)Nnative_libs.txteager_resources.txt)rr)rrrr)rrr rrr	r7s
z ZipProvider._get_eager_resourcescCsy|jSWntk
ri}x|jD]y}|jtj}x^|rtjj|dd}||kr||j|dPqF|jg||<qFWq+W||_|SYnXdS)Nrrr)		_dirindexAttributeErrorrrrrrDrr)rindrpartsparentrrr	r@s
		zZipProvider._indexcCs.|j|}||jkp-||jkS)N)rrr)rrrrrr	rQszZipProvider._hascCs|j||jkS)N)rr)rrrrr	rUszZipProvider._isdircCs%t|jj|j|fS)N)rrrr)rrrrr	rXszZipProvider._listdircCs|j|j|j|S)N)rrr)rrrrr	r[szZipProvider._eager_to_zipcCs|j|j|j|S)N)rrr)rrrrr	r^szZipProvider._resource_to_zip)rrrrrrrrrrMrrrrrrrrrrrrrr	rs 		
1	c@sFeZdZdZddZddZddZdd	Zd
S)ra*Metadata handler for standalone PKG-INFO files

    Usage::

        metadata = FileMetadata("/path/to/PKG-INFO")

    This provider rejects all data and metadata requests except for PKG-INFO,
    which is treated as existing, and will be the contents of the file at
    the provided location.
    cCs
||_dS)N)r)rrrrr	rpszFileMetadata.__init__cCs
|dkS)NzPKG-INFOr)rr rrr	rsszFileMetadata.has_metadatacCsH|dkr8t|jd}|j}|j|StddS)NzPKG-INFOrUz(No metadata except PKG-INFO is available)rrrrr)rr rmetadatarrr	rvs
zFileMetadata.get_metadatacCst|j|S)N)rqr)rr rrr	r~szFileMetadata.get_metadata_linesN)rrrrrrrrrrrr	rds

c@s"eZdZdZddZdS)raqMetadata provider for egg directories

    Usage::

        # Development eggs:

        egg_info = "/path/to/PackageName.egg-info"
        base_dir = os.path.dirname(egg_info)
        metadata = PathMetadata(base_dir, egg_info)
        dist_name = os.path.splitext(os.path.basename(egg_info))[0]
        dist = Distribution(basedir,project_name=dist_name,metadata=metadata)

        # Unpacked egg directories:

        egg_path = "/path/to/PackageName-ver-pyver-etc.egg"
        metadata = PathMetadata(egg_path, os.path.join(egg_path,'EGG-INFO'))
        dist = Distribution.from_filename(egg_path, metadata=metadata)
    cCs||_||_dS)N)rr)rrrrrr	rs	zPathMetadata.__init__N)rrrrrrrrr	rsc@s"eZdZdZddZdS)rz Metadata provider for .egg filescCsrt|j|_|jtj|_||_|jrXtjj	|j|j|_
n|j|_
|jdS)z-Create a metadata provider from a zipimporterN)rrrrrrrprefixrrDrr)rimporterrrr	rs		!zEggMetadata.__init__N)rrrrrrrrr	rsr_distribution_finderscCs|t|<dS)axRegister `distribution_finder` to find distributions in sys.path items

    `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
    handler), and `distribution_finder` is a callable that, passed a path
    item and the importer instance, yields ``Distribution`` instances found on
    that path item.  See ``pkg_resources.find_on_path`` for an example.N)r)
importer_typedistribution_finderrrr	rscCs+t|}tt|}||||S)z.Yield distributions accessible via `path_item`)rrr)	path_itemonlyrfinderrrr	r\sccst|}|jdr2tj|d|Vn|r<dSxf|jdD]U}|jdrLtjj||}x(t	t
j||D]}|VqWqLqLWdS)NzPKG-INFOrrz.egg)rrrc
from_filenamerVrrrrDfind_in_zip	zipimportzipimporter)rrrrsubitemsubpathrrrr	rsrcCsfS)Nr)rrrrrr	find_nothingsrccst|}tjj|rtj|tjr|jjdrwtj	|dt
|tjj|dVqxtj|D]}}|j}|jds|jdrtjj||}tjj|rt
||}nt
|}tj|||dtVq|r]|jdr]xttjj||D]}|VqKWq|r|jdrttjj||}z|j}	Wd|jXxU|	D]J}
|
jsqnx.ttjj||
jD]}|VqWPqWqqWndS)	z6Yield distributions accessible on a sys.path directoryz.eggrzEGG-INFOz	.egg-infoz
.dist-info
precedencez	.egg-linkN)_normalize_cachedrrraccessR_OKr"rrcr
rrDrr
from_locationr}r\r	readlinesrstriprstrip)rrrrr"fullpathrr
entry_fileentry_lineslinerrrr	find_on_paths:'	 "
(	r_namespace_handlers_namespace_packagescCs|t|<dS)aRegister `namespace_handler` to declare namespace packages

    `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
    handler), and `namespace_handler` is a callable like this::

        def namespace_handler(importer,path_entry,moduleName,module):
            # return a path_entry to use for child packages

    Namespace handlers are only called if the importer object has already
    agreed that it can handle the relevant path item, and they should only
    return a subpath if the module __path__ does not already contain an
    equivalent subpath.  For an example namespace handler, see
    ``pkg_resources.file_ns_handler``.
    N)r)rnamespace_handlerrrr	rscCs
t|}|dkrdS|j|}|dkr;dStjj|}|dkrtj|}tj|<g|_t|n!t	|dst
d|ntt|}|||||}|dk	r	|j}|j
||j|||_n|S)zEEnsure that named package includes a subpath of path_item (if needed)N__path__zNot a package:)rfind_modulerBrrimp
new_moduler!_set_parent_nsrrrrrload_module)packageNamerrrrhandlerrrrrr	
_handle_nss*	
	

r)cCstjz|tkrdStjd}}d|krdj|jddd}t||tkr~t|nytj	|j
}Wqtk
rtd|YqXntj
|gj|tj
|gx|D]}t||qWWdtjXdS)z9Declare that package 'packageName' is a namespace packageNr=rzNot a package:r)r#acquire_lockrrBrrDrrYrrr!rrrrr)release_lock)r'rrrrrr	rY(s&
"



c
CsbtjzFx?tj|fD]+}t||}|r t||q q WWdtjXdS)zDEnsure that previously-declared namespace packages include path_itemN)r#r*rrr)rr+)rrpackagerrrr	rHs
cCs`tjj||jdd}t|}x+|jD]}t||kr8Pq8q8W|SdS)zBCompute an ns-package subpath for a filesystem or zipfile importerr=rNr)rrrDrrr!)rrr'rr
normalizedrrrr	file_ns_handlerRs"r.cCsdS)Nr)rrr'rrrr	null_ns_handleresr/cCstjjtjj|S)z1Normalize a file/dir name for comparison purposes)rrnormcaserealpath)r#rrr	rxkscCs=y||SWn*tk
r8t|||<}|SYnXdS)N)rrx)r#rrrrr	ros

rcCsU|jd}|j}|rQdj|}ttj||tj|ndS)Nr=)rrrDsetattrrBr)r'rr rrrr	r%vs
r%ccst|trSxn|jD]0}|j}|r|jdr|VqqWn-x*|D]"}xt|D]}|VqmWqZWdS)zAYield non-empty/non-comment lines of a ``basestring`` or sequence#N)rr
splitlinesrrrq)strsrssrrr	rq~s
z
\s*(#.*)?$z\s*\\\s*(#.*)?$z\s*((\w|[-.])+)z!\s*(<=?|>=?|==|!=)\s*((\w|[-.])+)z\s*,z\s*\[z\s*\]z\w+(\.\w+)*$zL(?P<name>[^-]+)( -(?P<ver>[^-]+) (-py(?P<pyver>[^-]+) (-(?P<plat>.+))? )? )?z(\d+ | [a-z]+ | \.| -)cprepreviewzfinal-r]rc@devccs{xotj|D]^}t||}|s|dkr>qn|dddkre|jdVqd|VqWdVdS)Nr=r
0123456789r*z*final)component_rerrzfill)rpartrrr	_parse_version_partss
rBcCsg}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)rBr"rrrtuple)rrrArrr	rlsc@seZdZdZffdddZddZddZd	ddd
dZdddd
ZdddZ	e
e	Z	dddZe
eZdddZe
eZdS)rez3Object representing an advertised importable objectNcCsnt|std|n||_||_t||_tjddj|j	|_	||_
dS)NzInvalid module namezx[%s],)MODULErGr module_namerDattrsrdrrDrr)rr rGrHrrrrr	rs		"zEntryPoint.__init__cCsfd|j|jf}|jr<|ddj|j7}n|jrb|ddj|j7}n|S)Nz%s = %s:r=z [%s]rE)r rGrHrDr)rrrrr	__str__s		zEntryPoint.__str__cCsdt|S)NzEntryPoint.parse(%r))r)rrrr	rszEntryPoint.__repr__TcCs|r|j||nt|jttdg}xO|jD]D}yt||}WqDtk
rtd||fYqDXqDW|S)Nrz%r has no %r attribute)rKrrGrrHrrr)rrKrrrrkrrr	loads!
zEntryPoint.loadcCs]|jr%|jr%td|ntttjtj|jj|j||dS)Nz&Can't require() without a distribution)	rrrirrrZrrr)rrrrrr	rKs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[rIr=z9EntryPoint must be in 'name=module:attrs [extras]' formatN)	rrdrspecsrGrrFrr)clssrcrrHrr valuerrrr	rs&

			
zEntryPoint.parsecCst|std|ni}xZt|D]L}|j||}|j|krptd||jn|||j<q1W|S)zParse an entry point groupzInvalid group namezDuplicate entry point)rFrGrqrr )rOrFlinesrthisrrrrr	parse_groupszEntryPoint.parse_groupcCst|tr|j}nt|}i}x~|D]v\}}|dkrj|s[q7ntdn|j}||krtd|n|j|||||<q7W|S)z!Parse a map of entry point groupsNz%Entry points must be listed in groupszDuplicate group name)rrr$rrrGrrT)rOdatarmapsrFrRrrr		parse_map)szEntryPoint.parse_map)
rrrrrrJrrKrKrclassmethodrTrWrrrr	res	
cCsE|s
dSt|}|djdrAt|dddS|S)Nrrzmd5=rr)r)rrr)rparsedrrr	_remove_md5_fragment>srZc	@seZdZdZdZddddededdZdddZe	eZe
dd	Zd
dZdd
Z
ddZddZddZddZddZddZe
eZddZe
eZddZe
eZddZe
eZfd d!Zd"d#Zdd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zdd.d/Ze	eZd0d1Zd2d3Z dd4d5Z!d6d7Z"dd8d9Z#d:d;Z$d<d=Z%d>d?Z&d@dAZ'e
e'Z'dS)Brcz5Wrap an actual or potential sys.path entry w/metadatazPKG-INFONcCsjt|pd|_|dk	r3t||_n||_||_||_||_|p`t|_	dS)NUnknown)
rmrrn_versionrrCrrr	_provider)rrrrrrrCrrrr	rKs				zDistribution.__init__cKsdgd\}}}}tjj|\}}	|	jtkrt|}
|
r||
jdddd\}}}}nt|	j}n|||d|d|d|d	||S)
Nrr verpyverrHrrrrC)rrsplitextr"_distributionImplEGG_NAMErF)rOrrrr'rrrrCextrArrr	rXs!zDistribution.from_locationcCs7t|df|j|jt|j|j|jfS)Nparsed_version)rrr6rZrrrC)rrrr	r
jszDistribution.<lambda>cCs
t|jS)N)hashhashcmp)rrrr	__hash__sszDistribution.__hash__cCs|j|jkS)N)rf)rr)rrr	__lt__tszDistribution.__lt__cCs|j|jkS)N)rf)rr)rrr	__le__vszDistribution.__le__cCs|j|jkS)N)rf)rr)rrr	__gt__xszDistribution.__gt__cCs|j|jkS)N)rf)rr)rrr	__ge__zszDistribution.__ge__cCs&t||jsdS|j|jkS)NF)rrrf)rr)rrr	__eq__|szDistribution.__eq__cCs||kS)Nr)rr)rrr	__ne__szDistribution.__ne__cCs>y|jSWn,tk
r9|jj|_}|SYnXdS)N)_keyrrr")rr6rrr	r6s

zDistribution.keycCs>y|jSWn,tk
r9t|j|_}|SYnXdS)N)_parsed_versionrrlr)rpvrrr	rds

zDistribution.parsed_versioncCsy|jSWntk
rxq|j|jD]G}|jjdr.t|jdddj|_|jSq.Wt	d|j|YnXdS)Nzversion:rIrz(Missing 'Version:' header and/or %s file)
r\r
_get_metadataPKG_INFOr"rrnrrrG)rrrrr	rs
%zDistribution.versioncCsy|jSWntk
rigd6}|_xdD]}xt|j|D]\}}|rd|kr|jdd\}}t|rg}qt|sg}qnt|pd}n|j|gj	t
|qRWq6W|SYnXdS)Nrequires.txtdepends.txtrIr)rsrt)_Distribution__dep_maprrrrqrrurvrsrrrk)rdmr r`reqsmarkerrrr	_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)ryrrrsrri)rrrvdepsrcrrr	rs	

zDistribution.requiresccs5|j|r1x|j|D]}|VqWndS)N)rr)rr rrrr	rqszDistribution._get_metadatacCsd|dkrtj}n|j||tjkr`t|jttt|jdndS)z>Ensure distribution is importable on `path` (default=sys.path)Nznamespace_packages.txt)	rBrrrrrrrYrq)rrrrr	activates

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%sr])rtrrrr.rC)rr#rrr	rs	zDistribution.egg_namecCs(|jrd||jfSt|SdS)Nz%s (%s))rr)rrrr	rs	zDistribution.__repr__cCsNyt|dd}Wntk
r0d}YnX|p:d}d|j|fS)Nrz[unknown version]z%s %s)rrGr)rrrrr	rJs
zDistribution.__str__cCs.|jdrt|nt|j|S)zADelegate all unrecognized public attributes to .metadata providerr)rrrr])rrkrrr	__getattr__szDistribution.__getattr__cKs(|jt|tjj|||S)N)rrrrr)rOr#rr'rrr	r
szDistribution.from_filenamecCstjd|j|jfS)z?Return a ``Requirement`` that matches this distribution exactlyz%s==%s)rdrrr)rrrr	r	szDistribution.as_requirementcCsD|j||}|dkr:td||ffn|jS)z=Return the `name` entry point of `group` or raise ImportErrorNzEntry point %r not found)rQrrK)rrFr rrrr	rO	szDistribution.load_entry_pointcCsdy
|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_maprrerWrqr)rrFep_maprrr	rP		s

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




zDistribution.insert_oncCs|jdkrdStj|jd}t|j}x|jdD]}|tjksJ||ksJ|tkr}qJn|dkrqJnt	tj|dd}|rt|j
|sJ|j
|jrqJntd|||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)r6rrrqrxrrBrrrr
issue_warning)rnsprmodnamerrrr	r@	s"z#Distribution.check_version_conflictcCs<y|jWn*tk
r7tdt|dSYnXdS)NzUnbuilt egg for FT)rrGrr)rrrr	r&U	s
	zDistribution.has_versioncKsMx*d	D]"}|j|t||dqW|jd|j|j|S)
z@Copy this distribution, substituting in any changed keyword argsrrrrCrrNr)zproject_namezversionz
py_versionzplatformzlocationz
precedence)rrr]r)rr'rkrrr	clone]	s
 zDistribution.clonecCsdd|jDS)NcSsg|]}|r|qSrr)r{deprrr	ri	s	z'Distribution.extras.<locals>.<listcomp>)ry)rrrr	rh	szDistribution.extras)(rrrrrrr.ryrrrXpropertyrfrgrhrirjrkrlrmr6rdrryrrqr{rrrJr|r
r	rOrPrQrrr&rrrrrr	rcGsV			'c@sgeZdZdZdZejdZeddZ	eddZ
dd	Zd
dZdS)
DistInfoDistributionzGWrap an actual or potential sys.path entry w/metadata, .dist-info styleMETADATAz([\(,])\s*(\d.*?)\s*([,\)])cCs\y|jSWnJtk
rWddlm}|j|j|j|_|jSYnXdS)zParse and cache metadatar)ParserN)	_pkg_inforemail.parserrparsestrrrr)rrrrr	_parsed_pkg_infor	s
!z%DistInfoDistribution._parsed_pkg_infocCs: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())rrr^r_EQEQr)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
||	|||	<qW|S)z+Recompute this distribution's dependencies.r)rNz
Requires-Distc3s6x/D]'}|jdi|d6r|VqqWdS)Noverrider`)	marker_fn)r`r)rwrr	reqs_for_extra	s
zBDistInfoDistribution._compute_dependencies.<locals>.reqs_for_extrazProvides-Extra)rrrrget_allrrrkrr	frozensetrrsrr)
rcompile_markerrvrrrrYrcommonr`r)rwr	r	s$z*DistInfoDistribution._compute_dependenciesN)
rrrrrrr^rrrrryrrrrrr	rm	s
rz.eggz	.egg-infoz
.dist-infoc
Os|d}t}y-x&tj|j|kr:|d7}qWWntk
rPYnXddlm}|d|d||dS)Nrr)rE
stacklevel)rrBrrrGrDrE)r;r'levelr(rErrr	r	s	
rc#stt|fdd}xD]}t|}|sUtd|n|jd}|j}g}t||}|r|j}|tt||dd\}}}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
StopIterationrGrrFendCOMMA)ITEM
TERMINATORrrgroups	item_namer$rA)rRrr		scan_list	s0

*#z%parse_requirements.<locals>.scan_listzMissing distribution specrz'extra' namer>zversion speccSs(g|]\}}|t|fqSr)rn)r{rr)rrr	r	s	z&parse_requirements.<locals>.<listcomp>N)r)rr>)iterrqDISTROrGrFrOBRACKETCBRACKETVERSIONLINE_ENDrd)r5rrrArrrrNr)rRr	rk	s"!
$$cCsAdd|D}|jdd|D|ddd<dS)NcSsg|]}|j|fqSr)rf)r{rrrr	r
s	z_sort_dists.<locals>.<listcomp>cSsg|]\}}|qSrr)r{hcdrrr	r
s	rr)r)r$tmprrr	r#	s
r#c@speZdZddZddZddZddZd	d
ZddZd
dZ	e
e	Z	dS)rdcCs|t||_}||j|_|_dd|D}|jdd|D|_|ttt	||_
|_|jtdd|Dt|jf|_
t|j
|_dS)z>DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!cSs2g|](\}}t|t|||fqSr)rl
state_machine)r{rr.rrr	r

s	z(Requirement.__init__.<locals>.<listcomp>cSs(g|]\}}}}||fqSrr)r{rYtransrr^rrr	r
s	cSs(g|]\}}}}||fqSrr)r{rYrrr^rrr	r
s	N)rmunsafe_namer"rr6rrNrDrrsrrrhashCmpre_Requirement__hash)rrrNrrrrr	r
s
"zRequirement.__init__cCsXdjdd|jD}dj|j}|rDd|}nd|j||fS)NrEcSsg|]}dj|qS)r)rD)r{rrrr	r
s	z'Requirement.__str__.<locals>.<listcomp>z[%s]z%s%s%s)rDrNrr)rrNrrrr	rJ
s

zRequirement.__str__cCst|to|j|jkS)N)rrdr)rr)rrr	rl
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|dkrd}n|S)	NFcSs||k||kS)Nr)abrrr	r
$
sz*Requirement.__contains__.<locals>.<lambda>FTT+r])rrcr6rrdrrl)	rrrcomparerYrrr^actionrrr	r
s,		
	zRequirement.__contains__cCs|jS)N)r)rrrr	rg1
szRequirement.__hash__cCsdt|S)NzRequirement.parse(%r))r)rrrr	r4
szRequirement.__repr__cCsWtt|}|rDt|dkr2|dStd|ntd|dS)NrrzExpected only one requirementzNo requirements found)rrkrrG)rrwrrr	r7
szRequirement.parseN)rrrrrJrlrrgrrrMrrrr	rd
sz--T<zT-Tz<=zF+F>zT+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.<locals>.clsN)rrrrrrr	rOO
srOrN)rtypeobject__mro__)rOrrr	_get_mroL
srcCsAx:tt|dt|D]}||kr||SqWdS)z2Return an adapter factory for `ob` from `registry`rN)rrr)registryr7rrrr	rS
s%rcCs8tjj|}tjj|s4tj|ndS)z1Ensure that the parent directory of `path` existsN)rrr"rmakedirs)rr"rrr	rwZ
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``.
    NrM]rzInvalid section headingr)rqrrrrGr)rsectioncontentrrrr	rr`
s	cOsDddlm}tj}ztt_|||SWd|t_XdS)Nr)mkstemp)tempfilerrros_open)r;r'rold_openrrr	ry
s		rcCs@x9ttD]+}|jds
tt|||<q
q
WdS)Nr)r_managerrr)r(r rrr	_initialize
srr)__requires__cCs
|jS)N)r{)rrrr	r

s)rrBrrr^r#rrrDr@rpkgutilrrrrurllib.parserrZsetsrrr	cStringIOrrriorrrrrrrros.pathrrrfimplementationr Zimportlib._bootstrap
_bootstrapimportlib_bootstraprrr%r*r/r1r3r8r9r:
_sget_none
_sset_nonerJ__all__	Exceptionrfrgrhrirrr.ryrzr{r|r}rrMrErr?rr@rrorprLrrNrOrPrQr~rrrar`rrYrjrbr_rmrnrsrtZ
_marker_namesrrgrjrvrurvrrrrrrSourceFileLoaderrrrrr
rrrrr\rrrImpImporter
FileFinderrr)rYrr.r/rxrr%rqrArrrrrrrrFVERBOSE
IGNORECASErbr?rrrBrlrerZrcrrarrkr#rdrrrrwrrrrr__main__rrZrKrrrrrrrrRrr[rrrrrr	<module>s




'

									1)
	






Z	c
	!

( 

,)n	'?
><