U
    a                     @   s   d dl mZmZ d dlmZ 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mZmZ dd	lmZ e Ze ZdddZd ddZeee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 )#    )urlsplit
urlunsplit)Local)
iri_to_uri)lazy)override   )NoReverseMatchResolver404)_get_cached_resolverget_ns_resolverget_resolver)get_callableNc                 C   s   |d krt  }t|| S N)get_urlconfr   resolvepathurlconf r   /home/adriano.carvalho/ftp/files/BrinquedotecaVirtual/brinquedotecavirtual/venv/lib/python3.8/site-packages/django/urls/base.pyr      s    r   c                 C   s  |d krt  }t|}|pg }|p$i }t }t| ts>| }n@| d^ }}|rf|d}	|	  nd }	g }
d}i }|D ]}|	r|	 nd }z0|j| }|r||kr|}n||kr|d }W n t	k
r   Y nX ||krd }	z2|j
| \}}|
| || }||jj W qz t	k
r` } z.|
rDtd|d|
f ntd| W 5 d }~X Y qzX qz|r~t||t| }t|j||f||S )N: r   z,%s is not a registered namespace inside '%s'z %s is not a registered namespace)r   r   get_script_prefix
isinstancestrsplitreversepopZapp_dictKeyErrorZnamespace_dictappendupdatepattern
convertersr	   joinr   tupleitemsr   Z_reverse_with_prefix)Zviewnamer   argskwargsZcurrent_appresolverprefixviewr   current_pathresolved_pathZ
ns_patternZns_convertersnsZ
current_nsZapp_listextrakeyr   r   r   r      sX    




 r   c                   C   s   t   t  t  d S r   )r   cache_clearr   r   r   r   r   r   clear_url_caches]   s    r2   c                 C   s   |  ds| d7 } | t_dS )z7
    Set the script prefix for the current thread.
    /N)endswith	_prefixesvalue)r*   r   r   r   set_script_prefixc   s    
r7   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).
    r6   r3   )getattrr5   r   r   r   r   r   l   s    r   c                   C   s"   zt `W n tk
r   Y nX dS )z9
    Unset the script prefix for the current thread.
    N)r5   r6   AttributeErrorr   r   r   r   clear_script_prefixu   s    r:   c                 C   s   | r| t _ntt drt `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.
    r6   N)	_urlconfsr6   hasattr)Zurlconf_namer   r   r   set_urlconf   s    
r=   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.
    r6   )r8   r;   )defaultr   r   r   r      s    r   c                 C   s,   zt | | W dS  tk
r&   Y dS X d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   is_valid_path   s
    
r?   c              	   C   s   t | }zt|j}W n tk
r*   Y nxX |jrBd|j|jf n|j}t|L zt||j|j	d} W n t
k
r|   Y nX t|j|j| |j|jf} W 5 Q R X | 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:%s)r'   r(   )r   r   r   r
   	namespaceZurl_namer   r   r'   r(   r	   r   schemenetlocqueryfragment)urlZ	lang_codeparsedmatchZto_be_reversedr   r   r   translate_url   s    
$rH   )N)NNNN)N)N)"urllib.parser   r   Zasgiref.localr   Zdjango.utils.encodingr   Zdjango.utils.functionalr   Zdjango.utils.translationr   
exceptionsr	   r
   Z	resolversr   r   r   utilsr   r5   r;   r   r   r   Zreverse_lazyr2   r7   r   r:   r=   r   r?   rH   r   r   r   r   <module>   s(   

>
		


