a
    ތxdX	                     @   s^   d dl Z d dlZd dlmZ d dlmZ G dd dZdddZdd	d
Zdd Z	dd Z
dS )    N)escape)tokensc                   @   s   e Zd ZdZdd ZdS )BoldKeywordFilterz$sqlparse filter to bold SQL keywordsc                 c   sJ   |D ]@\}}|t jv }|r&t jdfV  |t|fV  |rt jdfV  qdS )zProcess the token streamz<strong>z	</strong>N)TKeywordTextr   )selfstream
token_typevalueZ
is_keyword r   V/var/www/html/Ranjet/env/lib/python3.9/site-packages/debug_toolbar/panels/sql/utils.pyprocess   s    
zBoldKeywordFilter.processN)__name__
__module____qualname____doc__r   r   r   r   r   r      s   r   Fc                 C   s@   t | dd}|s|S tt | dd}d|}d|}|| S )NT)aligned_indentFz*<span class="djDebugUncollapsed">{}</span>z4<span class="djDebugCollapsed djdt-hidden">{}</span>)	parse_sqlsimplifyformat)sqlZwith_toggle	formattedsimpleZuncollapsed	collapsedr   r   r   reformat_sql   s    

r   c                 C   s^   t j }|  |r.|jt jjddd |jt	  |j
t j  d|| S )Nz&nbsp;z<br/>)charn )sqlparseZengineZFilterStackZenable_groupingZstmtprocessappendfiltersZAlignedIndentFilter
preprocessr   postprocessZSerializerUnicodejoinrun)r   r   stackr   r   r   r       s    
r   c                 C   s   d}d}t ||| S )Nz,SELECT</strong> (...........*?) <strong>FROMz2SELECT</strong> &#8226;&#8226;&#8226; <strong>FROM)resub)r   exprr(   r   r   r   r   ,   s    r   c                  #   s   dd } g d}d g dg} dkr,dV  t |}|D ]<|D ]2 fdd	td
D }|| | |V  q@q8 dL  qdS )z
    Generate constrasting colors by varying most significant bit of RGB first,
    and then vary subsequent bits systematically.
    c                 S   s   dt |  S )Nz#%02x%02x%02x)tuple)rgbr   r   r   
rgb_to_hex8   s    z/contrasting_color_generator.<locals>.rgb_to_hex))   r   r   )r   r-   r   )r   r   r-   )r-   r-   r   )r   r-   r-   )r-   r   r-   )r-   r-   r-      )r   r   r   r   z#000000c                    s    g | ]} |  |  qS r   r   ).0ir   previousZtripler   r   
<listcomp>L       z/contrasting_color_generator.<locals>.<listcomp>   r-   N)listranger    )r,   ZtriplesZso_farZcopy_so_farr+   r   r1   r   contrasting_color_generator2   s    	

r8   )F)F)r'   r   Zdjango.utils.htmlr   r   r   r   r   r   r   r8   r   r   r   r   <module>   s   


