Your IP : 216.73.216.213
B
E�W� � @ s� d Z ddlZddlZddlZddlmZmZ ddlm Z m
Z
mZmZm
Z
mZ ddlmZ ddlmZmZ ddlmZ ee�Ze dd �d
d� �Ze dd �d
d� �Ze dd �dd� �ZG dd� de�ZdS )z'Python source expertise for coverage.py� N)�env�files)�contract�CoverageException� expensive�NoSource�
join_regex�isolate_module)�PythonParser)�source_token_lines�source_encoding)�FileReporter�bytes)�returnsc C s. t | d��}|�� �dd��dd�S Q R X dS )zFRead the Python source text from `filename`.
Returns bytes.
�rbs
�
�
N)�open�read�replace)�filename�f� r �B/opt/alt/python37/lib64/python3.7/site-packages/coverage/python.py�read_python_source s r �unicodec C s� t j�| �\}}|dkr(tjr(ddg}n|g}xV|D ]4}|| }t j�|�rVt|�}P t|�}|dk r4P q4W d| f }|d7 }t|��|� dd�}|�
t|�d�}|r�|d d
kr�|d
7 }|S )z#Return the source code, as unicode.z.pyz.pywNzNo source for code: '%s'.
z*Aborting report output, consider using -i.� � r ����
)�os�path�splitextr ZWINDOWS�existsr �
get_zip_bytesr r �decoder )r �base�extZextsZtry_filename�source�exc_msgr r r �get_python_source s(
r* z
bytes|Nonec C s� dt j dt j g}x�|D ]|}|| kr| �|�}yt�|d |dd� �}W n tjk
rf wY nX y|�|d �}W n tk
r� wY nX |S qW dS )z�Get 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.
z.zipz.eggr Nr � )r �sep�split� zipimport�zipimporter�ZipImportError�get_data�IOError)r �markers�marker�partsZzi�datar r r r$ E s
r$ c s� e Zd ZdZd!� fdd� Zedd�dd� �Zed d
� �Zdd� Z d
d� Z
dd� Zdd� Ze
dd� �Ze
dd� �Ze
dd� �Zd"dd�Zedd�dd� �Zdd� Zdd � Z� ZS )#�PythonFileReporterz!Report support for a Python file.Nc s� || _ t|d�r|j}n t|tj�r4td�|���n|}t� |�}|�
d�rZ|d d� }n|�
d�rt|d d� d }tt| ��
t�|�� t|d�r�|j}|�d tj�d }t� |�}n
t�|�}|| _d | _d | _d | _d | _d S )
N�__file__zModule {0} has no file)z.pycz.pyor z $py.classi����z.py�__name__�.)�coverage�hasattrr8 �
isinstance�types�
ModuleTyper �formatr Zunicode_filename�endswith�superr7 �__init__Zcanonical_filenamer9 r r r, �relative_filename�relname�_source�_parserZ_statementsZ _excluded)�selfZmorfr; r �name)� __class__r r rC a s,
zPythonFileReporter.__init__r )r c C s | j S )N)rE )rH r r r rD � s z$PythonFileReporter.relative_filenamec C s2 | j dkr,t| j| j�d�d�| _ | j �� | j S )z&Lazily create a :class:`PythonParser`.N�exclude)r rK )rG r
r r; Z_exclude_regexZparse_source)rH r r r �parser� s
zPythonFileReporter.parserc C s | j jS )z2Return the line numbers of statements in the file.)rL Z
statements)rH r r r �lines� s zPythonFileReporter.linesc C s | j jS )z2Return the line numbers of statements in the file.)rL Zexcluded)rH r r r �excluded_lines� s z!PythonFileReporter.excluded_linesc C s | j �|�S )N)rL �translate_lines)rH rM r r r rO � s z"PythonFileReporter.translate_linesc C s | j �|�S )N)rL �translate_arcs)rH �arcsr r r rP � s z!PythonFileReporter.translate_arcsc C s&