o
    
j6hK                  	   @   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mZ d dlmZmZmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z! d dl"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/ g dZ0e1e2Z3e dZ4eee5 e5ef Z6ee7e7e7f Z8ee9eee9 ee9 f f Z:de9fddZ;dee7df dee7e7e7f fddZ<de9ddfddZ=de9fddZ>e#de$de%dddde9d e?ddfd!d"Z@d#edef de9d$e6ddfd%d&ZAde9de9fd'd(ZBdde9d*e9de9fd+d,ZCd-e9d.ee9 de9fd/d0ZDd-e9ddfd1d2ZEd-e9d.ee9 de9fd3d4ZFd-e9de9fd5d6ZGd-e9de9fd7d8ZHd9e9de7fd:d;ZId<eJde9fd=d>ZKd?eee  deee9 ee7 f fd@dAZLde9de?fdBdCZMejNfdDedEe7deeO fdFdGZPdde9dHe?de9fdIdJZQde9dee9e9f fdKdLZRdMe9dNe9ddfdOdPZSde9de?fdQdRZTdSedTeddfdUdVZUG dWdX dXeZVe jWdYe9deeV fdZd[ZXdeeV fd\d]ZYdeeV fd^d_ZZd`edaedee fdbdcZ[dde9deee7 de9fdfdgZ\ddie9dje9de9fdkdlZ]die9dee9ee7 f fdmdnZ^die9de:fdodpZ_die9de9fdqdrZ`dse9dtee9geedf f dee9e:f fdudvZadie9de:fdwdxZbdie9dee9 fdydzZcdse9dee9e9ee9e9f f fd{d|Zddse9de9fd}d~Zedse9de9fddZfG dd dZgde9degfddZhdse9degfddZide?ddfddZjde?fddZkdde9de7deee7f fddZlde?fddZmdee deeeef  fddZndee4ge?f dee4 deee4 ee4 f fddZodS )    N)StringIO)filterfalseteezip_longest)TracebackType)AnyBinaryIOCallableContextManagerIterableIteratorListOptionalTextIOTupleTypeTypeVarcast)retrystop_after_delay
wait_fixed)__version__)CommandError)get_major_minor_version)WINDOWS)running_under_virtualenv)rmtreedisplay_path
backup_dirasksplitextformat_sizeis_installable_dirnormalize_pathrenamesget_progcaptured_stdout
ensure_dirremove_auth_from_urlTreturnc                  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   )pip_pkg_dir r3   g/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/pip/_internal/utils/misc.pyget_pip_versionD   s   r5   py_version_info.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   )r6   r3   r3   r4   normalize_version_infoO   s
   
r:   r,   c              
   C   s`   zt |  W dS  ty/ } z|jtjkr|jtjkr$ W Y d}~dS W Y d}~dS d}~ww )z os.path.makedirs without EEXIST.N)r+   makedirsOSErrorerrnoEEXIST	ENOTEMPTY)r,   er3   r3   r4   r'   b   s   r'   c               
   C   sJ   zt jtjd } | dv rtj dW S | W S  tttfy$   Y dS w )Nr   )z__main__.pyz-cz -m pippip)	r+   r,   basenamesysargv
executableAttributeError	TypeError
IndexError)progr3   r3   r4   r%   l   s   r%   Tr7   g      ?)reraisestopwaitFdirignore_errorsc                 C   s   t j| |td d S )N)rN   onerror)shutilr   rmtree_errorhandler)rM   rN   r3   r3   r4   r   z      r   funcexc_infoc                 C   sN   zt |jtj@  }W n
 ty   Y dS w |r&t |tj | | 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_IWRITEr<   chmod)rS   r,   rT   has_attr_readonlyr3   r3   r4   rQ      s   rQ   c                 C   sF   t jt j| } | t  t jj r!d| tt  d  } | S )zTGives the display value for a given path, making it relative to cwd
    if possible..N)r+   r,   normcaser0   
startswithgetcwdsepr9   r,   r3   r3   r4   r      s   r   .bakextc                 C   sD   d}|}t j| | r|d7 }|t| }t j| | s| | S )z\Figure out the name of a directory to back up the given dir to
    (adding .bak, .bak2, etc)   )r+   r,   existsstr)rM   ra   n	extensionr3   r3   r4   r      s   r   messageoptionsc                 C   s2   t jdd D ]
}||v r|  S q	t| |S )NPIP_EXISTS_ACTION )r+   environgetsplitr   )rg   rh   actionr3   r3   r4   ask_path_exists   s
   
ro   c                 C   s   t jdrtd|  dS )z&Raise an error if no input is allowed.PIP_NO_INPUTz5No input was expected ($PIP_NO_INPUT set); question: N)r+   rk   rl   	Exceptionrg   r3   r3   r4   _check_no_input   s
   rs   c                 C   sD   	 t |  t| }|  }||vrtd|d| n|S q)z@Ask the message interactively, with the given possible responsesrb   z>Your response ({!r}) was not one of the expected responses: {}z, )rs   inputstriplowerprintr1   r-   )rg   rh   responser3   r3   r4   r      s   r   c                 C   s   t |  t| S )zAsk for input interactively.)rs   rt   rr   r3   r3   r4   	ask_input   s   ry   c                 C   s   t |  t| S )z!Ask for a password interactively.)rs   getpassrr   r3   r3   r4   ask_password   s   
r{   valc                 C   s.   |   } | dv r
dS | dv rdS td| )zConvert a string representation of truth to true (1) or false (0).

    True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
    are 'n', 'no', 'f', 'false', 'off', and '0'.  Raises ValueError if
    'val' is anything else.
    )yyesttrueon1rb   )re   noffalseoff0r   zinvalid truth value )rv   
ValueError)r|   r3   r3   r4   	strtobool   s   r   bytesc                 C   sX   | dkrd | d d S | dkrd t| d S | dkr%d | d S d t| S )	Ni@B z	{:.1f} MBg     @@i  i'  z{} kBz	{:.1f} kBz{} bytes)r1   int)r   r3   r3   r4   r!      s   r!   rowsc                    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      g | ]	}t tt|qS r3   )tuplemaprd   .0rowr3   r3   r4   
<listcomp>       ztabulate.<locals>.<listcomp>c                 S   r   r3   )maxr   r9   )r   colr3   r3   r4   r      r   	fillvaluerj   c                    s$   g | ]}d  ttj|  qS ) )r-   r   rd   ljustrstripr   sizesr3   r4   r      s   $ )r   )r   tabler3   r   r4   tabulate   s   r   c                 C   sH   t j| sdS t jt j| drdS t jt j| dr"dS dS )at  Is path is a directory containing pyproject.toml or setup.py?

    If pyproject.toml exists, this is a PEP 517 project. Otherwise we look for
    a legacy setuptools layout by identifying setup.py. We don't check for the
    setup.cfg because using it without setup.py is only available for PEP 517
    projects, which are already covered by the pyproject.toml check.
    Fzpyproject.tomlTzsetup.py)r+   r,   isdirisfiler-   r_   r3   r3   r4   r"      s   r"   filesizec                 c   s    	 |  |}|sdS |V  q)z7Yield pieces of data from a file-like object until EOF.TN)read)r   r   chunkr3   r3   r4   read_chunks  s   
r   resolve_symlinksc                 C   s6   t j| } |rt j| } nt j| } t j| S )zN
    Convert a path to its canonical, case-normalized, absolute version.

    )r+   r,   
expanduserrealpathr0   r[   )r,   r   r3   r3   r4   r#     s
   r#   c                 C   s@   t | \}}| dr|dd | }|dd }||fS )z,Like os.path.splitext, but take off .tar tooz.tarN)	posixpathr    rv   endswith)r,   basera   r3   r3   r4   r    !  s
   r    oldnewc                 C   s   t j|\}}|r|rt j|st | t| | t j| \}}|r<|r>zt | W dS  ty;   Y dS w dS dS )z7Like os.renames(), but handles renaming across devices.N)	r+   r,   rm   rc   r;   rP   move
removedirsr<   )r   r   headtailr3   r3   r4   r$   *  s   
r$   c                 C   s|   t | } d}t r| t tjS ddlm} ddlm} | |r<|d}|D ]}t	||}| t |r9 dS q(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   )
get_scheme)SCHEME_KEYSrj   TF)
r#   r   r\   rC   prefixpip._internal.locationsr   pip._internal.models.schemer   getattr)r,   r   r   r   schemekey
local_pathr3   r3   r4   is_local;  s   

r   msgargsc                 G   s   t j| g|R   d S N)loggerinfo)r   r   r3   r3   r4   write_outputa  s   r   c                   @   s<   e Zd ZU dZeed< ededd fddZedd Z	dS )StreamWrapperNorig_streamr*   c                 C   s   || _ |  S r   )r   )clsr   r3   r3   r4   from_streamh  s   zStreamWrapper.from_streamc                 C   s   | j jS r   )r   encodingselfr3   r3   r4   r   o  s   zStreamWrapper.encoding)
__name__
__module____qualname__r   r   __annotations__classmethodr   propertyr   r3   r3   r3   r4   r   e  s   
 r   stream_namec              
   c   sL    t t| }tt| t| zt t| V  W tt| | dS tt| | w )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)r   rC   setattrr   r   )r   orig_stdoutr3   r3   r4   captured_outputt  s   
r   c                   C      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   r3   r3   r3   r4   r&     s   	r&   c                   C   r   )z 
    See captured_stdout().
    stderrr   r3   r3   r3   r4   captured_stderr  s   r   
sequentialnamedc                  O   sD   t t| tt| fi |}dd | D }||d< tdd|S )Nc                 S   s   i | ]\}}||qS r3   r3   )r   r   valuer3   r3   r4   
<dictcomp>  s    zenum.<locals>.<dictcomp>reverse_mappingEnumr3   )dictzipranger9   itemstype)r   r   enumsreverser3   r3   r4   enum  s   r   hostportc                 C   s.   |du r| S d| v rd|  d} |  d| S )z.
    Build a netloc from a host-port pair
    N:[]r3   )r   r   r3   r3   r4   build_netloc  s
   r   httpsnetlocr   c                 C   s8   |  ddkrd| vrd| vrd|  d} | d|  S )z)
    Build a full URL from a netloc.
    r      @r   r   z://)count)r   r   r3   r3   r4   build_url_from_netloc  s   r   c                 C   s    t | }tj|}|j|jfS )z2
    Return the host-port pair from a netloc.
    )r   urllibparseurlparsehostnamer   )r   urlparsedr3   r3   r4   parse_netloc  s   r   c                 C   st   d| vr| dfS |  dd\}} d}d|v r|dd\}}n|d}}tj|}|dur4tj|}| ||ffS )zp
    Parse out and remove the auth information from a netloc.

    Returns: (netloc, (username, password)).
    r   )NNrb   Nr   )rsplitrm   r   r   unquote)r   authpwuserr3   r3   r4   split_auth_from_netloc  s   
r   c                 C   sN   t | \} \}}|du r| S |du rd}d}ntj|}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****rj   z:****z{user}{password}@{netloc})r   passwordr   )r   r   r   quoter1   )r   r   r  r3   r3   r4   redact_netloc  s   r  r   transform_netlocc                 C   sJ   t j| }||j}|j|d |j|j|jf}t j|}|t	d|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   NetlocTuple)
r   r   urlsplitr   r   r,   queryfragment
urlunsplitr   )r   r  purlnetloc_tuple
url_piecessurlr3   r3   r4   _transform_url  s
   
r  c                 C   s   t | S r   )r   r   r3   r3   r4   _get_netloc  s   r  c                 C   s
   t | fS r   )r  r  r3   r3   r4   _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   url_without_authr   r   r3   r3   r4   split_auth_netloc_from_url  s   
r  c                 C      t | td S )z7Return a copy of url with 'username:password@' removed.r   r  r   r3   r3   r4   r(     s   r(   c                 C   r  )z.Replace the password in a given url with ****.r   )r  r  r  r3   r3   r4   redact_auth_from_url  s   r  c                   @   sP   e Zd ZdededdfddZdefddZdefd	d
ZdedefddZ	dS )
HiddenTextsecretredactedr*   Nc                 C   s   || _ || _d S r   )r  r  )r   r  r  r3   r3   r4   __init__#  s   
zHiddenText.__init__c                 C   s   d t| S )Nz<HiddenText {!r}>)r1   rd   r   r3   r3   r4   __repr__'  s   zHiddenText.__repr__c                 C   s   | j S r   r  r   r3   r3   r4   __str__*  s   zHiddenText.__str__otherc                 C   s    t | t |kr
dS | j|jkS )NF)r   r  )r   r  r3   r3   r4   __eq__.  s   zHiddenText.__eq__)
r   r   r   rd   r  r  r  r   boolr   r3   r3   r3   r4   r  "  s
    r  r   c                 C   s   t | ddS )Nr   r  )r  )r   r3   r3   r4   
hide_value7  s   r"  c                 C   s   t | }t| |dS )Nr  )r  r  )r   r  r3   r3   r4   hide_url;  s   r#  modifying_pipc                 C   sz   dd tjd dj tjdd  g}| o!to!tjtjd |v }|r;t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{}.{}.exeNr   z-mrA   rb   z3To modify pip, please run the following command:
{}r   )r1   rC   version_infor   r+   r,   rB   rD   rE   r   r-   )r$  	pip_namesshould_show_use_python_msgnew_commandr3   r3   r4   (protect_pip_from_modification_on_windows@  s   r)  c                   C   s   t jduo	t j S )zIs this console interactive?N)rC   stdinisattyr3   r3   r3   r4   is_console_interactiveZ  rR   r,     	blocksizec                 C   sl   t  }d}t| d}t||dD ]}|t|7 }|| qW d   ||fS 1 s-w   Y  ||fS )z5Return (hash, length) for path using hashlib.sha256()r   rb)r   N)hashlibsha256openr   r9   update)r,   r.  hlengthr   blockr3   r3   r4   	hash_file_  s   
r7  c                  C   s$   zddl } W dS  ty   Y dS w )z8
    Return whether the wheel package is installed.
    r   NFT)wheelImportError)r8  r3   r3   r4   is_wheel_installedk  s   
r:  iterablec                 C   s   t | } t| | S )zb
    Return paired elements.

    For example:
        s -> (s0, s1), (s2, s3), (s4, s5), ...
    )iterr   )r;  r3   r3   r4   pairwisew  s   
r=  predc                 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   filter)r>  r;  t1t2r3   r3   r4   	partition  s   
rB  )F)r`   )T)r   )r-  )p
contextlibr=   rz   r0  iologgingr+   r   rP   rU   rC   urllib.parser   r   	itertoolsr   r   r   typesr   typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   pip._vendor.tenacityr   r   r   rA   r   pip._internal.exceptionsr   r   r   pip._internal.utils.compatr   pip._internal.utils.virtualenvr   __all__	getLoggerr   r   r)   BaseExceptionExcInfor   r8   rd   r  r5   r:   r'   r%   r!  r   rQ   r   r   ro   rs   r   ry   r{   r   floatr!   r   r"   DEFAULT_BUFFER_SIZEr   r   r#   r    r$   r   r   r   contextmanagerr   r&   r   r   r   r   r   r   r  r  r  r  r  r(   r  r  r"  r#  r)  r,  r7  r:  r=  rB  r3   r3   r3   r4   <module>   s   <
$
"	* 		&
	

$
 "