U
    9%ex                     @   s&  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZddlmZmZmZ ddlmZmZ ddlmZmZmZmZ ddlmZmZ ddlm Z m!Z! ddlm"Z"m#Z# d d	l$m%Z% d d
l&m'Z' d dl(m)Z) d dlm*Z* d dl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 ddddddddddddgZ2G dd de3Z4G dd dZ5G dd dZ6G dd  d e6Z7G d!d" d"e8Z9G d#d$ d$ej:Z;G d%d& d&Z<G d'd( d(Z=G d)d de=Z>G d*d de)Z?G d+d, d,Z@G d-d. d.ZAG d/d0 d0ZBeG d1d2 d2ee?ZCG d3d4 d4e>ZDeEe>d5d6dZFe,e> d7d8dZGeEej"d5d9dZHeEeEd5d:dZIejJe!ejKd;ZLe9d7d<dZMeEe/e-e;  d5d=dZNeEe/e-eE  d5d>dZOe.eEe-eE f d7d?dZPd@dA ZQe;e/eE dBdCdDZRe;eEdBdEdFZSdGdH ZTdS )I    N   )	_adapters_meta_py39compat)FreezableDefaultDictPair)
NullFinderStrPathinstallpypy_partial)method_cache	pass_none)always_iterableunique_everseen)PackageMetadata
SimplePath)suppress)import_module)MetaPathFinder)starmap)IterableListMappingOptionalSetcastDistributionDistributionFinderr   PackageNotFoundErrordistributiondistributionsentry_pointsfilesmetadatapackages_distributionsrequiresversionc                   @   s0   e Zd ZdZedddZeedddZdS )r   zThe package was not found.returnc                 C   s   d| j  S )Nz"No package metadata was found for nameself r-   Z/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/importlib_metadata/__init__.py__str__7   s    zPackageNotFoundError.__str__c                 C   s   | j \}|S N)argsr,   r*   r-   r-   r.   r*   :   s    zPackageNotFoundError.nameN)__name__
__module____qualname____doc__strr/   propertyr*   r-   r-   r-   r.   r   4   s   c                   @   sJ   e Zd ZdZed Zedd Z	e
dddZe
edd	d
ZdS )	Sectioneda  
    A simple entry point config parser for performance

    >>> for item in Sectioned.read(Sectioned._sample):
    ...     print(item)
    Pair(name='sec1', value='# comments ignored')
    Pair(name='sec1', value='a = 1')
    Pair(name='sec1', value='b = 2')
    Pair(name='sec2', value='a = 2')

    >>> res = Sectioned.section_pairs(Sectioned._sample)
    >>> item = next(res)
    >>> item.name
    'sec1'
    >>> item.value
    Pair(name='a', value='1')
    >>> item = next(res)
    >>> item.value
    Pair(name='b', value='2')
    >>> item = next(res)
    >>> item.name
    'sec2'
    >>> item.value
    Pair(name='a', value='2')
    >>> list(res)
    []
    zm
        [sec1]
        # comments ignored
        a = 1
        b = 2

        [sec2]
        a = 2
        c                 C   s   dd | j || jdD S )Nc                 s   s,   | ]$}|j d k	r|jt|jdV  qd S )N)value)r*   _replacer   parser:   ).0sectionr-   r-   r.   	<genexpr>k   s   
z*Sectioned.section_pairs.<locals>.<genexpr>)filter_)readvalid)clstextr-   r-   r.   section_pairsi   s    zSectioned.section_pairsNc                 c   sX   t |ttj|  }d }|D ]4}|do4|d}|rF|d}qt||V  qd S )N[]z[])filtermapr7   strip
splitlines
startswithendswithr   )rD   r@   linesr*   r:   Zsection_matchr-   r-   r.   rA   q   s    
zSectioned.readlinec                 C   s   | o|  d S )N#)rL   rO   r-   r-   r.   rB   |   s    zSectioned.valid)N)r3   r4   r5   r6   textwrapdedentlstripZ_sampleclassmethodrE   staticmethodrA   r7   rB   r-   r-   r-   r.   r9   @   s   

r9   c                   @   s0   e Zd ZdZejejdee	ddZ
dd ZdS )DeprecatedTuplea  
    Provide subscript item access for backward compatibility.

    >>> recwarn = getfixture('recwarn')
    >>> ep = EntryPoint(name='name', value='value', group='group')
    >>> ep[:]
    ('name', 'value', 'group')
    >>> ep[0]
    'name'
    >>> len(recwarn)
    1
    zAEntryPoint tuple interface is deprecated. Access members by name.   
stacklevelc                 C   s   |    |  | S r0   )_warn_key)r,   itemr-   r-   r.   __getitem__   s    zDeprecatedTuple.__getitem__N)r3   r4   r5   r6   	functoolspartialwarningswarnDeprecationWarningr   r[   r^   r-   r-   r-   r.   rW      s   rW   c                   @   s   e Zd ZU dZedZeed< eed< eed< dZ	e
d ed< eeedd	d
dZdd ZeedddZeedddZeee dddZdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zedd#d$ZdS )%
EntryPointa  An entry point as defined by Python packaging conventions.

    See `the packaging docs on entry points
    <https://packaging.python.org/specifications/entry-points/>`_
    for more information.

    >>> ep = EntryPoint(
    ...     name=None, group=None, value='package.module:attr [extra1, extra2]')
    >>> ep.module
    'package.module'
    >>> ep.attr
    'attr'
    >>> ep.extras
    ['extra1', 'extra2']
    zH(?P<module>[\w.]+)\s*(:\s*(?P<attr>[\w.]+)\s*)?((?P<extras>\[.*\])\s*)?$r*   r:   groupNr   dist)r*   r:   re   r(   c                 C   s   t | j|||d d S )Nr*   r:   re   varsupdate)r,   r*   r:   re   r-   r-   r.   __init__   s    zEntryPoint.__init__c                 C   sD   | j | j}t|d}td|dp,dd}tt	||S )zLoad the entry point from its definition. If only a module
        is indicated by the value, return that module. Otherwise,
        return the named object.
        moduleNattr .)
patternmatchr:   r   re   rH   splitr_   reducegetattr)r,   rq   rl   attrsr-   r-   r.   load   s    zEntryPoint.loadr'   c                 C   s$   | j | j}|d k	st|dS )Nrl   rp   rq   r:   AssertionErrorre   r,   rq   r-   r-   r.   rl      s    zEntryPoint.modulec                 C   s$   | j | j}|d k	st|dS )Nrm   rw   ry   r-   r-   r.   rm      s    zEntryPoint.attrc                 C   s0   | j | j}|d k	sttd|dp,dS )Nz\w+extrasrn   )rp   rq   r:   rx   refindallre   ry   r-   r-   r.   rz      s    zEntryPoint.extrasc                 C   s   t | j|d | S )Nrf   rh   )r,   rf   r-   r-   r.   _for   s    zEntryPoint._forc                    s(    fdd|D }t ttj| |S )a$  
        EntryPoint matches the given parameters.

        >>> ep = EntryPoint(group='foo', name='bar', value='bing:bong [extra1, extra2]')
        >>> ep.matches(group='foo')
        True
        >>> ep.matches(name='bar', value='bing:bong [extra1, extra2]')
        True
        >>> ep.matches(group='foo', name='other')
        False
        >>> ep.matches()
        True
        >>> ep.matches(extras=['extra1', 'extra2'])
        True
        >>> ep.matches(module='bing')
        True
        >>> ep.matches(attr='bong')
        True
        c                 3   s   | ]}t  |V  qd S r0   rt   )r=   paramr+   r-   r.   r?      s     z%EntryPoint.matches.<locals>.<genexpr>)allrI   operatoreqvalues)r,   paramsru   r-   r+   r.   matches   s    zEntryPoint.matchesc                 C   s   | j | j| jfS r0   rg   r+   r-   r-   r.   r\     s    zEntryPoint._keyc                 C   s   |   |  k S r0   r\   r,   otherr-   r-   r.   __lt__  s    zEntryPoint.__lt__c                 C   s   |   |  kS r0   r   r   r-   r-   r.   __eq__  s    zEntryPoint.__eq__c                 C   s   t dd S )Nz!EntryPoint objects are immutable.)AttributeError)r,   r*   r:   r-   r-   r.   __setattr__  s    zEntryPoint.__setattr__c                 C   s   d| j d| jd| jdS )NzEntryPoint(name=z, value=z, group=)rg   r+   r-   r-   r.   __repr__  s    zEntryPoint.__repr__c                 C   s   t |  S r0   )hashr\   r+   r-   r-   r.   __hash__  s    zEntryPoint.__hash__)r3   r4   r5   r6   r{   compilerp   r7   __annotations__rf   r   rk   rv   r8   rl   rm   r   rz   r~   r   r\   r   r   r   r   intr   r-   r-   r-   r.   rd      s0   

rd   c                   @   sp   e Zd ZdZdZeedddZdd Ze	e
e dd	d
Ze	e
e dddZedd Zedd ZdS )EntryPointszC
    An immutable collection of selectable EntryPoint objects.
    r-   r*   r(   c                 C   s8   zt t| j|dW S  tk
r2   t|Y nX dS )z;
        Get the EntryPoint in self matching name.
        r)   N)nextiterselectStopIterationKeyErrorr2   r-   r-   r.   r^     s    zEntryPoints.__getitem__c                    s   t  fdd| D S )zv
        Select entry points from self that match the
        given parameters (typically group and/or name).
        c                 3   s    | ]}t j|f r|V  qd S r0   )r   Z
ep_matchesr=   epr   r-   r.   r?   -  s      z%EntryPoints.select.<locals>.<genexpr>)r   )r,   r   r-   r   r.   r   (  s    zEntryPoints.selectr'   c                 C   s   dd | D S )zB
        Return the set of all names of all entry points.
        c                 S   s   h | ]
}|j qS r-   r)   r   r-   r-   r.   	<setcomp>4  s     z$EntryPoints.names.<locals>.<setcomp>r-   r+   r-   r-   r.   names/  s    zEntryPoints.namesc                 C   s   dd | D S )zC
        Return the set of all groups of all entry points.
        c                 S   s   h | ]
}|j qS r-   )re   r   r-   r-   r.   r   ;  s     z%EntryPoints.groups.<locals>.<setcomp>r-   r+   r-   r-   r.   groups6  s    zEntryPoints.groupsc                    s   |  fdd|  |D S )Nc                 3   s   | ]}|  V  qd S r0   )r~   r   r}   r-   r.   r?   ?  s     z-EntryPoints._from_text_for.<locals>.<genexpr>)
_from_text)rC   rD   rf   r-   r}   r.   _from_text_for=  s    zEntryPoints._from_text_forc                 C   s   dd t | pdD S )Nc                 s   s&   | ]}t |jj|jj|jd V  qdS )rg   N)rd   r:   r*   )r=   r]   r-   r-   r.   r?   C  s   z)EntryPoints._from_text.<locals>.<genexpr>rn   )r9   rE   )rD   r-   r-   r.   r   A  s    zEntryPoints._from_textN)r3   r4   r5   r6   	__slots__r7   rd   r^   r   r8   r   r   r   rU   r   rV   r   r-   r-   r-   r.   r     s   	
r   c                   @   s^   e Zd ZU dZed ed< eed< ded< deedd	d
Ze	dddZ
ejdddZdS )PackagePathz"A reference to a path in a packageFileHashr   sizer   rf   utf-8)encodingr(   c              
   C   s0   |   j|d}| W  5 Q R  S Q R X d S )Nr   locateopenrA   )r,   r   streamr-   r-   r.   	read_textP  s    zPackagePath.read_textr'   c              
   C   s.   |   d}| W  5 Q R  S Q R X d S )Nrbr   )r,   r   r-   r-   r.   read_binaryT  s    zPackagePath.read_binaryc                 C   s   | j | S )z'Return a path-like object for this path)rf   locate_filer+   r-   r-   r.   r   X  s    zPackagePath.locateN)r   )r3   r4   r5   r6   r   r   r   r7   r   bytesr   pathlibPathr   r-   r-   r-   r.   r   I  s   
r   c                   @   s*   e Zd ZeddddZedddZdS )r   N)specr(   c                 C   s   | d\| _}| _d S )N=)	partitionmoder:   )r,   r   _r-   r-   r.   rk   ^  s    zFileHash.__init__r'   c                 C   s   d| j  d| j dS )Nz<FileHash mode: z value: >)r   r:   r+   r-   r-   r.   r   a  s    zFileHash.__repr__)r3   r4   r5   r7   rk   r   r-   r-   r-   r.   r   ]  s   r   c                       s   e Zd Z fddZ  ZS )DeprecatedNonAbstractc                    sL   dd t  D } fdd|D }|r@tjd| tdd t  S )Nc                 S   s   h | ]}t |D ]}|qqS r-   )ri   )r=   subclassr*   r-   r-   r.   r   g  s    
  z0DeprecatedNonAbstract.__new__.<locals>.<setcomp>c                    s"   h | ]}t t  |d dr|qS )__isabstractmethod__Fr   r=   r*   rC   r-   r.   r   j  s   zUnimplemented abstract methods rX   rY   )inspectgetmrora   rb   rc   super__new__)rC   r1   kwargsZ	all_namesZabstract	__class__r   r.   r   f  s    
zDeprecatedNonAbstract.__new__)r3   r4   r5   r   __classcell__r-   r-   r   r.   r   e  s   r   c                   @   sT  e Zd ZdZejee dddZeje	e
jdddZeed dd	d
Zeed  dddZee	d dddZedd ZeejdddZeedddZedd ZeedddZeedddZeeee  dddZdd Z dd  Z!d!d" Z"eeee  dd#d$Z#d%d& Z$d'd( Z%ed)d* Z&ed+d, Z'd-S ).r   zA Python distribution package.r'   c                 C   s   dS )zAttempt to load metadata file given by the name.

        :param filename: The name of the file in the distribution info.
        :return: The text if found, otherwise None.
        Nr-   r,   filenamer-   r-   r.   r   {  s    zDistribution.read_textpathr(   c                 C   s   dS )z[
        Given a path to a file in this distribution, return a path
        to it.
        Nr-   r,   r   r-   r-   r.   r     s    zDistribution.locate_filer   c                 C   sD   |st dztt| j|dW S  tk
r>   t|Y nX dS )a  Return the Distribution for the given package name.

        :param name: The name of the distribution package to search for.
        :return: The Distribution instance (or subclass thereof) for the named
            package, if found.
        :raises PackageNotFoundError: When the named package's distribution
            metadata cannot be found.
        :raises ValueError: When an invalid value is supplied for name.
        z A distribution name is required.r)   N)
ValueErrorr   r   discoverr   r   )rC   r*   r-   r-   r.   	from_name  s    zDistribution.from_namec                    sJ   | dd  r|rtd p*tjf | tj fdd|  D S )a  Return an iterable of Distribution objects for all packages.

        Pass a ``context`` or pass keyword arguments for constructing
        a context.

        :context: A ``DistributionFinder.Context`` object.
        :return: Iterable of Distribution objects for all packages.
        contextNz cannot accept context and kwargsc                 3   s   | ]}| V  qd S r0   r-   )r=   resolverr   r-   r.   r?     s    z(Distribution.discover.<locals>.<genexpr>)popr   r   Context	itertoolschainfrom_iterable_discover_resolvers)rC   r   r-   r   r.   r     s    
zDistribution.discoverc                 C   s   t t| S )zReturn a Distribution for the indicated metadata path

        :param path: a string or path-like object
        :return: a concrete Distribution instance for the path
        )PathDistributionr   r   r   r-   r-   r.   at  s    zDistribution.atc                  C   s   dd t jD } td| S )z#Search the meta_path for resolvers.c                 s   s   | ]}t |d dV  qdS )find_distributionsNr   )r=   finderr-   r-   r.   r?     s    z3Distribution._discover_resolvers.<locals>.<genexpr>N)sys	meta_pathrH   )Zdeclaredr-   r-   r.   r     s    z Distribution._discover_resolversc                 C   s8   |  dp|  dp|  d}tt|}tt|S )zReturn the parsed metadata for this Distribution.

        The returned object will have keys that name the various bits of
        metadata.  See PEP 566 for details.
        METADATAzPKG-INFOrn   )r   r   r7   r   Messageemailmessage_from_string)r,   Zopt_textrD   r-   r-   r.   r#     s    

zDistribution.metadatac                 C   s
   | j d S )z8Return the 'Name' metadata for the distribution package.Namer#   r+   r-   r-   r.   r*     s    zDistribution.namec                 C   s   t | jS )z(Return a normalized version of the name.)Prepared	normalizer*   r+   r-   r-   r.   _normalized_name  s    zDistribution._normalized_namec                 C   s
   | j d S )z;Return the 'Version' metadata for the distribution package.Versionr   r+   r-   r-   r.   r&     s    zDistribution.versionc                 C   s   t | d| S )Nzentry_points.txt)r   r   r   r+   r-   r-   r.   r!     s    zDistribution.entry_pointsc                    sJ   dfdd	 t  fdd}t dd }|| pD pD S )	aZ  Files in this distribution.

        :return: List of PackagePath for this distribution or None

        Result is `None` if the metadata file that enumerates files
        (i.e. RECORD for dist-info, or installed-files.txt or
        SOURCES.txt for egg-info) is missing.
        Result may be empty if the metadata exists but is empty.
        Nc                    s6   t | }|rt|nd |_|r&t|nd |_ |_|S r0   )r   r   r   r   r   rf   )r*   r   Zsize_strresultr+   r-   r.   	make_file  s
    z%Distribution.files.<locals>.make_filec                    s   t  t| S r0   )r   csvreader)rN   )r   r-   r.   
make_files  s    z&Distribution.files.<locals>.make_filesc                 S   s   t tdd | S )Nc                 S   s   |    S r0   )r   existsr   r-   r-   r.   <lambda>      z@Distribution.files.<locals>.skip_missing_files.<locals>.<lambda>)listrH   )Zpackage_pathsr-   r-   r.   skip_missing_files  s    z.Distribution.files.<locals>.skip_missing_files)NN)r   _read_files_distinfo_read_files_egginfo_installed_read_files_egginfo_sources)r,   r   r   r-   )r   r,   r.   r"     s    
zDistribution.filesc                 C   s   |  d}|o| S )z*
        Read the lines of RECORD
        RECORD)r   rK   r,   rD   r-   r-   r.   r     s    
z!Distribution._read_files_distinfoc                    sF     d}t dd|rs"dS  fdd| D }tdj|S )a  
        Read installed-files.txt and return lines in a similar
        CSV-parsable format as RECORD: each file must be placed
        relative to the site-packages directory and must also be
        quoted (since file names can contain literal commas).

        This file is written when the package is installed by pip,
        but it might not be written for other installation methods.
        Assume the file is accurate if it exists.
        zinstalled-files.txt_pathNc                 3   s.   | ]&}|    d    V  qdS )rn   N)resolverelative_tor   as_posixr   r,   subdirr-   r.   r?   !  s   z=Distribution._read_files_egginfo_installed.<locals>.<genexpr>"{}")r   rt   rK   rI   format)r,   rD   pathsr-   r   r.   r     s    
z*Distribution._read_files_egginfo_installedc                 C   s   |  d}|otdj| S )a  
        Read SOURCES.txt and return lines in a similar CSV-parsable
        format as RECORD: each file name must be quoted (since it
        might contain literal commas).

        Note that SOURCES.txt is not a reliable source for what
        files are installed by a package. This file is generated
        for a source archive, and the files that are present
        there (e.g. setup.py) may not correctly reflect the files
        that are present after the package has been installed.
        zSOURCES.txtr   )r   rI   r  rK   r   r-   r-   r.   r   *  s    
z(Distribution._read_files_egginfo_sourcesc                 C   s   |   p|  }|ot|S )z6Generated requirements specified for this Distribution)_read_dist_info_reqs_read_egg_info_reqsr   )r,   reqsr-   r-   r.   r%   9  s    zDistribution.requiresc                 C   s   | j dS )NzRequires-Dist)r#   get_allr+   r-   r-   r.   r  ?  s    z!Distribution._read_dist_info_reqsc                 C   s   |  d}t| j|S )Nzrequires.txt)r   r   _deps_from_requires_text)r,   sourcer-   r-   r.   r  B  s    
z Distribution._read_egg_info_reqsc                 C   s   |  t|S r0   )%_convert_egg_info_reqs_to_simple_reqsr9   rA   )rC   r  r-   r-   r.   r  F  s    z%Distribution._deps_from_requires_textc                 #   sJ   dd   fdd}dd }| D ]$}||j }|j | ||j V  q dS )a  
        Historically, setuptools would solicit and store 'extra'
        requirements, including those with environment markers,
        in separate sections. More modern tools expect each
        dependency to be defined separately, with any relevant
        extras and environment markers attached directly to that
        requirement. This method converts the former to the
        latter. See _test_deps_from_requires_text for an example.
        c                 S   s   | od|  dS )Nz
extra == ""r-   r)   r-   r-   r.   make_conditionV  s    zJDistribution._convert_egg_info_reqs_to_simple_reqs.<locals>.make_conditionc                    sX   | pd} |  d\}}}|r,|r,d| d}ttd | |g}|rTdd| S dS )Nrn   :(r   z; z and )r   r   rH   join)r>   extrasepmarkersZ
conditionsr  r-   r.   quoted_markerY  s    zIDistribution._convert_egg_info_reqs_to_simple_reqs.<locals>.quoted_markerc                 S   s   dd| k S )z
            PEP 508 requires a space between the url_spec and the quoted_marker.
            Ref python/importlib_metadata#357.
             @r-   )reqr-   r-   r.   url_req_spacea  s    zIDistribution._convert_egg_info_reqs_to_simple_reqs.<locals>.url_req_spaceN)r:   r*   )sectionsr  r  r>   spacer-   r  r.   r	  J  s    
z2Distribution._convert_egg_info_reqs_to_simple_reqsN)(r3   r4   r5   r6   abcabstractmethodr   r7   r   r	   r   r   r   rU   r   r   r   rV   r   r   r8   r   r   r#   r*   r   r&   r   r!   r   r   r"   r   r   r   r%   r  r  r  r	  r-   r-   r-   r.   r   x  sH   

"
c                   @   s<   e Zd ZdZG dd dZeje fee dddZ	dS )r   zJ
    A MetaPathFinder capable of discovering installed distributions.
    c                   @   s2   e Zd ZdZdZdd Zeee dddZ	dS )zDistributionFinder.Contextaw  
        Keyword arguments presented by the caller to
        ``distributions()`` or ``Distribution.discover()``
        to narrow the scope of a search for distributions
        in all DistributionFinders.

        Each DistributionFinder may expect any parameters
        and should attempt to honor the canonical
        parameters defined below when appropriate.
        Nc                 K   s   t | | d S r0   rh   )r,   r   r-   r-   r.   rk     s    z#DistributionFinder.Context.__init__r'   c                 C   s   t | dtjS )z
            The sequence of directory path that a distribution finder
            should search.

            Typically refers to Python installed package paths such as
            "site-packages" directories and defaults to ``sys.path``.
            r   )ri   getr   r   r+   r-   r-   r.   r     s    	zDistributionFinder.Context.path)
r3   r4   r5   r6   r*   rk   r8   r   r7   r   r-   r-   r-   r.   r   s  s
   r   r'   c                 C   s   dS )z
        Find distributions.

        Return an iterable of all Distribution instances capable of
        loading the metadata for packages matching the ``context``,
        a DistributionFinder.Context instance.
        Nr-   )r,   r   r-   r-   r.   r     s    z%DistributionFinder.find_distributionsN)
r3   r4   r5   r6   r   r  r  r   r   r   r-   r-   r-   r.   r   n  s    c                       sh   e Zd ZdZe  fddZdd Zdd Zdd	 Z	d
d Z
dd Zedd Zedd Z  ZS )FastPathzs
    Micro-optimized class for searching a path for
    children.

    >>> FastPath('').children()
    ['...']
    c                    s   t  | S r0   )r   r   )rC   rootr   r-   r.   r     s    zFastPath.__new__c                 C   s
   || _ d S r0   )r  )r,   r  r-   r-   r.   rk     s    zFastPath.__init__c                 C   s   t | j|S r0   )r   r   r  )r,   childr-   r-   r.   joinpath  s    zFastPath.joinpathc              
   C   sT   t t t| jpdW  5 Q R  S Q R X t t |  W  5 Q R  S Q R X g S Nro   )r   	Exceptionoslistdirr  zip_childrenr+   r-   r-   r.   children  s
    
"
zFastPath.childrenc                 C   s2   t | j}|j }|j| _tdd |D S )Nc                 s   s    | ]}| tjd d V  qdS )r   r   N)rr   	posixpathr  )r=   r  r-   r-   r.   r?     s     z(FastPath.zip_children.<locals>.<genexpr>)zippr   r  namelistr   dictfromkeys)r,   zip_pathr   r-   r-   r.   r%    s    
zFastPath.zip_childrenc                 C   s   |  | j|S r0   )lookupmtimesearchr2   r-   r-   r.   r/    s    zFastPath.searchc              
   C   s8   t t t| jjW  5 Q R  S Q R X | j  d S r0   )r   OSErrorr#  statr  st_mtimer-  cache_clearr+   r-   r-   r.   r.    s    
 zFastPath.mtimec                 C   s   t | S r0   )Lookup)r,   r.  r-   r-   r.   r-    s    zFastPath.lookup)r3   r4   r5   r6   r_   	lru_cacher   rk   r   r&  r%  r/  r8   r.  r   r-  r   r-   r-   r   r.   r    s   
r  c                   @   s"   e Zd ZedddZdd ZdS )r4  r   c           	      C   s   t j|j }|d}tt| _tt| _	|
 D ]}| }|dr|dd dd }t|}| j| || q8|r8|dkr8|dd dd }t|}| j	| || q8| j  | j	  d S )Nz.eggz
.dist-infoz	.egg-inforo   r   -zegg-info)r#  r   basenamer  lowerrM   r   r   infoseggsr&  
rpartitionr   r   r   appendr   legacy_normalizefreeze)	r,   r   baseZbase_is_eggr  lowr*   
normalizedlegacy_normalizedr-   r-   r.   rk     s     






zLookup.__init__c                 C   sP   |r| j |j ntj| j  }|r2| j|j ntj| j }t||S r0   )r:  rB  r   r   r   r   r;  rC  )r,   preparedr:  r;  r-   r-   r.   r/    s    zLookup.searchN)r3   r4   r5   r  rk   r/  r-   r-   r-   r.   r4    s   r4  c                   @   s@   e Zd ZdZdZdZdd Zedd Zedd Z	d	d
 Z
dS )r   zE
    A prepared search for metadata on a possibly-named package.
    Nc                 C   s.   || _ |d krd S | || _| || _d S r0   )r*   r   rB  r>  rC  r2   r-   r-   r.   rk     s
    zPrepared.__init__c                 C   s   t dd|  ddS )zC
        PEP 503 normalization plus dashes as underscores.
        z[-_.]+r7  r   )r{   subr9  replacer)   r-   r-   r.   r      s    zPrepared.normalizec                 C   s   |   ddS )z|
        Normalize the package name as found in the convention in
        older packaging tools versions and specs.
        r7  r   )r9  rF  r)   r-   r-   r.   r>    s    zPrepared.legacy_normalizec                 C   s
   t | jS r0   )boolr*   r+   r-   r-   r.   __bool__  s    zPrepared.__bool__)r3   r4   r5   r6   rB  rC  rk   rV   r   r>  rH  r-   r-   r-   r.   r     s   

r   c                   @   sD   e Zd ZdZe fed dddZedd Z	ddd	d
Z
dS )MetadataPathFinderzA degenerate finder for distribution packages on the file system.

    This finder supplies only a find_distributions() method for versions
    of Python that do not have a PathFinder find_distributions().
    r   r'   c                 C   s   |  |j|j}tt|S )a   
        Find distributions.

        Return an iterable of all Distribution instances capable of
        loading the metadata for packages matching ``context.name``
        (or all names if ``None`` indicated) along the paths in the list
        of directories ``context.path``.
        )_search_pathsr*   r   rI   r   )r,   r   foundr-   r-   r.   r     s    z%MetadataPathFinder.find_distributionsc                    s(   t | tj fddtt|D S )z1Find metadata directories in paths heuristically.c                 3   s   | ]}|  V  qd S r0   )r/  )r=   r   rD  r-   r.   r?   -  s    z3MetadataPathFinder._search_paths.<locals>.<genexpr>)r   r   r   r   rI   r  )rC   r*   r  r-   rL  r.   rJ  )  s    z MetadataPathFinder._search_pathsNc                 C   s   t j  d S r0   )r  r   r3  r   r-   r-   r.   invalidate_caches1  s    z$MetadataPathFinder.invalidate_caches)r3   r4   r5   r6   r   r   r   r   rU   rJ  rM  r-   r-   r-   r.   rI    s   
rI  c                       sl   e Zd ZeddddZeee dddZe	jj
e_
eejddd	Ze fd
dZedd Z  ZS )r   Nr   c                 C   s
   || _ dS )zfConstruct a distribution.

        :param path: SimplePath indicating the metadata directory.
        N)r   r   r-   r-   r.   rk   6  s    zPathDistribution.__init__)r   r(   c              
   C   s<   t ttttt" | j|jddW  5 Q R  S Q R X d S )Nr   r   )	r   FileNotFoundErrorIsADirectoryErrorr   NotADirectoryErrorPermissionErrorr   r   r   r   r-   r-   r.   r   =  s    &zPathDistribution.read_textc                 C   s   | j j| S r0   )r   parentr   r-   r-   r.   r   K  s    zPathDistribution.locate_filec                    s.   t jt| j}ttj| |p,t	 j
S )zz
        Performance optimization: where possible, resolve the
        normalized name from the file system path.
        )r#  r   r8  r7   r   r   r   r   _name_from_stemr   r   )r,   stemr   r-   r.   r   N  s    z!PathDistribution._normalized_namec                 C   s0   t j| \}}|dkrdS |d\}}}|S )a7  
        >>> PathDistribution._name_from_stem('foo-3.0.egg-info')
        'foo'
        >>> PathDistribution._name_from_stem('CherryPy-3.0.dist-info')
        'CherryPy'
        >>> PathDistribution._name_from_stem('face.egg-info')
        'face'
        >>> PathDistribution._name_from_stem('foo.bar')
        r6  Nr7  )r#  r   splitextr   )rT  r   extr*   r  restr-   r-   r.   rS  Z  s
    z PathDistribution._name_from_stem)r3   r4   r5   r   rk   r	   r   r7   r   r   r6   r   r   r   r8   r   rV   rS  r   r-   r-   r   r.   r   5  s   
r   )distribution_namer(   c                 C   s
   t | S )zGet the ``Distribution`` instance for the named package.

    :param distribution_name: The name of the distribution package as a string.
    :return: A ``Distribution`` instance (or subclass thereof).
    )r   r   rX  r-   r-   r.   r   l  s    r'   c                  K   s   t jf | S )z|Get all ``Distribution`` instances in the current environment.

    :return: An iterable of ``Distribution`` instances.
    )r   r   )r   r-   r-   r.   r    u  s    c                 C   s   t | jS )zGet the metadata for the named package.

    :param distribution_name: The name of the distribution package to query.
    :return: A PackageMetadata containing the parsed metadata.
    )r   r   r#   rY  r-   r-   r.   r#   }  s    c                 C   s
   t | jS )zGet the version string for the named package.

    :param distribution_name: The name of the distribution package to query.
    :return: The version string for the package as defined in the package's
        "Version" metadata key.
    )r   r&   rY  r-   r-   r.   r&     s    )keyc                  K   s,   t jdd tt D }t|jf | S )a  Return EntryPoint objects for all installed packages.

    Pass selection parameters (group or name) to filter the
    result to entry points matching those properties (see
    EntryPoints.select()).

    :return: EntryPoints for all installed packages.
    c                 s   s   | ]}|j V  qd S r0   )r!   )r=   rf   r-   r-   r.   r?     s    zentry_points.<locals>.<genexpr>)r   r   r   _uniquer    r   r   )r   Zepsr-   r-   r.   r!     s    	c                 C   s
   t | jS )zReturn a list of files for the named package.

    :param distribution_name: The name of the distribution package to query.
    :return: List of files composing the distribution.
    )r   r"   rY  r-   r-   r.   r"     s    c                 C   s
   t | jS )z
    Return a list of requirements for the named package.

    :return: An iterable of requirements, suitable for
        packaging.requirement.Requirement.
    )r   r%   rY  r-   r-   r.   r%     s    c                  C   sH   t t} t D ].}t|p"t|D ]}| | |jd  q$qt| S )z
    Return a mapping of top-level packages to their
    distributions.

    >>> import collections.abc
    >>> pkgs = packages_distributions()
    >>> all(isinstance(dist, collections.abc.Sequence) for dist in pkgs.values())
    True
    r   )	collectionsdefaultdictr   r    _top_level_declared_top_level_inferredr=  r#   r*  )Zpkg_to_distrf   pkgr-   r-   r.   r$     s
    


c                 C   s   |  dpd S )Nztop_level.txtrn   )r   rr   r}   r-   r-   r.   r^    s    r^  r   c                 C   s   | j ^}}|r|S dS )zB
    Return the top-most parent as long as there is a parent.
    N)parts)r*   toprW  r-   r-   r.   _topmost  s    
rc  c                 C   s   t | pt| pt| S )a  
    Infer a possibly importable module name from a name presumed on
    sys.path.

    >>> _get_toplevel_name(PackagePath('foo.py'))
    'foo'
    >>> _get_toplevel_name(PackagePath('foo'))
    'foo'
    >>> _get_toplevel_name(PackagePath('foo.pyc'))
    'foo'
    >>> _get_toplevel_name(PackagePath('foo/__init__.py'))
    'foo'
    >>> _get_toplevel_name(PackagePath('foo.pth'))
    'foo.pth'
    >>> _get_toplevel_name(PackagePath('foo.dist-info'))
    'foo.dist-info'
    )rc  r   getmodulenamer7   r)   r-   r-   r.   _get_toplevel_name  s    
re  c                 C   s&   t ttt| j}dd }t||S )Nc                 S   s   d| kS r!  r-   r)   r-   r-   r.   importable_name  s    z,_top_level_inferred.<locals>.importable_name)setrI   re  r   r"   rH   )rf   	opt_namesrf  r-   r-   r.   r_    s    r_  )Ur#  r{   r  r   r   r(  r   r   r   r   rR   ra   r_   r   r'  r\  rn   r   r   r   _collectionsr   r   Z_compatr   r	   r
   r   
_functoolsr   r   
_itertoolsr   r   r   r   
contextlibr   	importlibr   importlib.abcr   r   typingr   r   r   r   r   r   __all__ModuleNotFoundErrorr   r9   rW   rd   tupler   PurePosixPathr   r   r   r   r   r  r4  r   rI  r   r7   r   r    r#   r&   r`   normalized_namer[  r!   r"   r%   r$   r^  rc  re  r_  r-   r-   r-   r.   <module>   s    A|1 w0/$"!7		
		
