î
ªÍ Xý  ã               @   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 n  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 ƒ  |  ƒ }  n  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   ú>/home/ubuntu/projects/ifolica/build/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 |  | Œ ƒ } t |  ƒ } t | ƒ j t | t ƒ ƒ r± t | ƒ t | ƒ k r± t t | ƒ ƒ t | ƒ k r± t d j | | ƒ ƒ ‚ n  | 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 Sr   )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 | ƒ zO y t j | | ƒ d } Wn! t t t	 f k
 rƒ d } Yn Xt j
 | ƒ Wd t j | ƒ t j |  ƒ | SX)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).
    ZoriginalÚsymlinkTFN)ÚtempfileÚmkdtempr   r   r   Úmakedirsr%   ÚOSErrorÚNotImplementedErrorÚAttributeErrorÚremoveÚrmdir)ZtmpdirZoriginal_pathZsymlink_pathÚ	supportedr   r   r   Úsymlinks_supportedR   s    
r/   )Ú
__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$   r/   r   r   r   r   Ú<module>   s    4			
