3
g$                 @   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   m/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django_extensions/management/commands/show_urls.pyr      s   r   c               @   s   e Zd ZdS )RegexURLResolverN)r   r   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdS )LocaleRegexURLResolverN)r   r   r   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jsonz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| |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j  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 k	rLtj fddttdg D | _nttdd6| _|d }|sldg}|d }|tkrtd	|d
j	t
tj f |dk}|rd}t| }|d }g }	tt|stdjt|yttt|i i dg}W nX tk
rJ }
 z:|d r dd l}|j  tdtt|t|
f W Y d d }
~
X nX | j|j}xN|D ]D\}}}t|dr|j nt|dr|j ni   fdd|D }t|tjr|j}|jdd t|dr|j}t|dr|j}n,t|dr
d|jj }ntj ddt!|}dj|j"|}|p2d}t#|}d
j	|}|dkrf|	j$||||d n>|	j$|jdj|j%|j"|j&||j'||j(||dj)  q`W |d  r|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 }|j&d'|j&d(|j&d)|j&d*f}|j$d+j	d,d- t*|D  |j$d.j	d/d- D  x.|	D ]&}|j$d+j	d0d- t*|D  qW |}	n(|dkr|rt+j,|	d1d2S t+j,|	S d3j	d4d |	D d3 S )7Nno_colorr%   c                s    g | ]\}}| kr||fqS r   r   ).0codename)r%   r   r   
<listcomp>N   s    z"Command.handle.<locals>.<listcomp>	LANGUAGESr'   Zlogin_requiredr)   z-Format style '%s' does not exist. Options: %sz, zpretty-jsonr   r*   z2Settings module {} does not have the attribute {}.r   	tracebackr   z*Error occurred while trying to load %s: %s__globals__func_globalsc                s   g | ]}| kr|qS r   r   )r4   d)r;   r   r   r7   z   s    zfunctools.partial
view_classr   r2   z%s()z at 0x[0-9a-f]+z{0}.{1})urlmoduler6   
decorators)r?   url_namer>   r'   r!   r   c             S   s   g | ]}|j d dqS ),   )split)r4   rowr   r   r   r7      s    c             S   s   g | ]}t t|t d qS ))key)lenmax)r4   columnsr   r   r   r7      s    c                s&   g | ]}d j dd t |D qS )z   c             s   s   | ]\}}d j ||V  qdS )z{0:<{1}}N)format)r4   widthcdatar   r   r   	<genexpr>   s    z,Command.handle.<locals>.<listcomp>.<genexpr>)joinzip)r4   rE   )widthsr   r   r7      s   r   c             S   s   g | ]}|j d dqS )rB   rC   )rD   )r4   rE   r   r   r   r7      s    c             S   s   g | ]}t t|t d qS ))rF   )rG   rH   )r4   rI   r   r   r   r7      s    URLModuleNameZ	Decoratorz | c             s   s   | ]\}}d j ||V  qdS )z{0:<{1}}N)rJ   )r4   rK   titler   r   r   rM      s    z!Command.handle.<locals>.<genexpr>z-+-c             s   s   | ]}d | V  qdS )-Nr   )r4   rK   r   r   r   rM      s    c             s   s   | ]\}}d j ||V  qdS )z{0:<{1}}N)rJ   )r4   rK   rL   r   r   r   rM      s       )indent
c             S   s   g | ]}|qS r   r   )r4   vr   r   r   r7      s    NN)rZ   )-r	   r   r   activategetattrr   r8   r.   r   rN   sortedr/   hasattrrJ   
__import__	Exceptionr9   	print_excr   extract_views_from_urlpatternsurlpatternsr:   r;   
isinstance	functoolspartialfuncinsertr=   r   r2   resubreprr   r   r&   MODULEZMODULE_NAMEZURL_NAMErQ   striprO   r   dumps)r0   argsoptionsstyler'   r)   Zpretty_jsonZfmtrr*   viewser9   Zview_functionsrg   regexrA   r@   	func_namer?   r>   Ztable_viewsheaderrE   r   )r;   r%   rP   r   handleG   s    


,






$
"

zCommand.handler   Nc             C   s
  g }x|D ]}t |ttfryJ|js0|j}n|rDdj||j}n|j}t|}|j|j|| |f W n tk
r   wY nX qt |t	t
frPy
|j}W n tk
r   wY nX |r|jrdj||j}	n
|jp|}	t|}t |tr4x^| jD ]8}
tj|
d   |j| j||| |	d W dQ R X qW n|j| j||| |	d qt|dry"|j|j |t| |jf W n tk
r   wY nX qt|dst|dry
|j}W n tk
r   wY nX |j| j||t| |d qtd| qW |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)rd   r   r   r6   rJ   r   r&   callbackr   r   r   rz   ImportErrorrx   r   r8   r   overrideextendrb   r^   ry   	TypeError)r0   rc   baserx   rr   r   r6   r   patterns
_namespacer%   r   r   r   rb      sP    



*"

 z&Command.extract_views_from_urlpatterns)r   N)	r   r   r   r$   r,   r
   rw   rb   __classcell__r   r   )r2   r   r   -   s   wr   )re   r   ri   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   r.   r   r   r   r   r   <module>   s*   