
-X4              %   @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Td d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( g% Z d) Z d* Z d) Z d+ Z	 d, Z
 d- Z d Z d. Z d/ d0   Z d1 d   Z d2 d   Z d3 d   Z d4 d   Z d5 d	   Z e j j  e _  d6 d   Z d7 d
   Z d8 d   Z d9 d   Z d: d   Z d; d   Z d< d   Z d a d a d= d   Z d> d   Z d? d   Z  d@ d&   Z! dA dB   Z" e j# dC k Z$ d dD d(  Z% d S)Ea  Common operations on Posix pathnames.

Instead of importing this module directly, import os and refer to
this module as os.path.  The "os.path" name is an alias for this
module on Posix systems; on other systems (e.g. Mac, Windows),
os.path provides the same operations in a manner specific to that
platform, and is an alias to another module (e.g. macpath, ntpath).

Some of this can actually be useful on non-Posix systems too, e.g.
for manipulation of the pathname component of URLs.
    N)*normcaseisabsjoin
splitdrivesplitsplitextbasenamedirnamecommonprefixZgetsizeZgetmtimeZgetatimeZgetctimeislinkexistslexistsisdirZisfileismount
expanduser
expandvarsnormpathabspathZsamefileZsameopenfilesamestatcurdirpardirseppathsepdefpathaltsepextsepdevnullrealpathsupports_unicode_filenamesrelpath.z../:z:/bin:/usr/binz	/dev/nullc             C   s   t  |  t  r d Sd Sd  S)N   /r"   )
isinstancebytes)path r(   9/home/kubikplay/www/django_dtb/lib/python3.4/posixpath.py_get_sep&   s    r*   c             C   s7   t  |  t t f  s3 t d j |  j j    n  |  S)z6Normalize case of pathname.  Has no effect under Posixz2normcase() argument must be str or bytes, not '{}')r%   r&   str	TypeErrorformat	__class____name__)sr(   r(   r)   r   1   s    	c             C   s   t  |   } |  j |  S)zTest whether a path is absolute)r*   
startswith)r0   r   r(   r(   r)   r   <   s    c             G   s   t  |   } |  } y^ xW | D]O } | j |  r: | } q | sP | j |  r] | | 7} q | | | 7} q WWnG t k
 r t d d   |  f | D  r t d  d  n    Yn X| S)zJoin two or more pathname components, inserting '/' as needed.
    If any component is an absolute path, all previous path components
    will be discarded.  An empty last part will result in a path that
    ends with a separator.c             s   s$   |  ] } t  | t t f  Vq d  S)N)r%   r+   r&   ).0r0   r(   r(   r)   	<genexpr>V   s    zjoin.<locals>.<genexpr>z.Can't mix strings and bytes in path componentsN)r*   r1   endswithr,   all)apr   r'   br(   r(   r)   r   F   s    	 		c             C   sx   t  |   } |  j |  d } |  d |  |  | d  } } | rn | | t |  k rn | j |  } n  | | f S)zSplit a pathname.  Returns tuple "(head, tail)" where "tail" is
    everything after the final slash.  Either part may be empty.   N)r*   rfindlenrstrip)r7   r   iheadtailr(   r(   r)   r   c   s    !c             C   s@   t  |  t  r d } d } n d } d } t j |  | d  |  S)Nr$      .r"   r!   )r%   r&   genericpath	_splitext)r7   r   r   r(   r(   r)   r   s   s    	c             C   s   |  d d  |  f S)zJSplit a pathname into drive and path. On Posix, drive is always
    empty.Nr   r(   )r7   r(   r(   r)   r      s    c             C   s-   t  |   } |  j |  d } |  | d  S)z)Returns the final component of a pathnamer9   N)r*   r:   )r7   r   r=   r(   r(   r)   r	      s    c             C   sa   t  |   } |  j |  d } |  d |  } | r] | | t |  k r] | j |  } n  | S)z-Returns the directory component of a pathnamer9   N)r*   r:   r;   r<   )r7   r   r=   r>   r(   r(   r)   r
      s    c             C   sB   y t  j |   } Wn t t f k
 r1 d SYn Xt j | j  S)z&Test whether a path is a symbolic linkF)oslstatOSErrorAttributeErrorstatS_ISLNKst_mode)r'   str(   r(   r)   r      s
    	c             C   s.   y t  j |   Wn t k
 r) d SYn Xd S)zCTest whether a path exists.  Returns True for broken symbolic linksFT)rC   rD   rE   )r'   r(   r(   r)   r      s
    	c             C   s   y t  j |   } Wn t k
 r+ d SYn Xt j | j  rB d St |  t  rc t |  d  } n t |  d  } y t  j |  } Wn t k
 r d SYn X| j	 } | j	 } | | k r d S| j
 } | j
 } | | k r d Sd S)z$Test whether a path is a mount pointFs   ..z..T)rC   rD   rE   rG   rH   rI   r%   r&   r   st_devst_ino)r'   Zs1parentZs2Zdev1Zdev2Zino1Zino2r(   r(   r)   r      s,    						c       	      C   s  t  |  t  r d } n d } |  j |  s1 |  St |   } |  j | d  } | d k  rj t |   } n  | d k r d t j k r d d l } | j	 t j
    j } q.t j d } nr d d l } |  d |  } t  | t  r t | d  } n  y | j |  } Wn t k
 r$|  SYn X| j } t  |  t  rUt j |  } d } n d	 } | j |  } | |  | d  p| S)
zOExpand ~ and ~user constructions.  If user or $HOME is unknown,
    do nothing.   ~~r9   r   HOMENASCIIr$   r"   )r%   r&   r1   r*   findr;   rC   environpwdZgetpwuidgetuidZpw_dirr+   ZgetpwnamKeyErrorfsencoder<   )	r'   Ztilder   r=   rT   ZuserhomenameZpwentZrootr(   r(   r)   r      s:    				c             C   s  t  |  t  rs d |  k r |  St sI d d l } | j d | j  a n  t j } d } d } t t d d  } nX d |  k r |  St	 s d d l } | j d	 | j  a	 n  t	 j } d
 } d } t j
 } d } x| |  |  } | s Pn  | j d  \ } } | j d  }	 |	 j |  rB|	 j |  rB|	 d d  }	 n  y< | d k rst j t j
 t j |	   }
 n
 | |	 }
 Wn t k
 r| } Yq X|  | d  } |  d |  |
 }  t |   } |  | 7}  q W|  S)zZExpand shell variables of form $var and ${var}.  Unknown variables
    are left unchanged.   $r   Ns   \$(\w+|\{[^}]*\})   {   }environb$z\$(\w+|\{[^}]*\}){}r9   )r%   r&   	_varprogbrecompilerQ   searchgetattrrC   _varprogrS   ZspanZgroupr1   r4   rW   fsdecoderV   r;   )r'   rb   rd   startendrS   r=   mjrX   valuer?   r(   r(   r)   r   
  sN    			"c       	      C   s^  t  |  t  r* d } d } d } d } n d } d } d } d } |  | k rR | S|  j |  } | r |  j | d	  r |  j | d
  r d	 } n  |  j |  } g  } xy | D]q } | | | f k r q n  | | k s| r | s| r| d | k r| j |  q | r | j   q q W| } | j |  }  | rT| | |  }  n  |  p]| S)z0Normalize path, eliminating double slashes, etc.r$       r@   s   ..r"    r!   z..      r9   r`   )r%   r&   r1   r   appendpopr   )	r'   r   ZemptydotZdotdotZinitial_slashesZcompsZ	new_compsZcompr(   r(   r)   r   >  s<    	'	c             C   sR   t  |   sH t |  t  r* t j   } n t j   } t | |   }  n  t |   S)zReturn an absolute path.)r   r%   r&   rC   getcwdbgetcwdr   r   )r'   Zcwdr(   r(   r)   r   c  s    c             C   s,   t  |  d d  |  i   \ } } t |  S)zlReturn the canonical path of the specified filename, eliminating any
symbolic links encountered in the path.Nr   )_joinrealpathr   )filenamer'   okr(   r(   r)   r   q  s    "c       
      C   s  t  |  t  r$ d } d } d } n d } d } d } t |  r[ | d d   } | }  n  x?| r| j |  \ } } } | s^ | | k r q^ n  | | k r |  r t |   \ }  } | | k r t |  | |  }  q q^ | }  q^ n  t |  |  } t |  s| }  q^ n  | | k rK| | }  |  d  k	 r8q^ n  t | |  d f Sd  | | <t |  t j	 |  |  \ }  }	 |	 st |  |  d f S|  | | <q^ W|  d	 f S)
Nr$   r@   s   ..r"   r!   z..r9   FT)
r%   r&   r   	partitionr   r   r   rv   rC   readlink)
r'   restZseenr   r   r   rX   _Znewpathrx   r(   r(   r)   rv   y  sH    			

!rv   darwinc       	      C   s   |  s t  d   n  t |  t  r9 d } d } d } n d } d } d } | d k r` | } n  d	 d
   t |  j |  D } d d
   t |   j |  D } t t | | g   } | g t |  | | | d  } | s | St |   S)z#Return a relative version of a pathzno path specifiedr@   r$   s   ..r!   r"   z..Nc             S   s   g  |  ] } | r |  q Sr(   r(   )r2   xr(   r(   r)   
<listcomp>  s   	 zrelpath.<locals>.<listcomp>c             S   s   g  |  ] } | r |  q Sr(   r(   )r2   r~   r(   r(   r)   r     s   	 )
ValueErrorr%   r&   r   r   r;   r   r   )	r'   rh   r   r   r   Z
start_list	path_listr=   Zrel_listr(   r(   r)   r      s$    		""%)&__doc__rC   sysrG   rA   __all__r   r   r   r   r   r   r   r   r*   r   r   r   r   r   rB   r   r	   r
   r   r   r   r   rf   ra   r   r   r   r   rv   platformr   r    r(   r(   r(   r)   <module>   sV   
	
	
)*4%3