U
    mf                      @   s   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dS )    )Counter)settings   )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   ;/tmp/pip-unpacked-wheel-siwebuq3/django/core/checks/urls.pycheck_url_config   s
    r   c                 C   s4   t | dd}|dk	r| S t| ds,t| S g S dS )z)
    Recursively check the resolver.
    checkNresolve)r   hasattrget_warning_for_invalid_pattern)r   Z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	 qL|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   Zall_namespacescounterZnon_unique_namespaceserrors	namespacer   r   r   check_url_namespaces_unique   s$    r&   r   c                    s^   t | dg } fdd|D }|D ]6}t |dd} }|dk	rH||f7 }|t|| q"|S )z<
    Recursively load all namespaces from URL patterns.
    url_patternsc                    s.   g | ]&}t |d ddk	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   r,   r'   
namespacespatternr%   currentr   r+   r   r   9   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   )r/   r1   r   r   r   r   L   s     

r   c                 K   s8   g }dD ]*}t t|}|r|ds|t| q|S )N)Z
STATIC_URLZ	MEDIA_URL/)r   r   endswithr!   E006)r   r   r$   namevaluer   r   r   check_url_settingsg   s    
r:   c                 C   s   t d| ddS )Nz%The {} setting must end with a slash.z	urls.E006r   )r   r"   )r8   r   r   r   r7   q   s    r7   N)r   )collectionsr   Zdjango.confr    r   r   r   r   urlsr   r   r&   r   r   r:   r7   r   r   r   r   <module>   s   
	


	