
    7 f77                        d Z ddlZddlZ	 ddlmZ n# e$ r	 ddlmZ Y nw xY wddlZ	ddl
Z
ddlZ
ddlmZmZmZmZ ddlmZ ddlmZ 	 ddlmZ d Zn'# e$ r dd	lmZmZmZmZ  G d
 d          Zd ZY nw xY w G d de          ZdZdZd Ze
j         dk     r e!d          d Z"d Z#d Z$d Z% G d de	j&        j'        e	j&        j(                  Z) G d de	j&        j*                  Z*d Z+d Z,d Z-d dZ.dS )!z$The Django template coverage plugin.    N)NoSource)LexerNodeListTemplateTextNode)VerbatimNode)BlockTranslateNode)	TokenTypec                 8    | j                                          d S N)name
capitalize
token_types    S/var/www/equiseq/venv/lib/python3.11/site-packages/django_coverage_plugin/plugin.py_token_namer      s    ""$$$$$    )TOKEN_BLOCKTOKEN_MAPPING
TOKEN_TEXT	TOKEN_VARc                       e Zd ZeZeZeZdS )r
   N)	__name__
__module____qualname__r   TEXTr   VARr   BLOCK r   r   r
   r
   $   s        r   r
   c                     t           |          S r   )r   r   s    r   r   r   )   s    Z((r   c                       e Zd ZdZdS )DjangoTemplatePluginExceptionz+Used for any errors from the plugin itself.N)r   r   r   __doc__r   r   r   r"   r"   -   s        55Dr   r"   Fc                  D   ddl m}  | j        sdS ddlm} |j        sdS t          t          j        d          sdS t          t          j        j	        d          sdS t          t          j        j	        j        d          st          d          t          j        j        j        sdS t          j        j                                        D ]U}t          |t          j        j	        j        j                  st          d          |j        j        st          d	          Vd
S )a-  Check that Django's template debugging is enabled.

    Django's built-in "template debugging" records information the plugin needs
    to do its work.  Check that the setting is correct, and raise an exception
    if it is not.

    Returns True if the debug check was performed, False otherwise
    r   settingsF)appsbackendsdjangoDjangoTemplateszCan't use non-Django templates.z/Template debugging must be enabled in settings.T)django.confr&   
configureddjango.appsr'   readyhasattrr)   templater(   r"   engines_enginesall
isinstancer*   enginedebug)r&   r'   r5   s      r   check_debugr7   7   sB    %$$$$$ u !     : u 6?J// u6?+X66 u6?+24EFF O+,MNNN?"+ u/)--//  &&/":"A"QRR 	/1   }" 	/A  	
 4r   )   r   z4Django Coverage Plugin requires Django 2.x or higherc                 b    	 | j         d         j        j        S # t          t          f$ r Y d S w xY w)Nself)f_localsoriginr   KeyErrorAttributeError)frames    r   filename_for_framer@   i   sA    ~f%,11n%   tts    ..c                 >    	 | j         j        S # t          $ r Y d S w xY wr   )tokenpositionr>   )nodes    r   position_for_noderE   p   s4    z""   tts    
c                     | j         S r   )rC   )rB   s    r   position_for_tokenrG   w   s
    >r   c                    ddl m} |j        s|                                 t	          | d          5 }t
          j        dk    rd}n|j        }|                                	                    |          }ddd           n# 1 swxY w Y   |S )zARead the source of a Django template, returning the Unicode text.r   r%   rb)      zutf-8N)
r+   r&   r,   	configureopenr)   VERSIONFILE_CHARSETreaddecode)filenamer&   fcharsettexts        r   read_template_sourcerV   {   s     %$$$$$ 	h		 ( >V##GG+Gvvxxw''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( Ks   AB  BBc                   R    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dd	hZ
d
 Zd Zd ZdS )DjangoTemplatePluginc                 p   |                     dd          }d |                    d          D             | _        d| _        t          j                            t          j                            t          j                            t          j
        j                                      | _        i | _        d S )Ntemplate_extensionszhtml,htm,txtc                 6    g | ]}|                                 S r   )strip).0es     r   
<listcomp>z1DjangoTemplatePlugin.__init__.<locals>.<listcomp>   s     DDD17799DDDr   ,F)getsplit
extensionsdebug_checkedospathnormcaserealpathdirnamer)   r0   __file__django_template_dir
source_map)r:   optionsrc   s      r   __init__zDjangoTemplatePlugin.__init__   s    [[!6GG
DDj.>.>s.C.CDDD"#%7#3#3BG4D4DGOOFO4555
 5
 $ $  r   c                     d| j         fdt          d t          j                                        D                       fgS )Nrk   environmentc              3   P   K   | ]!\  }}d |v 	d                     ||          V  "dS )DJANGOz{} = {}N)format)r]   kvs      r   	<genexpr>z0DjangoTemplatePlugin.sys_info.<locals>.<genexpr>   sH       # #Aqq== !!!Q'' ===# #r   )rk   sortedre   environitemsr:   s    r   sys_infozDjangoTemplatePlugin.sys_info   sU    "D$<=F # #J,,..# # #   
 	
r   c                 t    t           j                            |                    d                    | _        d S )Nzhtml:directory)re   rf   abspath
get_optionhtml_report_dir)r:   configs     r   rL   zDjangoTemplatePlugin.configure   s-    !wv/@/@AQ/R/RSSr   c                     t           j                            |                              | j                  r| j        st                      | _        | S d S r   )re   rf   rg   
startswithrk   rd   r7   r:   rR   s     r   file_tracerz DjangoTemplatePlugin.file_tracer   sN    7H%%001IJJ 	% 3 &1]]"Ktr   c                      t          |          S r   )FileReporterr   s     r   file_reporterz"DjangoTemplatePlugin.file_reporter   s    H%%%r   c              #     K   dd                     | j                  z   dz   }t          j        |          D ]N\  }}}|| j        k    r|D ]9}t          j        ||          r"t          j                             ||          V  :Od S )Nz^[^.#~!$@%^&*()+=,]+\.(|z)$)joinrc   re   walkr   researchrf   )r:   src_dirrxdirpathdirnames	filenamesrR   s          r   find_executable_filesz*DjangoTemplatePlugin.find_executable_files   s       (#((4?*C*CCeK.0gg.>.> 	: 	:*Wh	$...% : :9R** :',,w99999:		: 	:r   c                     dS )NTr   rz   s    r   has_dynamic_source_filenamez0DjangoTemplatePlugin.has_dynamic_source_filename   s    tr   renderrender_annotatedc                     |j         j        | j        vrd S 	 t	          |          }||                    d          rd S |S d S )Nr   dynamic_source_filenamelabel<)f_codeco_nameRENDER_METHODS
dump_framer@   r   )r:   rR   r?   s      r   r   z,DjangoTemplatePlugin.dynamic_source_filename   sY    <t':::4	?%e,,""3''  tOtr   c                    |j         j        | j        v sJ 	 |j        d         }t          |t          t          f          rdS t          |          }|dS t          rt          |d|            |\  }}t          |t                    rG|j                            d          d         }|                                r|t          |          z  }nrt           r-t          |t                     r|t          |j                  z  }n>t          |t$                    r)|j        p|j        }t+          |d                   d	         }t-          |          }|                     |          }	t1          |	|          }
t1          |	|d	z
            }|
dk     s|dk     rd\  }
}t          r%t          d
                    ||
|f                     |
|fS )Nr   line_number_ranger   r:   )r   : Tr   rK   zline_number_range({}) -> {})r   r   r   r   r;   r4   r   r   rE   SHOW_TRACINGprintr   s
splitlinesisspacelenr   contentr	   pluralsingularrG   r@   get_line_mapget_line_numberrs   )r:   r?   render_selfrC   s_starts_end
first_linelast_tokensrR   line_mapstartends               r   r   z&DjangoTemplatePlugin.line_number_range   s   |#t':::::	9 nV,kHh#788 	6$[116 	2[00h00111!k8,, 	;$11$77:J!!## +3z??* 
	;jlCC 
	; S,---EE%788 	; &,D0DK&{277:E%e,,$$X..'22ha00199aJE3 	/665#,     czr   c                 |    || j         vr't          |          }	 t          |          | j         |<   | j         |         S )aJ  The line map for `filename`.

        A line map is a list of character offsets, indicating where each line
        in the text begins.  For example, a line map like this::

            [13, 19, 30]

        means that line 2 starts at character 13, line 3 starts at 19, etc.
        Line 1 always starts at character 0.

        )rl   rV   ranger   r   make_line_map)r:   rR   template_sourceis       r   r   z!DjangoTemplatePlugin.get_line_map  sG     4?**28<<OD )6o(F(FDOH%x((r   N)r   r   r   rn   r{   rL   r   r   r   r   r   r   r   r   r   r   r   rX   rX      s        

 
 

 
 
T T T  & & &: : :   
  23N  * * *\) ) ) ) )r   rX   c                   *     e Zd Z fdZd Zd Z xZS )r   c                 X    t                                          |           d | _        d S r   )superrn   _source)r:   rR   	__class__s     r   rn   zFileReporter.__init__'  s(    """ r   c                     | j         N	 t          | j                  | _         n3# t          t          f$ r}t          d| j         d|           d }~ww xY w| j         S )NzCouldn't read r   )r   rV   rR   OSErrorUnicodeErrorr   )r:   excs     r   sourcezFileReporter.source-  st    <H3DMBB\* H H HFFFFFGGGH|s   # AAAc                    t                      }t          rt          d| j                    t	          |                                           }|                                }d}d}d}|D ]}t          r1t          dt          |j                  |j	        |j
        fz             |j        t          j        k    r|j
        dk    rd}^|ra|j        t          j        k    r|j
                            d          rd}n|j
                            d          rd}|r|r|s|j
        dk    rd}|j
                            d	          r|j
        d
v r|j
                            d          r|j
                            d          rd}|                    |j	                   n|j        t          j        k    r|                    |j	                   n|j        t          j        k    r|r|s|j	        }|j
                            d          }	t%          |	          }
|	d                                         r
|dz  }|
dz  }
|                    t+          |||
z                        t          rt          d|           |S )Nz-------------- Fz%10s %2d: %r
endcommentendblockblockTcommentr   )elseemptyelifextendsr   rK   z			Now source_lines is: )setSHOW_PARSINGr   rR   r   r   tokenizer   r   linenocontentsr
   r   r   addr   r   r   r   r   updater   )r:   source_lineslexertokensr   r   inblockrB   r   lines	num_liness              r   r   zFileReporter.lines5  s   uu 	53DM33444dkkmm$$!!  ?	F ?	FE "#E$455&    9?22>\11#G 9?22>,,Z88 !#GG^..w77 !"G !  7  >Y.."G>,,U33 
#^'888^..v66 # ^..y99 #"G  ....!Y]22  ....!Y^33 7  11$77JJ	8##%% #aKFNI##E&&2B$C$CDDD FDLDDEEEr   )r   r   r   rn   r   r   __classcell__)r   s   @r   r   r   &  s]              Q Q Q Q Q Q Qr   r   c              #   *   K   d}| D ]}||z  }|V  d S )Nr   r   )seqtotalnums      r   running_sumr     s8      E   r   c                 |    d |                      d          D             }t          t          |                    }|S )Nc                 ,    g | ]}t          |          S r   )r   )r]   lines     r   r_   z!make_line_map.<locals>.<listcomp>  s    @@@$CII@@@r   T)r   listr   )rU   line_lengthsr   s      r   r   r     s;    @@$//$*?*?@@@LK--..HOr   c                 H    t          | d          D ]\  }}||k    r|c S dS )z<Find a line number, given a line map and a character offset.rK   )r   r   )	enumerate)r   offsetr   line_offsets       r   r   r     sA    (;;;  MMM  2r    c           	         t          | j                  }|                    dd          }|                    dd          }d|v r|d= |rd|z  }t          d|z             t          d                    t
          j                            | j        j	                  | j
        t          |                               t          |           |rt          d|j                   |rt          d	|j                   t          d
           dS )z.Dump interesting information about this frame.r:   Ncontext__builtins__z ( %s ) z"-- frame --%s---------------------z{}:{}:{}zself:zcontext:z\--)dictr;   ra   r   rs   re   rf   basenamer   co_filenamef_linenotype__dict__)r?   r   localsr:   r   s        r   r   r     s   %.!!F::fd##DjjD))G>" #U"	
.
6777	*


122T


 
   
 
&MMM &gt}%%% ,j'*+++	&MMMMMr   )r   )/r#   os.pathre   r   coverage.exceptionsr   ImportErrorcoverage.misccoverage.plugincoverager)   django.templatedjango.template.baser   r   r   r   django.template.defaulttagsr   django.templatetags.i18nr	   r
   r   r   r   r   r   	Exceptionr"   r   r   r7   rN   RuntimeErrorr@   rE   rG   rV   pluginCoveragePlugin
FileTracerrX   r   r   r   r   r   r   r   r   <module>r     s   + *  				',,,,,,, ' ' '&&&&&&&&'          D D D D D D D D D D D D 4 4 4 4 4 4 7 7 7 7 7 7)......% % % %  ) ) )                  
) ) ) ) ))$	 	 	 	 	I 	 	 	 ) ) )X 
>F
,M
N
NN
        *S) S) S) S) S)O"OS) S) S)l` ` ` ` `8?/ ` ` `F           s    !!		A !A76A7