a
    ep                     @   s  d dl m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 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 d d	lmZmZmZ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- d dl.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7m8Z8 er\d dlm9Z: nd dlm:Z: e4rd dl;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZG d dlHmIZI eEeJeJeJf ZKeFdZLg dZMeNeOZPdd ZQdd ZRdd ZSdd ZTed d!d"dd$d%ZUd&d' ZVd(d) ZWd*d+ ZXdd-d.ZYd/d0 ZZd1d2 Z[d3d4 Z\d5d6 Z]d7d8 Z^d9d: Z_d;d< Z`d=d> Zaejbfd?d@ZcddBdCZddDdE ZedFdG ZfdHdI ZgdJdK ZhdLdM ZidNdO ZjdPdQ ZkdAe1dAd#d#dfdRdSZldTdU ZmdVdW ZndXdY ZodZd[ Zpd\d] ZqG d^d_ d_erZsG d`da dae:Ztejudbdc Zvddde Zwdfdg ZxddhdiZydjdk Zzdldm Z{dndo Z|ddqdrZ}dsdt Z~dudv Zdwdx Zdydz Zd{d| Zd}d~ Zdd Zdd Zdd ZG dd derZdd Zdd Zdd Zdd ZdddZdd Zdd Zdd ZdS )    )absolute_importNdeque)tee)pkg_resources)canonicalize_name)retry)PY2	text_type)filterfilterfalseinputmapzip_longest)parse)unquote)__version__)CommandError)get_major_minor_versionsite_packages	user_site)WINDOWS
expanduserstdlib_pkgsstr_to_display)MYPY_CHECK_RUNNINGcast)running_under_virtualenvvirtualenv_no_global)BytesIO)StringIO)AnyAnyStrCallable	ContainerIterableIteratorListOptionalTextTupleTypeVarUnion)DistributionT)rmtreedisplay_path
backup_dirasksplitextformat_sizeis_installable_dirnormalize_pathrenamesget_progcaptured_stdout
ensure_dirget_installed_versionremove_auth_from_urlc                  C   s4   t jt jtdd} t j| } dt| t S )Nz..zpip {} from {} (python {}))	ospathjoindirname__file__abspathformatr   r   )Zpip_pkg_dir rD   L/var/www/sunrise/env/lib/python3.9/site-packages/pip/_internal/utils/misc.pyget_pip_versionQ   s    rF   c                 C   sD   t | dk r"| dt |  d 7 } nt | dkr:| dd } td| S )ax  
    Convert a tuple of ints representing a Python version to one of length
    three.

    :param py_version_info: a tuple of ints representing a Python version,
        or None to specify no version. The tuple can have any length.

    :return: a tuple of length three if `py_version_info` is non-None.
        Otherwise, return `py_version_info` unchanged (i.e. None).
       )r   NVersionInfo)lenr   )py_version_inforD   rD   rE   normalize_version_info]   s
    rK   c              
   C   sR   zt |  W n> tyL } z&|jtjkr8|jtjkr8 W Y d}~n
d}~0 0 dS )z os.path.makedirs without EEXIST.N)r=   makedirsOSErrorerrnoEEXISTZ	ENOTEMPTY)r>   erD   rD   rE   r:   q   s
    r:   c               
   C   sP   z2t jtjd } | dv r*dtjW S | W S W n ttt	fyJ   Y n0 dS )Nr   )z__main__.pyz-cz	{} -m pippip)
r=   r>   basenamesysargvrC   
executableAttributeError	TypeError
IndexError)progrD   rD   rE   r8   |   s    
r8   i  i  )stop_max_delay
wait_fixedFc                 C   s   t j| |td d S )N)ignore_errorsonerror)shutilr/   rmtree_errorhandler)dirr\   rD   rD   rE   r/      s    r/   c              	   C   sV   zt |jtj@  }W n ttfy0   Y dS 0 |rPt |tj | | dS  dS )zOn Windows, the files in .svn are read-only, so when rmtree() tries to
    remove them, an exception is thrown.  We catch that here, remove the
    read-only attribute, and hopefully continue without problems.N)r=   statst_modeS_IWRITEIOErrorrM   chmod)funcr>   exc_infoZhas_attr_readonlyrD   rD   rE   r_      s    r_   c                 C   sb   | du rdS t | tr| S z| t d}W n. ty\   trPtd| }nt	| }Y n0 |S )z
    Convert a bytes (or text) path to text (unicode in Python 2) for display
    and logging purposes.

    This function should never error out. Also, this function is mainly needed
    for Python 2 since in Python 3 str paths are already text.
    Nstrictzb{!r})

isinstancer
   decoderS   getfilesystemencodingUnicodeDecodeErrorr	   r   rC   ascii)r>   r0   rD   rD   rE   path_to_display   s    	
rn   c                 C   st   t jt j| } tjd dkrB| t d} | t	 d} | 
t  t jj rpd| tt  d  } | S )zTGives the display value for a given path, making it relative to cwd
    if possible.r      replace.N)r=   r>   normcaserB   rS   version_inforj   rk   encodegetdefaultencoding
startswithgetcwdseprI   )r>   rD   rD   rE   r0      s    r0   .bakc                 C   s6   d}|}t j| | r.|d7 }|t| }q| | S )z\Figure out the name of a directory to back up the given dir to
    (adding .bak, .bak2, etc)   )r=   r>   existsstr)r`   extn	extensionrD   rD   rE   r1      s    r1   c                 C   s2   t jdd D ]}||v r|  S qt| |S )NZPIP_EXISTS_ACTION )r=   environgetsplitr2   )messageoptionsactionrD   rD   rE   ask_path_exists   s    
r   c                 C   s   t jdrtd| dS )z&Raise an error if no input is allowed.ZPIP_NO_INPUTz7No input was expected ($PIP_NO_INPUT set); question: {}N)r=   r   r   	ExceptionrC   r   rD   rD   rE   _check_no_input   s    r   c                 C   sF   t |  t| }|  }||vr<td|d| q |S q dS )z@Ask the message interactively, with the given possible responsesz>Your response ({!r}) was not one of the expected responses: {}z, N)r   r   striplowerprintrC   r?   )r   r   responserD   rD   rE   r2      s    
r2   c                 C   s   t |  t| S )zAsk for input interactively.)r   r   r   rD   rD   rE   	ask_input  s    r   c                 C   s   t |  t| S )z!Ask for a password interactively.)r   getpassr   rD   rD   rE   ask_password	  s    r   c                 C   s\   | dkrd | d d S | dkr4d t| d S | dkrJd | d S d t| S d S )	Ni@B z	{:.1f} MBg     @@i  i'  z{} kBz	{:.1f} kBz{} bytes)rC   int)bytesrD   rD   rE   r4     s    r4   c                    s@   dd | D } dd t | ddiD   fdd| D }| fS )zReturn a list of formatted rows and a list of column sizes.

    For example::

    >>> tabulate([['foobar', 2000], [0xdeadbeef]])
    (['foobar     2000', '3735928559'], [10, 4])
    c                 S   s   g | ]}t tt|qS rD   )tupler   r|   .0rowrD   rD   rE   
<listcomp>%      ztabulate.<locals>.<listcomp>c                 S   s   g | ]}t tt|qS rD   )maxr   rI   )r   colrD   rD   rE   r   &  r   	fillvaluer   c                    s$   g | ]}d  ttj|  qS ) )r?   r   r|   ljustrstripr   ZsizesrD   rE   r   '  r   )r   )ZrowstablerD   r   rE   tabulate  s    	r   c                 C   sP   t j| sdS t j| d}t j|r.dS t j| d}t j|rLdS dS )zBIs path is a directory containing setup.py or pyproject.toml?
    Fzsetup.pyTzpyproject.toml)r=   r>   isdirr?   isfile)r>   Zsetup_pyZpyproject_tomlrD   rD   rE   r5   +  s    r5   c                 c   s   |  |}|sq|V  q dS )z7Yield pieces of data from a file-like object until EOF.N)read)filesizechunkrD   rD   rE   read_chunks:  s    
r   Tc                 C   s2   t | } |rtj| } ntj| } tj| S )zN
    Convert a path to its canonical, case-normalized, absolute version.

    )r   r=   r>   realpathrB   rr   )r>   Zresolve_symlinksrD   rD   rE   r6   C  s
    r6   c                 C   s@   t | \}}| dr8|dd | }|dd }||fS )z,Like os.path.splitext, but take off .tar tooz.tarN)	posixpathr3   r   endswith)r>   baser}   rD   rD   rE   r3   Q  s
    r3   c                 C   sx   t j|\}}|r.|r.t j|s.t | t| | t j| \}}|rt|rtzt | W n tyr   Y n0 dS )z7Like os.renames(), but handles renaming across devices.N)	r=   r>   r   r{   rL   r^   move
removedirsrM   )oldnewheadtailrD   rD   rE   r7   [  s    
r7   c                 C   sj   t | } d}t r"| t tjS ddlm} | |rb|d D ]}| t |rD dS qDdS dS dS )a  
    Return True if this is a path pip is allowed to modify.

    If we're in a virtualenv, sys.prefix points to the virtualenv's
    prefix; only sys.prefix is considered local.

    If we're not in a virtualenv, in general we can modify anything.
    However, if the OS vendor has configured distutils to install
    somewhere other than sys.prefix (which could be a subdirectory of
    sys.prefix, e.g. /usr/local), we consider sys.prefix itself nonlocal
    and the domain of the OS vendor. (In other words, everything _other
    than_ sys.prefix is considered local.)

    Caution: this function assumes the head of path has been normalized
    with normalize_path.
    z/usrr   )distutils_schemer   TFN)r6   r   rv   rS   prefixpip._internal.locationsr   values)r>   r   r   Z
local_pathrD   rD   rE   is_localm  s    
r   c                 C   s   t t| S )zh
    Return True if given Distribution object is installed somewhere pip
    is allowed to modify.

    )r   dist_locationdistrD   rD   rE   dist_is_local  s    r   c                 C   s   t | ttS )zF
    Return True if given Distribution is installed in user site.
    )r   rv   r6   r   r   rD   rD   rE   dist_in_usersite  s    r   c                 C   s   t | ttS )z[
    Return True if given Distribution is installed in
    sysconfig.get_python_lib().
    )r   rv   r6   r   r   rD   rD   rE   dist_in_site_packages  s    r   c                 C   s   t t| S )zC
    Return True if given Distribution is an editable install.
    )boolegg_link_pathr   rD   rD   rE   dist_is_editable  s    r   c                    s   |rt |}nt j}| r tndd |r6dd  ndd  |rLdd ndd |r^tnd	d
  fdd|D S )a^  
    Return a list of installed Distribution objects.

    If ``local_only`` is True (default), only return installations
    local to the current virtualenv, if in a virtualenv.

    ``skip`` argument is an iterable of lower-case project names to
    ignore; defaults to stdlib_pkgs

    If ``include_editables`` is False, don't report editables.

    If ``editables_only`` is True , only report editables.

    If ``user_only`` is True , only report installations in the user
    site directory.

    If ``paths`` is set, only report the distributions present at the
    specified list of locations.
    c                 S   s   dS NTrD   drD   rD   rE   
local_test  s    z/get_installed_distributions.<locals>.local_testc                 S   s   dS r   rD   r   rD   rD   rE   editable_test  s    z2get_installed_distributions.<locals>.editable_testc                 S   s
   t |  S Nr   r   rD   rD   rE   r     s    c                 S   s   t | S r   r   r   rD   rD   rE   editables_only_test  s    z8get_installed_distributions.<locals>.editables_only_testc                 S   s   dS r   rD   r   rD   rD   rE   r     s    c                 S   s   dS r   rD   r   rD   rD   rE   	user_test  s    z.get_installed_distributions.<locals>.user_testc                    s:   g | ]2}|r|j vr |r|r|r|qS rD   )key)r   r   r   r   r   skipr   rD   rE   r     s   
z/get_installed_distributions.<locals>.<listcomp>)r   
WorkingSetworking_setr   r   )
local_onlyr   include_editableseditables_only	user_onlypathsr   rD   r   rE   get_installed_distributions  s     

r   c                 C   s4   t | } tddddddd}dd |D }|| S )zFind a distribution matching the ``req_name`` in the environment.

    This searches from *all* distributions available in the environment, to
    match the behavior of ``pkg_resources.get_distribution()``.
    FrD   TN)r   r   r   r   r   r   c                 S   s   i | ]}t |j|qS rD   )r   r   )r   prD   rD   rE   
<dictcomp>  r   z(_search_distribution.<locals>.<dictcomp>)r   r   r   )req_namepackagesZpkg_dictrD   rD   rE   _search_distribution  s    
r   c                 C   s<   t | }|s4ztj|  W n tjy2   Y dS 0 t | S )zGiven a requirement name, return the installed Distribution object.

    This searches from *all* distributions available in the environment, to
    match the behavior of ``pkg_resources.get_distribution()``.
    N)r   r   r   requireDistributionNotFound)r   r   rD   rD   rE   get_distribution  s    	r   c                 C   sx   g }t  r*|t t sBtrB|t ntr8|t |t |D ],}tj|| jd }tj	|rF|  S qFdS )a  
    Return the path for the .egg-link file if it exists, otherwise, None.

    There's 3 scenarios:
    1) not in a virtualenv
       try to find in site.USER_SITE, then site_packages
    2) in a no-global virtualenv
       try to find in site_packages
    3) in a yes-global virtualenv
       try to find in site_packages, then site.USER_SITE
       (don't look in global location)

    For #1 and #3, there could be odd cases, where there's an egg-link in 2
    locations.

    This method will just return the first one found.
    z	.egg-linkN)
r   appendr   r   r   r=   r>   r?   project_namer   )r   ZsitessiteZegglinkrD   rD   rE   r   +  s    




r   c                 C   s   t | }|rt|S t| jS )aO  
    Get the site-packages location of this distribution. Generally
    this is dist.location, except in the case of develop-installed
    packages, where dist.location is the source code location, and we
    want to know where the egg-link file is.

    The returned location is normalized (in particular, with symlinks removed).
    )r   r6   location)r   Zegg_linkrD   rD   rE   r   O  s    
r   c                 G   s   t j| g|R   d S r   )loggerinfo)msgargsrD   rD   rE   write_output_  s    r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	FakeFilezQWrap a list of lines in an object with readline() to make
    ConfigParser happy.c                 C   s   t || _d S r   )iter_gen)selflinesrD   rD   rE   __init__g  s    zFakeFile.__init__c                 C   s&   zt | jW S  ty    Y dS 0 d S )Nr   )nextr   StopIterationr   rD   rD   rE   readlinej  s    zFakeFile.readlinec                 C   s   | j S r   )r   r   rD   rD   rE   __iter__p  s    zFakeFile.__iter__N)__name__
__module____qualname____doc__r   r   r   rD   rD   rD   rE   r   d  s   r   c                   @   s$   e Zd Zedd Zedd ZdS )StreamWrapperc                 C   s   || _ |  S r   )orig_stream)clsr   rD   rD   rE   from_streamv  s    zStreamWrapper.from_streamc                 C   s   | j jS r   )r   encodingr   rD   rD   rE   r   |  s    zStreamWrapper.encodingN)r   r   r   classmethodr   propertyr   rD   rD   rD   rE   r   t  s   
r   c              
   c   sL   t t| }tt| t| zt t| V  W tt| | ntt| | 0 dS )zReturn a context manager used by captured_stdout/stdin/stderr
    that temporarily replaces the sys stream *stream_name* with a StringIO.

    Taken from Lib/support/__init__.py in the CPython repo.
    N)getattrrS   setattrr   r   )Zstream_nameorig_stdoutrD   rD   rE   captured_output  s
    
r  c                   C   s   t dS )zCapture the output of sys.stdout:

       with captured_stdout() as stdout:
           print('hello')
       self.assertEqual(stdout.getvalue(), 'hello
')

    Taken from Lib/support/__init__.py in the CPython repo.
    stdoutr  rD   rD   rD   rE   r9     s    	r9   c                   C   s   t dS )z 
    See captured_stdout().
    stderrr  rD   rD   rD   rE   captured_stderr  s    r  c                 C   s4   t j| }|du rt  }||}|r0|jS dS )zCGet the installed version of dist_name avoiding pkg_resources cacheN)r   Requirementr   r   findversion)Z	dist_namer   reqr   rD   rD   rE   r;     s
    
r;   c                 C   s   t | dd dS )zConsume an iterable at C speed.r   )maxlenNr   )iteratorrD   rD   rE   consume  s    r  c                  O   sD   t t| tt| fi |}dd | D }||d< tdd|S )Nc                 S   s   i | ]\}}||qS rD   rD   )r   r   valuerD   rD   rE   r     r   zenum.<locals>.<dictcomp>Zreverse_mappingEnumrD   )dictziprangerI   itemstype)Z
sequentialnamedenumsreverserD   rD   rE   enum  s    r  c                 C   s*   |du r| S d| v rd | } d | |S )z.
    Build a netloc from a host-port pair
    N:[{}]z{}:{})rC   )hostportrD   rD   rE   build_netloc  s
    
r  httpsc                 C   s4   |  ddkr(d| vr(d| vr(d| } d|| S )z)
    Build a full URL from a netloc.
    r  ro   @[r  z{}://{})countrC   )netlocschemerD   rD   rE   build_url_from_netloc  s    
r#  c                 C   s   t | }t|}|j|jfS )z2
    Return the host-port pair from a netloc.
    )r#  urllib_parseurlparsehostnamer  )r!  urlparsedrD   rD   rE   parse_netloc  s    
r)  c                 C   sX   d| vr| dfS |  dd\}} d|v r6|dd}n|df}tdd |D }| |fS )zp
    Parse out and remove the auth information from a netloc.

    Returns: (netloc, (username, password)).
    r  )NNrz   r  Nc                 s   s"   | ]}|d u rd nt |V  qd S r   )urllib_unquote)r   xrD   rD   rE   	<genexpr>  s   z)split_auth_from_netloc.<locals>.<genexpr>)rsplitr   r   )r!  auth	user_passrD   rD   rE   split_auth_from_netloc  s    r0  c                 C   sL   t | \} \}}|du r| S |du r.d}d}nt|}d}dj||| dS )z
    Replace the sensitive data in a netloc with "****", if it exists.

    For example:
        - "user:pass@example.com" returns "user:****@example.com"
        - "accesstoken@example.com" returns "****@example.com"
    N****r   z:****z{user}{password}@{netloc})userpasswordr!  )r0  r$  quoterC   )r!  r2  r3  rD   rD   rE   redact_netloc   s    	
r5  c                 C   s@   t | }||j}|j|d |j|j|jf}t |}||fS )aR  Transform and replace netloc in a url.

    transform_netloc is a function taking the netloc and returning a
    tuple. The first element of this tuple is the new netloc. The
    entire tuple is returned.

    Returns a tuple containing the transformed url as item 0 and the
    original tuple returned by transform_netloc as item 1.
    r   )r$  urlsplitr!  r"  r>   queryfragment
urlunsplit)r'  Ztransform_netlocZpurlZnetloc_tupleZ
url_piecesZsurlrD   rD   rE   _transform_url  s    



r:  c                 C   s   t | S r   )r0  r!  rD   rD   rE   _get_netloc+  s    r<  c                 C   s
   t | fS r   )r5  r;  rD   rD   rE   _redact_netloc/  s    r=  c                 C   s   t | t\}\}}|||fS )z
    Parse a url into separate netloc, auth, and url with no auth.

    Returns: (url_without_auth, netloc, (username, password))
    r:  r<  )r'  Zurl_without_authr!  r.  rD   rD   rE   split_auth_netloc_from_url3  s    r?  c                 C   s   t | td S )z7Return a copy of url with 'username:password@' removed.r   r>  r'  rD   rD   rE   r<   >  s    r<   c                 C   s   t | td S )z.Replace the password in a given url with ****.r   )r:  r=  r@  rD   rD   rE   redact_auth_from_urlF  s    rA  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )
HiddenTextc                 C   s   || _ || _d S r   )secretredacted)r   rC  rD  rD   rD   rE   r   M  s    zHiddenText.__init__c                 C   s   d t| S )Nz<HiddenText {!r}>)rC   r|   r   rD   rD   rE   __repr__V  s    zHiddenText.__repr__c                 C   s   | j S r   rD  r   rD   rD   rE   __str__Z  s    zHiddenText.__str__c                 C   s    t | t |krdS | j|jkS )NF)r  rC  r   otherrD   rD   rE   __eq___  s    zHiddenText.__eq__c                 C   s
   | |k S r   rD   rH  rD   rD   rE   __ne__j  s    zHiddenText.__ne__N)r   r   r   r   rE  rG  rJ  rK  rD   rD   rD   rE   rB  L  s
   	rB  c                 C   s   t | ddS )Nr1  rF  )rB  )r  rD   rD   rE   
hide_valueo  s    rL  c                 C   s   t | }t| |dS )NrF  )rA  rB  )r'  rD  rD   rD   rE   hide_urlt  s    rM  c                 C   sz   dd tjd dj tjdd  g}| oBtoBtjtjd |v }|rvtjddgtjd	d  }t	d
 d
|dS )zProtection of pip.exe from modification on Windows

    On Windows, any operation modifying pip should be run as:
        python -m pip ...
    zpip.exez	pip{}.exer   zpip{}.{}.exeNro   z-mrQ   rz   z3To modify pip, please run the following command:
{}r   )rC   rS   rs   r   r=   r>   rR   rT   rU   r   r?   )Zmodifying_pipZ	pip_namesZshould_show_use_python_msgZnew_commandrD   rD   rE   (protect_pip_from_modification_on_windowsz  s&    rN  c                   C   s   t jduot j S )z!Is this console interactive?
    N)rS   stdinisattyrD   rD   rD   rE   is_console_interactive  s    rQ     c                 C   sf   t  }d}t| d8}t||dD ]}|t|7 }|| q$W d   n1 sT0    Y  ||fS )z:Return (hash, length) for path using hashlib.sha256()
    r   rb)r   N)hashlibsha256openr   rI   update)r>   	blocksizehlengthfblockrD   rD   rE   	hash_file  s    *r]  c                  C   s&   zddl } W n ty    Y dS 0 dS )z8
    Return whether the wheel package is installed.
    r   NFT)wheelImportError)r^  rD   rD   rE   is_wheel_installed  s
    r`  c                 C   s   t | } t| | S )zb
    Return paired elements.

    For example:
        s -> (s0, s1), (s2, s3), (s4, s5), ...
    )r   r   )iterablerD   rD   rE   pairwise  s    rb  c                 C   s    t |\}}t| |t| |fS )z
    Use a predicate to partition entries into false entries and true entries,
    like

        partition(is_odd, range(10)) --> 0 2 4 6 8   and  1 3 5 7 9
    )r   r   r   )predra  t1t2rD   rD   rE   	partition  s    rf  )F)ry   )T)N)r  )rR  )
__future__r   
contextlibrN   r   rT  iologgingr=   r   r^   ra   rS   collectionsr   	itertoolsr   pip._vendorr   pip._vendor.packaging.utilsr   Zpip._vendor.retryingr   pip._vendor.sixr	   r
   Zpip._vendor.six.movesr   r   r   r   r   Zpip._vendor.six.moves.urllibr   r$  Z"pip._vendor.six.moves.urllib.parser   r*  rQ   r   pip._internal.exceptionsr   r   r   r   r   pip._internal.utils.compatr   r   r   r   pip._internal.utils.typingr   r   Zpip._internal.utils.virtualenvr   r   r   r    typingr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   Zpip._vendor.pkg_resourcesr-   r   rH   r.   __all__	getLoggerr   r   rF   rK   r:   r8   r/   r_   rn   r0   r1   r   r   r2   r   r   r4   r   r5   DEFAULT_BUFFER_SIZEr   r6   r3   r7   r   r   r   r   r   r   r   r   r   r   r   objectr   r   contextmanagerr  r9   r  r;   r  r  r  r#  r)  r0  r5  r:  r<  r=  r?  r<   rA  rB  rL  rM  rN  rQ  r]  r`  rb  rf  rD   rD   rD   rE   <module>   s   8	

"

	

$
		
D$



#
