o
    <g5                     @   s   d dl Z d dlmZ d dlmZ d dlmZ ddlmZm	Z	m
Z
mZ ee	jdd Zd	d
 Zee	jdd ZdddZdd Zee	jdd Zdd Zee	jdd ZdS )    N)Counter)settings)ViewDoesNotExist   )ErrorTagsWarningregisterc                 K   s*   t tdd rddlm} | }t|S g S )NROOT_URLCONFr   get_resolver)getattrr   django.urlsr   check_resolver)app_configskwargsr   resolver r   J/var/www/html/venv/lib/python3.10/site-packages/django/core/checks/urls.pycheck_url_config
   s
   r   c                 C   s0   t | dd}|dur| S t| dst| S g S )z)
    Recursively check the resolver.
    checkNresolve)r   hasattrget_warning_for_invalid_pattern)r   check_methodr   r   r   r      s   
r   c           	      K   sn   t tddsg S ddlm} | }t|}t|}dd | D }g }|D ]}|td	|dd	 q&|S )
zD
    Warn if URL namespaces used in applications aren't unique.
    r
   Nr   r   c                 S   s   g | ]
\}}|d kr|qS )r   r   ).0ncountr   r   r   
<listcomp>.   s    z/check_url_namespaces_unique.<locals>.<listcomp>zZURL namespace '{}' isn't unique. You may not be able to reverse all URLs in this namespacez	urls.W005id)
r   r   r   r   _load_all_namespacesr   itemsappendr   format)	r   r   r   r   all_namespacescounternon_unique_namespaceserrors	namespacer   r   r   check_url_namespaces_unique!   s"   r*   r   c                    s^   t | dg } fdd|D }|D ]}t |dd} }|dur$||f7 }|t|| q|S )z<
    Recursively load all namespaces from URL patterns.
    url_patternsc                    s.   g | ]}t |d ddurd |jf qS )r)   N:)r   joinr)   )r   urlparentsr   r   r   @   s
    z(_load_all_namespaces.<locals>.<listcomp>r)   N)r   extendr!   )r   r0   r+   
namespacespatternr)   currentr   r/   r   r!   ;   s   

r!   c                 C   s@   t | trd| }n
t | trd}nd}td| |ddgS )z
    Return a list containing a warning that the pattern is invalid.

    describe_pattern() cannot be used here, because we cannot rely on the
    urlpattern having regex or name attributes.
    zkTry removing the string '{}'. The list of urlpatterns should not have a prefix string as the first element.z$Try using path() instead of a tuple.NziYour URL pattern {!r} is invalid. Ensure that urlpatterns is a list of path() and/or re_path() instances.z	urls.E004hintr    )
isinstancestrr$   tupler   )r3   r6   r   r   r   r   N   s   

r   c                 K   s8   g }dD ]}t t|}|r|ds|t| q|S )N)
STATIC_URL	MEDIA_URL/)r   r   endswithr#   E006)r   r   r(   namevaluer   r   r   check_url_settingsi   s   
rA   c                 C   s   t d| ddS )Nz%The {} setting must end with a slash.z	urls.E006r   )r   r$   )r?   r   r   r   r>   s   s   r>   c                 K   s  t tdd sg S ddlm} | }g }dD ]r\}}z||}W n/ ttfyO } z!t |jd| }	dj||	d}
|	t
|
t|dd	 W Y d }~qd }~ww t|}d g| }z|j|  W q ty   d
j||jd |j |dkrxdndd}
|	t
|
dd Y qw |S )Nr
   r   r   ))i     )i  rB   )i  rB   )i  r   z	handler%szDThe custom handler{status_code} view '{path}' could not be imported.)status_codepathz	urls.E008r5   zeThe custom handler{status_code} view '{path}' does not take the correct number of arguments ({args})..rB   zrequest, exceptionrequest)rC   rD   argsz	urls.E007r   )r   r   r   r   resolve_error_handlerImportErrorr   urlconf_moduler$   r#   r   r8   inspect	signaturebind	TypeError
__module____qualname__)r   r   r   r   r(   rC   num_parametershandlererD   msgrL   rG   r   r   r   check_custom_error_handlersz   s>   


rU   )r   )rK   collectionsr   django.confr   django.core.exceptionsr    r   r   r   r	   urlsr   r   r*   r!   r   rA   r>   rU   r   r   r   r   <module>   s"    
	


	