o
    Mf	                     @   sj   d dl Z d dlZd dlm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)tokens)settingsc                   @   s   e Zd ZdZdd ZdS )BoldKeywordFilterz$sqlparse filter to bold SQL keywordsc                 c   sL    |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value
is_keyword r   `/var/www/html/analyze/labelStudio/lib/python3.10/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)sqlwith_toggle	formattedsimpleuncollapsed	collapsedr   r   r   reformat_sql   s   

r   c                 C   sj   t j }t d r|  |r|jt jj	ddd |j
t  |jt j  d|| S )NPRETTIFY_SQLz&nbsp;z<br/>)charn )sqlparseengineFilterStackdt_settings
get_configenable_groupingstmtprocessappendfiltersAlignedIndentFilter
preprocessr   postprocess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   exprr5   r   r   r   r   /   s   r   c                  #   s    dd } g d}d g dg}	  dkrdV  t |}|D ]|D ] fd	d
tdD }|| | |V  q"q dL  q)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_hex;   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   Tr   z#000000c                    s    g | ]} |  |  qS r   r   ).0ir"   previoustripler   r   
<listcomp>O   s     z/contrasting_color_generator.<locals>.<listcomp>   r:   )listranger+   )r9   triplesso_farcopy_so_farr8   r   r>   r   contrasting_color_generator5   s"   	

rH   )F)r4   r$   django.utils.htmlr   r   r   debug_toolbarr   r'   r   r   r   r   rH   r   r   r   r   <module>   s    


