o
    {,h{                     @   s  d Z ddlZddlZddlZddl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 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 ddl m!Z! ddl"m#Z# ddl$m%Z%m&Z& ddl'm(Z( G dd dZ)d/ddZ*ej+d/ddZ,ej+dd Z-G dd dZ.G dd dZ/G d d! d!e/Z0ed"Z1e2ej3Z4ej5d#d$ Z6G d%d& d&Z7G d'd( d(e/Z8G d)d* d*Z9G d+d, d,Z:G d-d. d.Z;dS )0z
This module converts requested URLs to callback view functions.

URLResolver is the main class here. Its resolve() method takes a URL (as
a string) and returns a ResolverMatch object which provides access to all
attributes of the resolved URL match.
    N)import_module)PicklingError)quote)Local)settings)ErrorWarning)check_resolver)ImproperlyConfigured)MultiValueDict)cached_property)RFC3986_SUBDELIMSescape_leading_slashes)_lazy_re_compile	normalize)get_language   )get_converters)NoReverseMatchResolver404)get_callablec                   @   s<   e Zd Z							d
ddZdd Zdd Zdd	 ZdS )ResolverMatchNc                 C   s   || _ || _|| _|| _|| _|| _|	| _|
| _|r!dd |D ng | _d	| j| _
|r4dd |D ng | _d	| j| _t|drF|j}t|dsW|jjd |jj | _n	|jd |j | _|pd| j}d	| j|g | _d S )Nc                 S      g | ]}|r|qS  r   .0xr   r   K/var/www/html/rh/venv/lib/python3.10/site-packages/django/urls/resolvers.py
<listcomp>;       z*ResolverMatch.__init__.<locals>.<listcomp>:c                 S   r   r   r   r   r   r   r   r   =   r   
view_class__name__.)funcargskwargsurl_nameroutetriedcaptured_kwargsextra_kwargs	app_namesjoinapp_name
namespaces	namespacehasattrr!   	__class__
__module__r"   
_func_path	view_name)selfr$   r%   r&   r'   r,   r/   r(   r)   r*   r+   	view_pathr   r   r   __init__#   s&   


zResolverMatch.__init__c                 C   s   | j | j| jf| S N)r$   r%   r&   )r6   indexr   r   r   __getitem__L      zResolverMatch.__getitem__c                 C   sn   t | jtjrt| j}n| j}d|| j| j| j| j	| j
| j| jr'd| jnd| jr3d| jf	 S df	 S )NzbResolverMatch(func=%s, args=%r, kwargs=%r, url_name=%r, app_names=%r, namespaces=%r, route=%r%s%s)z, captured_kwargs= z, extra_kwargs=)
isinstancer$   	functoolspartialreprr4   r%   r&   r'   r,   r/   r(   r*   r+   )r6   r$   r   r   r   __repr__O   s,   zResolverMatch.__repr__c                 C   s   t d| jj d)NzCannot pickle r#   )r   r2   __qualname__)r6   protocolr   r   r   __reduce_ex__h   r<   zResolverMatch.__reduce_ex__)NNNNNNN)r"   r3   rC   r8   r;   rB   rE   r   r   r   r   r   "   s    
)r   c                 C   s   | d u rt j} t| S r9   )r   ROOT_URLCONF_get_cached_resolverurlconfr   r   r   get_resolverl   s   rJ   c                 C   s   t td| S N^/)URLResolverRegexPatternrH   r   r   r   rG   r   s   rG   c                 C   s.   t | }t||_t||j}tt d|gS rK   )rN   dict
convertersrM   url_patterns)
ns_patternresolverrP   patternns_resolverr   r   r   get_ns_resolverw   s   
rV   c                   @   s   e Zd ZdddZdd ZdS )LocaleRegexDescriptorNc                 C   sd   |du r| S |j }t|tr| ||jd< |jd S t }||jvr-| t||j|< |j| S )T
        Return a compiled regular expression based on the active language.
        Nregex)_regexr>   str_compile__dict__r   _regex_dict)r6   instanceclsrT   language_coder   r   r   __get__   s   



zLocaleRegexDescriptor.__get__c              
   C   s>   zt |W S  t jy } ztd| d| |d }~ww )N"z%" is not a valid regular expression: )recompileerrorr
   )r6   rY   er   r   r   r\      s   zLocaleRegexDescriptor._compiler9   )r"   r3   rC   rb   r\   r   r   r   r   rW      s    
rW   c                   @   s   e Zd Zdd Zdd ZdS )CheckURLMixinc                 C   s$   d | }| jr|d | j7 }|S )zI
        Format the URL pattern for display in warning messages.
        '{}'z [name='{}'])formatname)r6   descriptionr   r   r   describe   s   
zCheckURLMixin.describec                 C   sB   t jsg S | jdr| jdstd|  dd}|gS g S )zM
        Check that the pattern does not begin with a forward slash.
        )/rL   z^\/rn   zYour URL pattern {} has a route beginning with a '/'. Remove this slash as it is unnecessary. If this pattern is targeted in an include(), ensure the include() pattern has a trailing '/'.z	urls.W002id)r   APPEND_SLASHrZ   
startswithendswithr   rj   rm   r6   warningr   r   r   _check_pattern_startswith_slash   s   z-CheckURLMixin._check_pattern_startswith_slashN)r"   r3   rC   rm   rv   r   r   r   r   rh      s    	rh   c                   @   <   e Zd Ze ZdddZdd Zdd Zd	d
 Zdd Z	dS )rN   NFc                 C   s"   || _ i | _|| _|| _i | _d S r9   )rZ   r^   _is_endpointrk   rP   )r6   rY   rk   is_endpointr   r   r   r8      s
   
zRegexPattern.__init__c                 C   st   | j r| jjdr| j|n| j|}|r8| }|r dn| }dd | D }||	 d  ||fS d S )N$r   c                 S   s   i | ]\}}|d ur||qS r9   r   )r   kvr   r   r   
<dictcomp>   s    z&RegexPattern.match.<locals>.<dictcomp>)
rx   rY   rT   rs   	fullmatchsearch	groupdictgroupsitemsend)r6   pathmatchr&   r%   r   r   r   r      s   
zRegexPattern.matchc                 C   s*   g }| |   | js| |   |S r9   )extendrv   rx   _check_include_trailing_dollarr6   warningsr   r   r   check   s
   zRegexPattern.checkc                 C   s4   | j dr| j dstd|  ddgS g S )Nrz   z\$zYour URL pattern {} uses include with a route ending with a '$'. Remove the dollar from the route to avoid problems including URLs.z	urls.W001ro   )rZ   rs   r   rj   rm   r6   r   r   r   r      s   
	z+RegexPattern._check_include_trailing_dollarc                 C   
   t | jS r9   )r[   rZ   r   r   r   r   __str__      
zRegexPattern.__str__NF)
r"   r3   rC   rW   rY   r8   r   r   r   r   r   r   r   r   rN      s    
rN   z1<(?:(?P<converter>[^>:]+):)?(?P<parameter>[^>]+)>c                 C   s,  dg}t  }i }d}t| D ]l}t|d s td| d|jdd\}}| s7td| d|dz|| }	W n tyU }
 ztd| d	|d
|
d}
~
ww |	||< |	 \}}|
t| ||  |}|
d| d|	j d q|
t| |d  |r|
d d||fS )a  
    Convert a path pattern into a regular expression. Return the regular
    expression and a dictionary mapping the capture names to the converters.
    For example, 'foo/<int:pk>' returns '^foo\/(?P<pk>[0-9]+)'
    and {'pk': <django.urls.converters.IntConverter>}.
    ^r   z
URL route u3    cannot contain whitespace in angle brackets <…>.r[   )defaultz uses parameter name z' which isn't a valid Python identifier.z uses invalid converter r#   N(?P<>)z\Zr=   )r   _PATH_PARAMETER_COMPONENT_REfinditerwhitespace_set
isdisjointr
   r   isidentifierKeyErrorspanappendrd   escaperY   r-   )r(   ry   partsall_convertersrP   previous_endmatch_raw_converter	parameter	converterrg   startr   r   r   r   _route_to_regex   sB   

r   c                   @   s   e Zd ZdddZdS )LocaleRegexRouteDescriptorNc                 C   sp   |du r| S t |jtrt|j|jd< |jd S t }||jvr3tt	t|j|j
d |j|< |j| S )rX   NrY   r   )r>   _router[   rd   re   rZ   r]   r   r^   r   rx   )r6   r_   r`   ra   r   r   r   rb   &  s   



z"LocaleRegexRouteDescriptor.__get__r9   )r"   r3   rC   rb   r   r   r   r   r   %  s    r   c                   @   rw   )RoutePatternNFc                 C   s2   || _ tt||\| _| _i | _|| _|| _d S r9   )r   r   r[   rZ   rP   r^   rx   rk   )r6   r(   rk   ry   r   r   r   r8   =  s
   
zRoutePattern.__init__c              	   C   sv   | j |}|r9| }| D ]\}}| j| }z	||||< W q ty-   Y  d S w || d  d|fS d S Nr   )rY   r   r   r   rP   	to_python
ValueErrorr   )r6   r   r   r&   keyvaluer   r   r   r   r   D  s   
zRoutePattern.matchc                 C   sV   g |   |  }| j}d|v s|ds|dr)|td|  dd |S )Nr   r   rz   zYour URL pattern {} has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path().z2_0.W001ro   )	rv   '_check_pattern_unmatched_angle_bracketsr   rr   rs   r   r   rj   rm   )r6   r   r(   r   r   r   r   R  s   
zRoutePattern.checkc                 C   s   g }d}t dt| j}d}|D ](}|dkr|d7 }q|dkr9|d8 }|dk r9|t||  df dd d}q|dkrM|t||  df dd |S )	Nz2Your URL pattern %s has an unmatched '%s' bracket.z[<>]r   <r   r   z	urls.W010ro   )rd   findallr[   r   r   r   rm   )r6   r   msgbracketsopen_bracket_counterbracketr   r   r   r   c  s$   
z4RoutePattern._check_pattern_unmatched_angle_bracketsc                 C   r   r9   )r[   r   r   r   r   r   r   v  r   zRoutePattern.__str__r   )
r"   r3   rC   r   rY   r8   r   r   r   r   r   r   r   r   r   :  s    
r   c                   @   sN   e Zd ZdddZedd Zedd Zdd	 Zd
d Zdd Z	dd Z
dS )LocalePrefixPatternTc                 C   s   || _ i | _d S r9   )prefix_default_languagerP   )r6   r   r   r   r   r8   {  s   
zLocalePrefixPattern.__init__c                 C   s   t t | jS r9   )rd   re   r   language_prefixr   r   r   r   rY     s   zLocalePrefixPattern.regexc                 C   s(   t  ptj}|tjkr| jsdS d| S )Nr=   z%s/)r   r   LANGUAGE_CODEr   r6   ra   r   r   r   r     s   z#LocalePrefixPattern.language_prefixc                 C   s$   | j }||r||di fS d S r   )r   rr   removeprefix)r6   r   r   r   r   r   r     s   
zLocalePrefixPattern.matchc                 C   s   g S r9   r   r   r   r   r   r     s   zLocalePrefixPattern.checkc                 C   s
   d | S )Nri   )rj   r   r   r   r   rm     r   zLocalePrefixPattern.describec                 C   s   | j S r9   )r   r   r   r   r   r     s   zLocalePrefixPattern.__str__N)T)r"   r3   rC   r8   propertyrY   r   r   r   rm   r   r   r   r   r   r   z  s    


r   c                   @   sJ   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd Ze	dd Z
dS )
URLPatternNc                 C   s    || _ || _|p	i | _|| _d S r9   )rT   callbackdefault_argsrk   )r6   rT   r   r   rk   r   r   r   r8     s   

zURLPattern.__init__c                 C   s   d| j j| j f S )Nz<%s %s>)r2   r"   rT   rm   r   r   r   r   rB     s   zURLPattern.__repr__c                 C   s*   |   }|| j  ||   |S r9   )_check_pattern_namer   rT   r   _check_callbackr   r   r   r   r     s   zURLPattern.checkc                 C   s:   | j jdurd| j jv rtd| j  dd}|gS g S )zG
        Check that the pattern name does not contain a colon.
        Nr    zjYour URL pattern {} has a name including a ':'. Remove the colon, to avoid ambiguous namespace references.z	urls.W003ro   )rT   rk   r   rj   rm   rt   r   r   r   r     s   zURLPattern._check_pattern_namec                 C   sL   ddl m} | j}t|r$t||r$td| j |j	|j	f ddgS g S )Nr   )ViewzIYour URL pattern %s has an invalid view, pass %s.as_view() instead of %s.z	urls.E009ro   )
django.viewsr   r   inspectisclass
issubclassr   rT   rm   r"   )r6   r   viewr   r   r   r     s   zURLPattern._check_callbackc              	   C   sP   | j |}|r&|\}}}i || j}t| j||| j jt| j || jdS d S )N)r(   r*   r+   )rT   r   r   r   r   rk   r[   )r6   r   r   new_pathr%   r*   r&   r   r   r   resolve  s   
zURLPattern.resolvec                 C   sV   | j }t|tjr|j}t|dr|j}nt|ds#|jd |jj	 S |jd |j
 S )zw
        A string that identifies the view (e.g. 'path.to.view_function' or
        'path.to.ClassBasedView').
        r!   r"   r#   )r   r>   r?   r@   r$   r1   r!   r3   r2   r"   rC   )r6   r   r   r   r   
lookup_str  s   

zURLPattern.lookup_str)NN)r"   r3   rC   r8   rB   r   r   r   r   r   r   r   r   r   r   r     s    
r   c                   @   s   e Zd Z	d"ddZdd Zdd Zdd	 Zed
d Zedd Z	edd Z
ed#ddZedd Zdd Zdd Zedd Zedd Zdd Zdd Zd d! ZdS )$rM   Nc                 C   sT   || _ || _d | _|pi | _|| _|| _i | _i | _i | _t	 | _
d| _t | _d S r   )rT   urlconf_namer   default_kwargsr0   r.   _reverse_dict_namespace_dict	_app_dictset_callback_strs
_populatedr   _local)r6   rT   r   r   r.   r0   r   r   r   r8     s   
zURLResolver.__init__c                 C   sP   t | jtr| jrd| jd jj }nt| j}d| jj|| j| j| j	 f S )Nz	<%s list>r   z<%s %s (%s:%s) %s>)
r>   r   listr2   r"   rA   r.   r0   rT   rm   )r6   urlconf_reprr   r   r   rB     s   
zURLResolver.__repr__c                 C   s,   g }| j D ]	}|t| q|p| j S r9   )rQ   r   r	   rT   r   )r6   messagesrT   r   r   r   r     s   
zURLResolver.checkc                 C   s  t | jddr	d S zd| j_t }i }i }t }t| jD ]}|jjj}|	d}t
|tr^| j|j t|jjj}||j|||j|jjf |jd ur]||j|||j|jjf q|  |jrx||jg |j ||f||j< nf|jD ]0}|j|D ]'\}	}
}}t||
 }|||||
 i ||ji | jj|jj|f qq{|j D ]\}\}}|jj}|jj| || |f||< q|j  D ]\}}||g !| q| j|j q|| j"|< || j#|< || j$|< d| _%W d| j_d S d| j_w )N
populatingFTr   )&getattrr   r   r   r   reversedrQ   rT   rY   r   r>   r   r   addr   r   
appendlistr   r   rP   rk   	_populater.   
setdefaultr   r0   reverse_dictgetlistr   namespace_dictr   updateapp_dictr   r   r   r   r   )r6   lookupsr/   appsra   url_pattern	p_patternbitsrk   matchespatdefaultsrP   new_matchesr0   prefixsub_patterncurrent_convertersr.   namespace_listr   r   r   r     s   



	






zURLResolver._populatec                 C   "   t  }|| jvr|   | j| S r9   )r   r   r   r   r   r   r   r   k     

zURLResolver.reverse_dictc                 C   r   r9   )r   r   r   r   r   r   r   r   r  r   zURLResolver.namespace_dictc                 C   r   r9   )r   r   r   r   r   r   r   r   y  r   zURLResolver.app_dictc                    s4   |d u r|   g d S |  fdd|D  d S )Nc                 3   s    | ]} g|V  qd S r9   r   )r   trT   r   r   	<genexpr>  s    z,URLResolver._extend_tried.<locals>.<genexpr>)r   r   )r)   rT   	sub_triedr   r   r   _extend_tried  s   zURLResolver._extend_triedc                 C   s   | s|S | d}| | S )z<Join two routes, without the starting ^ in the second route.r   )r   )route1route2r   r   r   _join_route  s   
zURLResolver._join_routec                 C   s   | j s|   || jv S r9   )r   r   r   )r6   rk   r   r   r   _is_callback  s   
zURLResolver._is_callbackc                 C   sP  t |}g }| j|}|r|\}}}| jD ]}z||}W n ty> }	 z| |||	jd d W Y d }	~	qd }	~	ww |ri || j	}
|

|j |j}|
sX||j }t|tr_dnt |j}| |||j t|j||
|j| jg|j | jg|j | ||j||ji | j	|jd
  S ||g qt||dtd|i)Nr   r)   r=   )r*   r+   )r)   r   r   )r[   rT   r   rQ   r   r   r   r%   getr   r   r&   r>   r   r)   r   r$   r'   r.   r,   r0   r/   r   r(   r*   r+   r   )r6   r   r)   r   r   r%   r&   rT   	sub_matchrg   sub_match_dictsub_match_argscurrent_router   r   r   r     sT   

&

zURLResolver.resolvec                 C   s   t | jtrt| jS | jS r9   )r>   r   r[   r   r   r   r   r   urlconf_module  s   
zURLResolver.urlconf_modulec              
   C   sP   t | jd| j}zt| W |S  ty' } zd}t|j| jd|d }~ww )NurlpatternszThe included URLconf '{name}' does not appear to have any patterns in it. If you see the 'urlpatterns' variable with valid patterns in the file then the issue is probably caused by a circular import.)rk   )r   r   iter	TypeErrorr
   rj   r   )r6   patternsrg   r   r   r   r   rQ     s   
	zURLResolver.url_patternsc                 C   s8   t | jd| d }|sddlm} t |d| }t|S )Nz	handler%sr   )urls)r   r   django.confr  r   )r6   	view_typer   r  r   r   r   resolve_error_handler  s
   z!URLResolver.resolve_error_handlerc                 O   s   | j |dg|R i |S )Nr=   )_reverse_with_prefix)r6   lookup_viewr%   r&   r   r   r   reverse  s   zURLResolver.reversec                 O   s  |r|rt d| js|   | j|}|D ]\}}}}	|D ]\}
}|r6t|t|kr.qtt||}n,t|	|
|rAqd}| D ]\}}||v rPqG||||kr\d} nqG|s`q|}i }d}| D ]&\}}||	v rz|	| |||< W qj t y   d}Y  nw t|||< qj|sq|dd|
 }tdt||f || rt|| td d}t|    S qqt|d	d }t|d
d }|d ur|d urd||f }n|}dd |D }|r|rd|f }n	|rd| }nd}d||t||f }t|dd|i }t|)Nz2Don't mix *args and **kwargs in call to reverse()!TF%z%%z^%s%sz/~:@)safer3   r"   z%s.%sc                 S   s   g | ]\}}}}|qS r   r   )r   _rT   r   r   r   r   ,  s    z4URLResolver._reverse_with_prefix.<locals>.<listcomp>zarguments '%s'zkeyword arguments '%s'zno argumentsz;Reverse for '%s' with %s not found. %d pattern(s) tried: %szZReverse for '%(view)s' not found. '%(view)s' is not a valid view function or pattern name.r   )r   r   r   r   r   lenrO   zipr   symmetric_difference
differencer   r   to_urlr[   replacerd   r   r   r   r   r   r   r   )r6   r
  _prefixr%   r&   possibilitiespossibilityrT   r   rP   resultparamscandidate_subsr   r{   r|   text_candidate_subsr   candidate_paturlmnlookup_view_sr  arg_msgr   r   r   r   r	    s   3
z URLResolver._reverse_with_prefix)NNNr9   )r"   r3   rC   r8   rB   r   r   r   r   r   r   staticmethodr   r   r   r   r   r   rQ   r  r  r	  r   r   r   r   rM     s2    
T



0


rM   r9   )<__doc__r?   r   rd   string	importlibr   pickler   urllib.parser   asgiref.localr   r  r   django.core.checksr   r   django.core.checks.urlsr	   django.core.exceptionsr
   django.utils.datastructuresr   django.utils.functionalr   django.utils.httpr   r   django.utils.regex_helperr   r   django.utils.translationr   rP   r   
exceptionsr   r   utilsr   r   rJ   cacherG   rV   rW   rh   rN   r   	frozenset
whitespacer   	lru_cacher   r   r   r   r   rM   r   r   r   r   <module>   sR    
J

"2

+@"Q