B
    UvgO                 @   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 yddlZW nR ek
r   y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ddg
ZeeZe	jdkrdZddlmZ n6ddlZy
ejZW n ek
r   dZY nX edk	Ze	jdkr6dZndd Ze de dZdd Z!e	jdkrnd-dd	Z"n
d.dd	Z"dd
 Z#e	jdkrddl$m%Z% dd Z&ndd lm'Z' d!d Z&d"d# Z(d$d%d&hZ)e	j*+d'pe	j*d(koej,d)kZ-d*d Z.e/edr
d+d Z0nd,d Z0dS )/zKStuff that differs in different Python versions and platform
distributions.    )absolute_importdivisionN)	text_type)	ipaddressr   uses_pycacheconsole_to_str
native_strget_path_uidstdlib_pkgsWINDOWSsamefileget_terminal_sizeget_extension_suffixes)      T)cache_from_source)r      backslashreplacec                sR    fddt  j jD }tjd dkr8dd |D }ddd |D  jfS )Nc             3   s   | ]} j | V  qd S )N)object).0i)err ;/tmp/pip-install-r_9ig3yj/pip/pip/_internal/utils/compat.py	<genexpr>:   s    z-backslashreplace_decode_fn.<locals>.<genexpr>r      c             s   s   | ]}t |V  qd S )N)ord)r   br   r   r   r   =   s     c             s   s   | ]}d | V  qdS )z\x%xNr   )r   cr   r   r   r   >   s    )rangestartendsysversion_infojoin)r   Z	raw_bytesr   )r   r   backslashreplace_decode_fn9   s    r&   backslashreplace_decodec             C   s   t  }|rt|jdkr d}y| |}W n. tk
r\   td| | j|t	d}Y nX t
t
tdddd}|r|j|dd}||}|S )	a4  Return a string, safe for output, of subprocess output.

    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-8z5Subprocess output does not appear to be encoded as %s)errors
__stderr__Nencodingr   )localegetpreferredencodingcodecslookupnamedecodeUnicodeDecodeErrorloggerwarningr'   getattrr#   encode)datar+   soutput_encodingr   r   r   r   F   s     
)r   Fc             C   s"   t | tr| d|rdndS | S )Nzutf-8replacestrict)
isinstancebytesr1   )r8   r:   r   r   r   r   z   s    
c             C   s   t | tr| dS | S )Nzutf-8)r<   r   r6   )r8   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_RDONLYr>   fstatst_uidclosepathislinkstatOSError)rF   fdfile_uidr   r   r   r	      s    

)EXTENSION_SUFFIXESc               C   s   t S )N)rL   r   r   r   r   r      s    )get_suffixesc               C   s   dd t  D S )Nc             S   s   g | ]}|d  qS )r   r   )r   suffixr   r   r   
<listcomp>   s    z*get_extension_suffixes.<locals>.<listcomp>)rM   r   r   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)r@   rF   
expanduser
startswith)rF   expandedr   r   r   rQ      s    rQ   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)r?   r@   rF   r   normcaseabspath)file1file2path1path2r   r   r   r      s
    c               C   s   t t S )z
        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}|sby(t t  t j}| |}t | W n tk
r`   Y nX |st jddt jdd	f}t|d t|d fS )
z
        Returns a tuple (x, y) representing the width(x) and the height(y)
        in characters of the terminal window.
        c             S   sZ   y4dd l }dd l}dd l}|d|| |jd}W n tk
rH   d S X |dkrVd S |S )Nr   hhZ12345678)r   r   )fcntltermiosstructunpack_fromZioctl
TIOCGWINSZ	Exception)rJ   rc   rd   re   crr   r   r   ioctl_GWINSZ   s    z'get_terminal_size.<locals>.ioctl_GWINSZr   rP   r   LINES   COLUMNSP   )	r@   rA   ctermidrB   rE   rh   environgetint)rj   ri   rJ   r   r   r   r      s    )F)F)1__doc__
__future__r   r   r.   r,   loggingr@   ra   r#   Zpip._vendor.sixr   r   ImportErrorpip._vendoripaddrZ	IPAddress
ip_addressZ	IPNetwork
ip_network__all__	getLogger__name__r3   r$   r   importlib.utilr   impAttributeErrorr'   r&   register_errorr   r   r	   importlib.machineryrL   r   rM   rQ   r
   platformrR   r0   r   r   r?   r   r   r   r   r   <module>   sn   




3




