U
    7c"                     @   s  d Z ddlmZ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
mZmZ ddlmZ er|ddlmZmZmZmZ zddlZW nR ek
r   zddlmZ W n, ek
r   ddlZeje_eje_Y nX Y nX dd	d
dddddgZeeZer8ddl Z z
e j!Z!W n e"k
r,   dZ!Y nX e!dk	Z#ndZ#ddl$m!Z! erhdd Z%e&de% dZ'ndZ'dd Z(d'ddZ)dd
 Z*dd Z+dd Z,ddd hZ-e	j./d!pe	j.d"koej0d#kZ1d$d Z2e3edrd%d Z4nd&d Z4dS )(zKStuff that differs in different Python versions and platform
distributions.    )absolute_importdivisionN)PY2	text_type)MYPY_CHECK_RUNNING)OptionalTextTupleUnion)	ipaddressr   uses_pycacheconsole_to_strget_path_uidstdlib_pkgsWINDOWSsamefileget_terminal_sizeT)cache_from_sourcec                    sD    fddt  j jD }dd |D }ddd |D  jfS )Nc                 3   s   | ]} j | V  qd S N)object).0ierr >/tmp/pip-unpacked-wheel-xvghy_sv/pip/_internal/utils/compat.py	<genexpr>@   s     z-backslashreplace_decode_fn.<locals>.<genexpr>c                 s   s   | ]}t |V  qd S r   )ord)r   br   r   r   r   B   s      c                 s   s   | ]}d | V  qdS )z\x%xNr   )r   cr   r   r   r   C   s     )rangestartendjoin)r   Z	raw_bytesr   r   r   backslashreplace_decode_fn?   s    r%   backslashreplace_decodebackslashreplacec                  C   s4   zdd l } W dS  tk
r"   Y nX ddlm} |S )Nr   T)IS_PYOPENSSL)_sslImportErrorpip._vendor.urllib3.utilr(   )r)   r(   r   r   r   has_tlsM   s    r,   c                 C   s   t | tr| S t }|r*t|jdkr.d}z| |}W nD tk
r   |dkrXd}d	|}t
|| | j|td}Y nX tttdddd}|r|j|d	d}||}|S )
a  
    For display or logging purposes, convert a bytes object (or text) to
    text (e.g. unicode in Python 2) safe for output.

    :param desc: An optional phrase describing the input data, for use in
        the log message if a warning is logged. Defaults to "Bytes object".

    This function should never error out and so can take a best effort
    approach. It is okay to be lossy if needed since the return value is
    just for display.

    We assume the data is in the locale preferred encoding. If it won't
    decode properly, we warn the user but decode as best we can.

    We also ensure that the output can be safely written to standard output
    without encoding errors.
    asciizutf-8NzBytes objectz&{} does not appear to be encoded as %s)errors
__stderr__encodingr'   )
isinstancer   localegetpreferredencodingcodecslookupnamedecodeUnicodeDecodeErrorformatloggerwarningr&   getattrsysencode)datadescr0   decoded_data
msg_formatoutput_encodingoutput_encodedr   r   r   str_to_displayY   s0    

 
rE   c                 C   s   t | ddS )z<Return a string, safe for output, of subprocess output.
    zSubprocess output)r@   )rE   )r?   r   r   r   r      s    c                 C   s`   t tdr6t| tjtjB }t|j}t| n&tj	| sPt
| j}ntd|  |S )a)  
    Return path's uid.

    Does not follow symlinks:
        https://github.com/pypa/pip/pull/935#discussion_r5307003

    Placed this function in compat due to differences on AIX and
    Jython, that should eventually go away.

    :raises OSError: When path is a symlink or can't be read.
    
O_NOFOLLOWz1%s is a symlink; Will not return uid for symlinks)hasattrosopenO_RDONLYrF   fstatst_uidclosepathislinkstatOSError)rN   fdfile_uidr   r   r   r      s    
c                 C   s0   t j| }| dr,|dr,|dd }|S )zm
    Expand ~ and ~user constructions.

    Includes a workaround for https://bugs.python.org/issue14768
    z~/z//   N)rH   rN   
expanduser
startswith)rN   expandedr   r   r   rU      s    rU   pythonwsgirefargparsewinclintc                 C   sN   t tjdrtj| |S tjtj| }tjtj|}||kS dS )z>Provide an alternative for os.path.samefile on Windows/Python2r   N)rG   rH   rN   r   normcaseabspath)file1file2path1path2r   r   r   r      s
    c                   C   s   t t S )
        Returns a tuple (x, y) representing the width(x) and the height(y)
        in characters of the terminal window.
        )tupleshutilr   r   r   r   r   r      s    c                  C   s   dd } | dp| dp| d}|slt jdkrlz(tt tj}| |}t| W n tk
rj   Y nX |stj	ddtj	d	d
f}t
|d t
|d fS )rd   c                 S   s\   z4dd l }dd l}dd l}|d|| |jd}W n tk
rJ   Y d S X |dkrXd S |S )Nr   hhZ12345678)r   r   )fcntltermiosstructunpack_fromZioctl
TIOCGWINSZ	Exception)rR   rh   ri   rj   crr   r   r   ioctl_GWINSZ   s    z'get_terminal_size.<locals>.ioctl_GWINSZr   rT      win32LINES   COLUMNSP   )r=   platformrH   rI   ctermidrJ   rM   rm   environgetint)ro   rn   rR   r   r   r   r      s    
)N)5__doc__
__future__r   r   r4   r2   loggingrH   rf   r=   Zpip._vendor.sixr   r   pip._internal.utils.typingr   typingr   r   r	   r
   r   r*   pip._vendoripaddrZ	IPAddress
ip_addressZ	IPNetwork
ip_network__all__	getLogger__name__r:   impr   AttributeErrorr   importlib.utilr%   register_errorr&   r,   rE   r   r   rU   r   rv   rV   r6   r   r   rG   r   r   r   r   r   <module>   sx         




B

