a
    8Xh$                     @   s   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
mZ d dlmZ d dlmZmZ d dlmZ d d	lmZmZ G d
d dZG dd dZG dd dZdd ZdddddddZG dd de
ZdS )    N)settings)simplify_regex)ViewDoesNotExist)BaseCommandCommandError)translation)color_styleno_style)signalcommand)
URLPatternURLResolverc                   @   s   e Zd ZdS )RegexURLPatternN__name__
__module____qualname__ r   r   t/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/django_extensions/management/commands/show_urls.pyr      s   r   c                   @   s   e Zd ZdS )RegexURLResolverNr   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )LocaleRegexURLResolverNr   r   r   r   r   r      s   r   c                 C   s
   t | jS )N)strpattern)pr   r   r   describe_pattern   s    r   z%{url}	{module}	{url_name}	{decorator}z%{url},{module},{url_name},{decorator}zK{url}
	Controller: {module}
	URL Name: {url_name}
	Decorators: {decorator}
 )densetablealignedverbosejsonpretty-jsonc                       s6   e Zd ZdZ fddZedd Zd
dd	Z  ZS )Commandz8Displays all of the url matching routes for the project.c                    s|   t  | |jdddddd |jddd	d
d |jddddg dd |jdddddt  d |jdddddd d S )Nz
--unsortedz-u
store_trueunsortedz:Show urls unsorted but same order as found in url patterns)actiondesthelpz
--languagez-llanguagez7Only show this language code (useful for i18n_patterns))r%   r&   z--decoratorz-dappend	decoratorz-Show the presence of given decorator on views)r$   r%   defaultr&   z--formatz-fformat_styler   z Style of the output. Choices: %s)r%   r*   r&   z	--urlconfz-curlconfZROOT_URLCONFz)Set the settings URL conf variable to use)superadd_argumentsadd_argumentFMTRkeys)selfparser	__class__r   r   r.   0   s*    

zCommand.add_argumentsc              
      s  |d rt  nt }|d d urLt fddttdg D | _nttdd| _|d }|sldg}|d	 }|tvrtd
|d	t
t f |dk}|rd}t| }|d }g }	tt|stdt|zttt|i i dg}W nZ tyL }
 z@|d rdd l}|  tdtt|t|
f W Y d }
~
n
d }
~
0 0 | |j}|D ]D\}}}t|dr~|j nt|dr|j ni   fdd|D }t|tjr|j}|dd t|dr|j}t|dr|j}n,t|drd|jj }nt ddt!|}d|j"|}|p0d}t#|}d	|}|dkrd|	$||||d n>|	$|jd|%|j"|&||'||(||d)  q^|d  s|dkrt
|	}	|d!kr d"d |	D }	d#d t*|	 D fd$d|	D }	n|d%krd&d |	D }	d'd t*|	 D g }|&d(|&d)|&d*|&d+f}|$d,	d-d. t*|D  |$d/	d0d. D  |	D ]&}|$d,	d1d. t*|D  q|}	n(|dkr|rt+j,|	d2d3S t+,|	S d4	d5d |	D d4 S )6Nno_colorr'   c                    s    g | ]\}}| kr||fqS r   r   ).0codename)r'   r   r   
<listcomp>N       z"Command.handle.<locals>.<listcomp>	LANGUAGES))NNr)   Zlogin_requiredr+   z-Format style '%s' does not exist. Options: %sz, r    r   r,   z2Settings module {} does not have the attribute {}.r   	tracebackr   z*Error occurred while trying to load %s: %s__globals__func_globalsc                    s   g | ]}| v r|qS r   r   )r7   d)r?   r   r   r:   z   r;   zfunctools.partial
view_classr   r5   z%s()z at 0x[0-9a-f]+z{0}.{1})urlmoduler9   
decorators)rC   url_namerB   r)   r#   r   c                 S   s   g | ]}| d dqS ,   splitr7   rowr   r   r   r:      r;   c                 S   s   g | ]}t t|t d qS )keylenmaxr7   columnsr   r   r   r:      r;   c                    s&   g | ]}d  dd t |D qS )z   c                 s   s   | ]\}}d  ||V  qdS z{0:<{1}}Nformatr7   widthcdatar   r   r   	<genexpr>   r;   z,Command.handle.<locals>.<listcomp>.<genexpr>)joinziprK   )widthsr   r   r:      s   r   c                 S   s   g | ]}| d dqS rF   rI   rK   r   r   r   r:      r;   c                 S   s   g | ]}t t|t d qS rM   rO   rR   r   r   r   r:      r;   URLModuleNameZ	Decoratorz | c                 s   s   | ]\}}d  ||V  qdS rT   rU   )r7   rX   titler   r   r   rZ      r;   z!Command.handle.<locals>.<genexpr>z-+-c                 s   s   | ]}d | V  qdS )-Nr   )r7   rX   r   r   r   rZ      r;   c                 s   s   | ]\}}d  ||V  qdS rT   rU   rW   r   r   r   rZ      r;      )indent
c                 S   s   g | ]}|qS r   r   )r7   vr   r   r   r:      r;   )-r	   r   r   activategetattrr   r<   r0   r   r[   sortedr1   hasattrrV   
__import__	Exceptionr=   	print_excr   extract_views_from_urlpatternsurlpatternsr>   r?   
isinstance	functoolspartialfuncinsertrA   r   r5   resubreprr   r   r(   MODULEZMODULE_NAMEZURL_NAMEr^   stripr\   r   dumps)r2   argsoptionsstyler)   r+   Zpretty_jsonZfmtrr,   viewser=   Zview_functionsrs   regexrE   rD   	func_namerC   rB   Ztable_viewsheaderrL   r   )r?   r'   r]   r   handleG   s    


0





$

zCommand.handler   Nc              
   C   s  g }|D ]}t |ttfrzJ|js,|j}n|r@d||j}n|j}t|}||j|| |f W n ty|   Y qY n0 qt |t	t
fr^z
|j}W n ty   Y qY n0 |r|jrd||j}	n
|jp|}	t|}t |trB| jD ]N}
t|
d * || j||| |	d W d   q1 s40    Y  qn|| j||| |	d qt|drz"|| |t| |jf W n ty   Y qY n0 qt|dst|drz
|j}W n ty   Y qY n0 || j||t| |d qtd| q|S )	z
        Return a list of views from a list of urlpatterns.

        Each object in the returned list is a three-tuple: (view_func, regex, name)
        z{0}:{1}r   )	namespaceN_get_callbackurl_patternsZ_get_url_patternsz,%s does not appear to be a urlpattern object)rp   r   r   r9   rV   r   r(   callbackr   r   r   r   ImportErrorr   r   r<   r   overrideextendrn   rj   r   	TypeError)r2   ro   baser   r~   r   r9   r   patterns
_namespacer'   r   r   r   rn      sP    





>"

 z&Command.extract_views_from_urlpatterns)r   N)	r   r   r   r&   r.   r
   r   rn   __classcell__r   r   r4   r   r!   -   s
   
vr!   )rq   r   ru   Zdjango.confr   Zdjango.contrib.admindocs.viewsr   Zdjango.core.exceptionsr   Zdjango.core.management.baser   r   Zdjango.utilsr   Z"django_extensions.management.colorr   r	   Z"django_extensions.management.utilsr
   Zdjango.urlsr   r   r   r   r   r   r0   r!   r   r   r   r   <module>   s,   
