o
    uvXj  ã                   @   sÞ   d dl mZ 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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„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 )!é    )Úlocal)ÚurlsplitÚ
urlunsplit)Ú
iri_to_uri)Úlazy)Úoverrideé   )ÚNoReverseMatchÚResolver404)Úget_ns_resolverÚget_resolver)Úget_callableNc                 C   s   |d u rt ƒ }t|ƒ | ¡S ©N)Úget_urlconfr   Úresolve©ÚpathÚurlconf© r   úM/var/www/html/myproject/venv/lib/python3.10/site-packages/django/urls/base.pyr      s   r   c              
   C   s¢  |d u rt ƒ }t|ƒ}|pg }|pi }tƒ }t| tƒs| }n¤|  d¡}| ¡  |d }|dd … }	|r=| d¡}
|
 ¡  nd }
g }d}i }|	r¶|	 ¡ }|
rQ|
 ¡ nd }z|j| }|rb||v rb|}n||vrj|d }W n	 t	yt   Y nw ||kr{d }
z|j
| \}}| |¡ || }| |jj¡ W n t	y³ } z|r©td|d |¡f ƒ‚td| ƒ‚d }~ww |	sG|rÂt||t| ¡ ƒƒ}t|j||g|¢R i |¤Žƒ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Ú
isinstanceÚstrÚsplitÚreverseÚpopÚapp_dictÚKeyErrorÚnamespace_dictÚappendÚupdateÚpatternÚ
convertersr	   Újoinr   ÚtupleÚitemsr   Ú_reverse_with_prefix)Úviewnamer   ÚargsÚkwargsÚcurrent_appÚresolverÚprefixÚviewÚpartsr   Úcurrent_pathÚresolved_pathÚ
ns_patternÚns_convertersÚnsÚ
current_nsÚapp_listÚextraÚkeyr   r   r   r      sj   




€ÿ
ÿÿ€ùæ"r   c                   C   s   t  ¡  t ¡  t ¡  d S r   )r   Úcache_clearr   r   r   r   r   r   Úclear_url_caches`   s   r;   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_prefixf   s   

r@   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    zt `W dS  ty   Y dS w )z9
    Unset the script prefix for the current thread.
    N)r>   r?   ÚAttributeErrorr   r   r   r   Úclear_script_prefixx   s
   
ÿrC   c                 C   s$   | r| t _dS tt dƒrt `dS 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)Úurlconf_namer   r   r   Úset_urlconf‚   s
   

ÿrG   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?   )rA   rD   )Údefaultr   r   r   r   Ž   s   r   c                 C   s&   zt | |ƒ W dS  ty   Y dS w )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.
    TF)r   r
   r   r   r   r   Úis_valid_path–   s   
ÿrI   c              	   C   sÊ   t | ƒ}zt|jƒ}W n
 ty   Y | S w |jr!d|j|jf n|j}t|ƒ�3 zt||j|j	d�} W n	 t
y=   Y nw t|j|j| |j|jfƒ} W d  ƒ | S W d  ƒ | S 1 s^w   Y  | 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+   N)r   r   r   r
   Ú	namespaceÚurl_namer   r   r*   r+   r	   r   ÚschemeÚnetlocÚqueryÚfragment)ÚurlÚ	lang_codeÚparsedÚmatchÚto_be_reversedr   r   r   Útranslate_url£   s,   
õ
ÿ
úý
üùrU   r   )NNNN)!Ú	threadingr   Úurllib.parser   r   Údjango.utils.encodingr   Údjango.utils.functionalr   Údjango.utils.translationr   Ú
exceptionsr	   r
   Ú	resolversr   r   Úutilsr   r>   rD   r   r   r   Úreverse_lazyr;   r@   r   rC   rG   r   rI   rU   r   r   r   r   Ú<module>   s*    


B		


