
 X$                 @   sm  d  d l  m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d l	 m
 Z
 d  d l m Z m Z d  d l m Z d d	 l m Z m Z d d
 l m Z m Z d d l m Z e   Z e   Z d d d  Z d d d d d d  Z e
 e e j  Z d d   Z d d   Z d d   Z  d d   Z! d d   Z" d d d  Z# d d d  Z$ d d    Z% d S)!    )unicode_literals)local)six)
force_text
iri_to_uri)lazy)urlsplit
urlunsplit)override   )NoReverseMatchResolver404)get_ns_resolverget_resolver)get_callableNc             C   s+   | d  k r t    } n  t |  j |   S)N)get_urlconfr   resolve)pathurlconf r   >/home/ubuntu/projects/ifolica/build/django/django/urls/base.pyr      s    r   c             C   s/  | d  k r t    } n  t |  } | p- g  } | p9 i  } t   } t |  t j  s` |  } n|  j d  } | j   | d } | d d   }	 | r | j d  }
 |
 j   n d  }
 g  } d } x+|	 r|	 j   } |
 r |
 j   n d  } yE | j	 | } | r| | k r| } n | | k r8| d } n  Wn t
 k
 rMYn X| | k rcd  }
 n  y. | j | \ } } | j |  | | } Wq t
 k
 r} z= | rt d | d j |  f   n t d |   WYd  d  } ~ Xq Xq W| rt | |  } n  t t | j | | | |    S)N:r   r    z,%s is not a registered namespace inside '%s'z %s is not a registered namespace)r   r   get_script_prefix
isinstancer   string_typessplitreversepopZapp_dictKeyErrorZnamespace_dictappendr   joinr   r   r   Z_reverse_with_prefix)Zviewnamer   argskwargsZcurrent_appresolverprefixZviewpartsr   Zcurrent_pathZresolved_pathZ
ns_patternnsZ
current_nsZapp_listextrakeyr   r   r   r      sX    		

			'r   c               C   s"   t  j   t j   t j   d  S)N)r   cache_clearr   r   r   r   r   r   clear_url_caches`   s    

r+   c             C   s)   |  j  d  s |  d 7}  n  |  t _ d S)z7
    Set the script prefix for the current thread.
    /N)endswith	_prefixesvalue)r%   r   r   r   set_script_prefixf   s    r0   c               C   s   t  t d d  S)z
    Return the currently active script prefix. Useful for client code that
    wishes to construct their own URLs manually (although accessing the request
    instance is normally going to be a lot cleaner).
    r/   r,   )getattrr.   r   r   r   r   r   o   s    r   c               C   s#   y
 t  ` Wn t k
 r Yn Xd S)z9
    Unset the script prefix for the current thread.
    N)r.   r/   AttributeErrorr   r   r   r   clear_script_prefixx   s    
r3   c             C   s.   |  r |  t  _ n t t  d  r* t  ` n  d S)z
    Set the URLconf for the current thread (overriding the default one in
    settings). If urlconf_name is None, revert back to the default.
    r/   N)	_urlconfsr/   hasattr)Zurlconf_namer   r   r   set_urlconf   s    r6   c             C   s   t  t d |   S)zp
    Return the root URLconf to use for the current thread if it has been
    changed from the default one.
    r/   )r1   r4   )defaultr   r   r   r      s    r   c             C   s2   y t  |  |  d SWn t k
 r- d SYn Xd S)z
    Return True if the given path resolves against the default URL resolver,
    False otherwise. This is a convenience method to make working with "is
    this a match?" cases easier, avoiding try...except blocks.
    TFN)r   r   )r   r   r   r   r   is_valid_path   s
    r8   c             C   s   t  |   } y t | j  } Wn t k
 r3 Yn X| j rS d | j | j f n | j } t |  c y" t | d | j d | j	 }  Wn t
 k
 r Yn( Xt | j | j |  | j | j f  }  Wd QX|  S)z
    Given a URL (absolute or relative), try to get its translated version in
    the `lang_code` language (either by i18n_patterns or by translated regex).
    Return the original URL if no translated version is found.
    z%s:%sr"   r#   N)r   r   r   r   	namespaceurl_namer
   r   r"   r#   r   r	   schemenetlocqueryfragment)urlZ	lang_codeparsedmatchZto_be_reversedr   r   r   translate_url   s    ("-rB   )&
__future__r   	threadingr   Zdjango.utilsr   Zdjango.utils.encodingr   r   Zdjango.utils.functionalr   Z#django.utils.six.moves.urllib.parser   r	   Zdjango.utils.translationr
   
exceptionsr   r   Z	resolversr   r   utilsr   r.   r4   r   r   	text_typeZreverse_lazyr+   r0   r   r3   r6   r   r8   rB   r   r   r   r   <module>   s,   		?		
