o
    v&i                     @  s   d Z ddlmZ ddlZddlZddlZddl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mZ ee	j Zdd
dZdddZdddZdddZdddZdS )z"Better tokenizing for coverage.py.    )annotationsN)Iterable)env)TLineNoTSourceTokenLinestoks
TokenInfosreturnc              	   c  s   d}d}d}| D ]|\}}\}}\}}	}
||krk|ri| drid}| dr)d}n#|tjkrA| dr>|d |r>d}nd}ntjjrL|tjkrLd}|rit|	d	d
 d }t
dd||f||d f|V  |
}|t
jt
jfvru|}t
||||f||	f|
V  |}q	dS )aB  Return all physical tokens, even line continuations.

    tokenize.generate_tokens() doesn't return a token for the backslash that
    continues lines.  This wrapper provides those tokens so that we can
    re-create a faithful representation of the original source.

    Returns the same values as generate_tokens()

    N z\
T\Fz \

   i    )endswithtokenSTRINGrstripr   
PYBEHAVIORfstring_syntaxFSTRING_MIDDLElensplittokenize	TokenInfoNEWLINENL)r   	last_linelast_lineno
last_ttextttypettextslinenoscolelinenoecolltextinject_backslashccol r*   Y/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/coverage/phystokens.py_phys_tokens   sD   




r,   sourcestrset[TLineNo]c                 C  sv   t  }tt| D ]-}t|tjr'||j |jD ]	}||j	j qqt
jdkr8t|tjr8||j q|S )zCHelper for finding lines with soft keywords, like match/case lines.)      )setastwalkparse
isinstanceMatchaddlinenocasespatternsysversion_info	TypeAlias)r-   soft_key_linesnodecaser*   r*   r+   find_soft_key_lines]   s   
rB   r   c                 c  s   t jt jt jtjh}g }d}| ddd} t| }t	| }t
|D ]\}}\}}	\}
}}
d}td|D ]}|dkrG|V  g }d}d}n|dkrNd}n||v rUd}nxtjjrn|t jkrn|d	d
dd}|	t| }|r|	|kr|dd|	|  f d}tj|d dd }|t jkrt|rd}n)t|rt|dkrd}nt|dkr|d d dkrd}nd}|r||v rd}|||f d}d}	q7|r|}q$|r|V  dS dS )a  Generate a series of lines, one for each line in `source`.

    Each line is a list of pairs, each pair is a token::

        [('key', 'def'), ('ws', ' '), ('nam', 'hello'), ('op', '('), ... ]

    Each pair has a token class, and the token text.

    If you concatenate all the token texts, and then join them with newlines,
    you should have your original `source` back, with two differences:
    trailing white space is not preserved, and a final line with no newline
    is indistinguishable from a final line with a newline.

    r      z
r   Tz(
)Fr   {z{{}z}}ws xxNr0   keyr   )r   INDENTDEDENTr   r   r   
expandtabsreplacegenerate_tokensrB   r,   rer   r   r   r   r   r   appendtok_namegetlowerNAMEkeyword	iskeywordissoftkeyword)r-   	ws_tokenslinecoltokgenr?   r!   r"   sliner$   _r&   
mark_startpartmark_end	tok_classis_start_of_liner*   r*   r+   source_token_linesl   s\   



rc   textc                 C  s   t | j}t|S )zA helper around `tokenize.generate_tokens`.

    Originally this was used to cache the results, but it didn't seem to make
    reporting go faster, and caused issues with using too much memory.

    )ioStringIOreadliner   rN   )rd   rg   r*   r*   r+   rN      s   
rN   bytesc                 C  s   t | dj}t|d S )zDetermine the encoding for `source`, according to PEP 263.

    `source` is a byte string: the text of the program.

    Returns a string, the name of the encoding.

    Tr   )iter
splitlines__next__r   detect_encoding)r-   rg   r*   r*   r+   source_encoding   s   rm   )r   r   r	   r   )r-   r.   r	   r/   )r-   r.   r	   r   )rd   r.   r	   r   )r-   rh   r	   r.   )__doc__
__future__r   r3   re   rU   rO   r<   r   r   collections.abcr   coverager   coverage.typesr   r   r   r   r,   rB   rc   rN   rm   r*   r*   r*   r+   <module>   s$   


F

E