
    /~h!                    2   d Z ddlmZ 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mZ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mZ ddlm Z  ddl!m"Z"m#Z#m$Z$m%Z% erddlm&Z&  ee      ZddZ'ddZ(ddZ)ddZ*ddZ+ G d de      Z,y)z'Python source expertise for coverage.py    )annotationsN)TYPE_CHECKING)Iterable)env)CoverageExceptionNoSource)canonical_filenamerelative_filenamezip_location)isolate_module
join_regex)PythonParser)source_token_linessource_encoding)
CodeRegionFileReporter)code_regions)TArcTLineNoTMorfTSourceTokenLines)Coveragec                    t        | d      5 }|j                         }ddd       j                  dd      j                  dd      S # 1 sw Y   +xY w)zFRead the Python source text from `filename`.

    Returns bytes.

    rbNs   
   
   )openreadreplace)filenamefsources      X/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/coverage/python.pyread_python_sourcer$      sP     
h	  >>'5)11%?? s   AAc                   t         j                  j                  |       \  }}|dk(  rt        j                  rddg}n|g}|D ]B  }||z   }t         j                  j                  |      rt        |      } n t        |      }|B n t        d|  d      |j                  dd      }|j                  t        |      d      }|r|d   d	k7  r|d	z  }|S )
z#Return the source code, as unicode..pyz.pywzNo source for code: 'z'.       r   
)ospathsplitextr   WINDOWSexistsr$   get_zip_bytesr   r   decoder   )r    baseextextstry_filenamesource_bytesr"   s          r#   get_python_sourcer7   +   s      *ID#
e|vu  =cz77>>,'-l;L %\2#= .xj;<<  ''t4L  !>	JF &*$$M    c                    t        |       }|/|\  }}	 t        j                  |      }	 |j	                  |      }|S y# t        j                  $ r Y yw xY w# t
        $ r Y yw xY w)zGet data from `filename` if it is a zip file path.

    Returns the bytestring data read from the zip file, or None if no zip file
    could be found or `filename` isn't in it.  The data returned will be
    an empty string if the file is empty.

    N)r   	zipimportzipimporterZipImportErrorget_dataOSError)r    zipfile_innerzipfileinnerzidatas         r#   r0   r0   N   s|     !*M &	&&w/B	;;u%D  '' 		  		s    > A AA	A#"A#c                
   | j                  d      r| S | j                  d      r^| dd }t        j                  j                  |      r|S t        j
                  r&|dz   }t        j                  j                  |      r|S |S | S )zReturn the source filename for `filename`.

    Given a file name being traced, return the best guess as to the source
    file to attribute it to.

    r&   )z.pycz.pyoNr)   w)endswithr+   r,   r/   r   r.   )r    py_filenamepyw_filenames      r#   source_for_filerI   e   s{     			+	,sm77>>+&;;&,Lww~~l+## Or8   c                    t        | d      r| j                  r| j                  }n+t        | t        j                        rt        d|  d      | }t        |      }|S )z6Get the source filename for the module-or-file `morf`.__file__zModule z has no file)hasattrrK   
isinstancetypes
ModuleTyper   rI   )morfr    s     r#   source_for_morfrQ      sU    tZ T]]==	D%**	+  '$| <==x(HOr8   c                       e Zd ZdZdd fdZddZddZedd       ZddZ	ddZ
ddZdd	Zdd
ZddZddZ	 d	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZddZd dZd!dZd"dZ xZS )#PythonFileReporterz!Report support for a Python file.c                   || _         t        |      }|}d}| j                   "| j                   j                  j                  rd}|rt	        |      }t
        |   |       t        |d      rt|j                  j                  dt        j                        }t        j                  j                  |      j                  d      r|t        j                  dz   z  }|dz  }nt        |      }|| _        d | _        d | _        d | _        y )NTF__name__.z	__init__.__init__r&   )coveragerQ   configrelative_filesr	   superrW   rL   rU   r   r+   sepr,   basename
startswithr
   relname_source_parser	_excluded)selfrP   rX   r    fnamecanonicalizename	__class__s          r#   rW   zPythonFileReporter.__init__   s     "4(==$}}##22$&x0E4$==((bff5Dww)44[A++EMD$X.D#',0r8   c                "    d| j                   dS )Nz<PythonFileReporter >)r    rc   s    r#   __repr__zPythonFileReporter.__repr__   s    %dmm%6a88r8   c                    | j                   S N)r_   rj   s    r#   r
   z$PythonFileReporter.relative_filename   s    ||r8   c                    | j                   J | j                  Ot        | j                  | j                   j	                  d            | _        | j                  j                          | j                  S )z&Lazily create a :class:`PythonParser`.exclude)r    ro   )rX   ra   r   r    _exclude_regexparse_sourcerj   s    r#   parserzPythonFileReporter.parser   s_     }}(((<<'44Y?DL LL%%'||r8   c                .    | j                   j                  S z2Return the line numbers of statements in the file.)rr   
statementsrj   s    r#   lineszPythonFileReporter.lines   s    {{%%%r8   c                .    | j                   j                  S rt   )rr   excludedrj   s    r#   excluded_linesz!PythonFileReporter.excluded_lines   s    {{###r8   c                8    | j                   j                  |      S rm   )rr   translate_lines)rc   rv   s     r#   r{   z"PythonFileReporter.translate_lines   s    {{**511r8   c                8    | j                   j                  |      S rm   )rr   translate_arcs)rc   arcss     r#   r}   z!PythonFileReporter.translate_arcs   s    {{))$//r8   c                    | j                   J | j                  j                  t        | j                   j                  j
                  | j                   j                  j                  z               }|S rm   )rX   rr   lines_matchingr   rY   partial_listpartial_always_list)rc   	no_branchs     r#   no_branch_linesz"PythonFileReporter.no_branch_lines   sa    }}(((KK..$$11--&&::;
	 r8   c                6    | j                   j                         S rm   )rr   r~   rj   s    r#   r~   zPythonFileReporter.arcs   s    {{!!r8   c                6    | j                   j                         S rm   )rr   exit_countsrj   s    r#   r   zPythonFileReporter.exit_counts   s    {{&&((r8   c                :    | j                   j                  ||      S rm   )rr   missing_arc_description)rc   startendexecuted_arcss       r#   r   z*PythonFileReporter.missing_arc_description   s     {{225#>>r8   c                :    | j                   j                  ||      S rm   )rr   arc_description)rc   r   r   s      r#   r   z"PythonFileReporter.arc_description   s    
 {{**5#66r8   c                f    | j                   t        | j                        | _         | j                   S rm   )r`   r7   r    rj   s    r#   r"   zPythonFileReporter.source   s&    <<,T]];DL||r8   c                    t         j                  j                  | j                        \  }}|j	                  d      ry|syy)zDoes it seem like this file should contain Python?

        This is used to decide if a file reported as part of the execution of
        a program was really likely to have contained Python in the first
        place.

        r&   TF)r+   r,   r-   r    r^   )rc   _r3   s      r#   should_be_pythonz#PythonFileReporter.should_be_python   s:     !!$--03 >>% r8   c                4    t        | j                               S rm   )r   r"   rj   s    r#   r   z%PythonFileReporter.source_token_lines  s    !$++-00r8   c                4    t        | j                               S rm   )r   r"   rj   s    r#   r   zPythonFileReporter.code_regions
  s    DKKM**r8   c                
    ddgS )N)function	functions)classclasses rj   s    r#   code_region_kindsz$PythonFileReporter.code_region_kinds  s    % 
 	
r8   rm   )rP   r   rX   zCoverage | NonereturnNone)r   str)r   r   )r   set[TLineNo])rv   zIterable[TLineNo]r   r   )r~   zIterable[TArc]r   	set[TArc])r   r   )r   zdict[TLineNo, int])r   r   r   r   r   zIterable[TArc] | Noner   r   )r   r   r   r   r   r   )r   bool)r   r   )r   zIterable[CodeRegion])r   zIterable[tuple[str, str]])rU   
__module____qualname____doc__rW   rk   r
   propertyrr   rv   ry   r{   r}   r   r~   r   r   r   r"   r   r   r   r   __classcell__)rg   s   @r#   rS   rS      s    +69 	 	&$20") 04	?? ? -	?
 
?77 7 
	7
(1+
r8   rS   )r    r   r   bytes)r    r   r   r   )r    r   r   zbytes | None)rP   r   r   r   )-r   
__future__r   os.pathr+   rN   r:   typingr   collections.abcr   rX   r   coverage.exceptionsr   r   coverage.filesr	   r
   r   coverage.miscr   r   coverage.parserr   coverage.phystokensr   r   coverage.pluginr   r   coverage.regionsr   coverage.typesr   r   r   r   r   r$   r7   r0   rI   rQ   rS   r   r8   r#   <module>r      sv    . "      $  ; N N 4 ( C 4 ) B B!B	@ F.:@
 @
r8   