3
š(ƒhý  ã               @   sÄ   d dl mZ d dlZd dlZd dlZd dlmZmZ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 ejr‚ejƒ p€ejƒ Zejs’ejdkr˜eZndd	„ Zd
d„ Zdd„ Zdd„ Zdd„ ZdS )é    )Úunicode_literalsN)ÚabspathÚdirnameÚisabsÚjoinÚnormcaseÚnormpathÚsep)ÚSuspiciousFileOperation)Úsix)Ú
force_textÚntc             C   s   t | ƒsttjƒ | ƒ} t| ƒS )zÕ
        Version of os.path.abspath that uses the unicode representation
        of the current working directory, thus avoiding a UnicodeDecodeError
        in join when the cwd has non-ASCII characters.
        )r   r   ÚosZgetcwdur   )Úpath© r   ú4/tmp/pip-install-q3hcpn_q/Django/django/utils/_os.pyÚabspathu   s    r   c             C   s"   t jrt| t jƒ r| jtƒS | S )z'
    Always return a unicode path.
    )r   ÚPY2Ú
isinstanceÚ	text_typeÚdecodeÚfs_encoding)r   r   r   r   Úupath#   s    
r   c             C   s    t jrt| tƒ r| jtƒS | S )zb
    Always return a native path, that is unicode on Python 3 and bytestring on
    Python 2.
    )r   r   r   ÚbytesÚencoder   )r   r   r   r   Únpath,   s    
r   c             G   s€   t | ƒ} dd„ |D ƒ}tt| f|žŽ ƒ}t| ƒ}t|ƒjt|t ƒƒ r|t|ƒt|ƒkr|tt|ƒƒt|ƒkr|tdj||ƒƒ‚|S )a  
    Joins one or more path components to the base path component intelligently.
    Returns a normalized, absolute version of the final path.

    The final path must be located inside of the base path component (otherwise
    a ValueError is raised).
    c             S   s   g | ]}t |ƒ‘qS r   )r   )Ú.0Úpr   r   r   ú
<listcomp>?   s    zsafe_join.<locals>.<listcomp>zGThe joined path ({}) is located outside of the base path component ({}))	r   r   r   r   Ú
startswithr	   r   r
   Úformat)ÚbaseÚpathsZ
final_pathÚ	base_pathr   r   r   Ú	safe_join6   s    
r$   c              C   sŠ   t jƒ } tjj| dƒ}tjj| dƒ}tj|ƒ zBytj||ƒ d}W n ttt	fk
rb   d}Y nX tj
|ƒ W dtj|ƒ tj| ƒ |S )z·
    A function to check if creating symlinks are supported in the
    host platform and/or if they are allowed to be created (e.g.
    on Windows it requires admin permissions).
    ÚoriginalÚsymlinkTFN)ÚtempfileÚmkdtempr   r   r   Úmakedirsr&   ÚOSErrorÚNotImplementedErrorÚAttributeErrorÚremoveÚrmdir)ZtmpdirZoriginal_pathZsymlink_pathÚ	supportedr   r   r   Úsymlinks_supportedR   s    



r0   )Ú
__future__r   r   Úsysr'   Úos.pathr   r   r   r   r   r   r	   Zdjango.core.exceptionsr
   Zdjango.utilsr   Zdjango.utils.encodingr   r   ÚgetfilesystemencodingÚgetdefaultencodingr   ÚPY3Únamer   r   r   r$   r0   r   r   r   r   Ú<module>   s    $	
