Ńň
çŐJc           @   s[   d  d k  Z  d   Z d   Z d   Z d   Z d   Z d   Z h  d  Z d	   Z d S(
   i˙˙˙˙Nc         C   s5   t  |   d j o |  d d j o	 |  d  S|  Sd S(   s@   If path ends with a /, strip it and return the stripped version.i    i˙˙˙˙t   /N(   t   len(   t   path(    (    s2   /var/www/Pootle/local_apps/pootle_app/url_manip.pyt   strip_trailing_slash   s    $	c         C   s5   t  |   d j o |  d d j o |  S|  d Sd S(   s/   If path does not end with /, add it and return.i    i˙˙˙˙R    N(   R   (   R   (    (    s2   /var/www/Pootle/local_apps/pootle_app/url_manip.pyt   add_trailing_slash   s    $c         C   sT   y3 t  |   i d  } |  | d  |  | d f SWn t j
 o d |  f SXd  S(   NR    i   t    (   R   t   rindext
   ValueError(   R   t	   slash_pos(    (    s2   /var/www/Pootle/local_apps/pootle_app/url_manip.pyt	   url_split&   s
    c         C   s2   |  d d j o |  d  |  d f S|  d f Sd  S(   Ni˙˙˙˙u   /u    (    (   t   p(    (    s2   /var/www/Pootle/local_apps/pootle_app/url_manip.pyt   split_trailing_slash-   s    c   
      C   są   d   } t  |  \ } } |  i d  } | i   | i d  } | | |  } t |  | d g } | | } d i | |  }	 |	 d j o | d j o d S|	 | Sd  S(   Nc         S   sP   t  t |   t |   } x. t |  D]  } |  | | | j o | Sq( W| S(   N(   t   minR   t   xrange(   t	   ref_chaint	   abs_chaint   max_post   i(    (    s2   /var/www/Pootle/local_apps/pootle_app/url_manip.pyt   get_last_agreement4   s     	R    s   ..u   /R   s   ./(   R   t   splitt   popR   t   join(
   t   ref_patht   abs_pathR   t	   abs_slashR   R   t   cut_post   go_upt   go_downt   result(    (    s2   /var/www/Pootle/local_apps/pootle_app/url_manip.pyt   get_relative3   s    	

c         C   s   t  |   \ } } | S(   N(   R	   (   t   urlt   parent_partt   _child_part(    (    s2   /var/www/Pootle/local_apps/pootle_app/url_manip.pyt   parentK   s    c         C   s?   t  |  d j o$ d |  t i t | i     f S|  Sd  S(   Ni    u   %s?%s(   R   t   urllibt	   urlencodet   sortedt	   iteritems(   R   t   args(    (    s2   /var/www/Pootle/local_apps/pootle_app/url_manip.pyt   make_urlO   s    $c         C   s   t  |   \ } } | S(   N(   R	   (   R   t   _parent_partt
   child_part(    (    s2   /var/www/Pootle/local_apps/pootle_app/url_manip.pyt   basenameU   s    (	   R"   R   R   R	   R   R   R!   R'   R*   (    (    (    s2   /var/www/Pootle/local_apps/pootle_app/url_manip.pyt   <module>   s   						