B
    =)H[è  ã               @   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g	Ze e¡Ze	jdkrìd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�r4dZndd„ Ze  de¡ dZdd„ Z!e	jdk�rld(dd	„Z"n
d)dd	„Z"dd
„ Z#dd„ Z$dd d!hZ%e	j& 'd"¡�p²e	j&d#k�o²ej(d$kZ)d%d„ Z*e+edƒ�rÒd&d„ Z,nd'd„ Z,d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)é   é   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© úUC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_internal\compat.pyú	<genexpr>9   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_fn8   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   E   s     
)r   Fc             C   s"   t | tƒr|  d|rdnd¡S | S )Nzutf-8ÚreplaceÚstrict)Ú
isinstanceÚbytesr0   )r7   r9   r   r   r   r   y   s    
c             C   s   t | tƒr|  d¡S | S )Nzutf-8)r;   r   r5   )r7   r9   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)rE   ÚfdÚfile_uidr   r   r   r	   †   s    

c             C   s0   t j | ¡}|  d¡r,| d¡r,|dd… }|S )zl
    Expand ~ and ~user constructions.

    Includes a workaround for http://bugs.python.org/issue14768
    z~/z//é   N)r?   rE   Ú
expanduserÚ
startswith)rE   Úexpandedr   r   r   rL   £   s    rL   Ú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?   rE   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ƒ}|sZy(t  t  ¡ t j¡}| |ƒ}t  |¡ W n   Y nX |szt 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   sP   y4dd l }dd l}dd l}| d| | |jd¡¡}W n
   d S |dkrLd S |S )Nr   ÚhhZ12345678)r   r   )ÚfcntlÚtermiosÚstructÚunpack_fromÚioctlZ
TIOCGWINSZ)rI   r^   r_   r`   Úcrr   r   r   Úioctl_GWINSZÓ   s    z'get_terminal_size.<locals>.ioctl_GWINSZr   rK   r   ÚLINESé   ÚCOLUMNSéP   )r?   r@   ZctermidrA   rD   ÚenvironÚgetÚint)rd   rc   rI   r   r   r   r   Î   s    )F)F)-Ú__doc__Ú
__future__r   r   r-   r+   Úloggingr?   r\   r"   Úpip._vendor.sixr   r   ÚImportErrorÚpip._vendorÚipaddrZ	IPAddressÚ
ip_addressZ	IPNetworkÚ
ip_networkÚ__all__Ú	getLoggerÚ__name__r2   r#   r   Úimportlib.utilr   ÚimpÚAttributeErrorr&   r%   Úregister_errorr   r   r	   rL   r
   ÚplatformrM   r/   r   r   r>   r   r   r   r   r   Ú<module>   sb   



3



