
 X                 @   s   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 d
 d   Z d d   Z d d   Z d d   Z d d   Z d S)    )unicode_literals)settings)six   )ErrorTagsWarningregisterc             K   s9   t  t d d   r5 d d l m } |   } t |  Sg  S)NZROOT_URLCONFr   )get_resolver)getattrr   django.urlsr
   check_resolver)Zapp_configskwargsr
   resolver r   E/home/ubuntu/projects/ifolica/build/django/django/core/checks/urls.pycheck_url_config	   s
    	
r   c             C   s   d d l  m } m } g  } x |  j D] } t | |  rd | j t |   | j t |   n8 t | |  r | j t |   n | j t	 |   | s& | j t
 |   q& q& W| S)z)
    Recursively check the resolver.
    r   )RegexURLPatternRegexURLResolver)r   r   r   Zurl_patterns
isinstanceextendcheck_include_trailing_dollarr   check_pattern_nameget_warning_for_invalid_patterncheck_pattern_startswith_slash)r   r   r   warningspatternr   r   r   r      s    r   c             C   sd   t  |  t j  r$ d j |   } n t  |  t  r< d } n d } t d j |   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 url() instead of a tuple.NzWYour URL pattern {!r} is invalid. Ensure that urlpatterns is a list of url() instances.hintidz	urls.E004)r   r   string_typesformattupler   )r   r   r   r   r   r   )   s    		r   c             C   sD   d j  |  j j  } t |  d d  r@ | d j  |  j  7} n  | S)zA
    Format the URL pattern for display in warning messages.
    z'{}'nameFz [name='{}'])r    regexr   r   r"   )r   descriptionr   r   r   describe_patternB   s    r%   c             C   s[   |  j  j } | j d  rS | j d  rS t d j t |    d d } | g Sg  Sd S)zK
    Check that include is not used with a regex ending with a dollar.
    $z\$zYour URL pattern {} uses include with a regex ending with a '$'. Remove the dollar from the regex to avoid problems including URLs.r   z	urls.W001N)r#   r   endswithr   r    r%   )r   regex_patternwarningr   r   r   r   L   s    	r   c             C   sg   |  j  j } t j s g  S| j d  s7 | j d  r_ t d j t |    d d } | g Sg  Sd S)zE
    Check that the pattern does not begin with a forward slash.
    /z^/zYour URL pattern {} has a regex 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 '/'.r   z	urls.W002N)r#   r   r   ZAPPEND_SLASH
startswithr   r    r%   )r   r(   r)   r   r   r   r   ]   s    		r   c             C   sN   |  j  d k	 rF d |  j  k rF t d j t |    d d } | g Sg  Sd S)z?
    Check that the pattern name does not contain a colon.
    N:zjYour URL pattern {} has a name including a ':'. Remove the colon, to avoid ambiguous namespace references.r   z	urls.W003)r"   r   r    r%   )r   r)   r   r   r   r   t   s    	r   N)
__future__r   Zdjango.confr   Zdjango.utilsr    r   r   r   r	   urlsr   r   r   r%   r   r   r   r   r   r   r   <module>   s   "	
