Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/IPython/utils/__pycache__/openpy.cpython-39.pyc
Ðазад
a o�hY � @ s� d Z ddlZddlmZmZ ddlmZ ddlZddlmZm Z e� dej�Ze� dej�Z dd d�Zdd � Zddd�Zddd�ZdS )z� Tools to open .py files as Unicode, using the encoding specified within the file, as per PEP 263. Much of the code is taken from the tokenize module in Python 3.2. � N)� TextIOWrapper�BytesIO)�Path)�open�detect_encodingzcoding[:=]\s*([-\w.]+)z^\s*#.*coding[:=]\s*([-\w.]+)�replaceTc C s� t | t�r| S t | t�r"t| �}n| }zt|j�\}}W n tyN d}Y n0 |�d� t|||dd��L}d|_ |r�d� t|��W d � S |�� W d � S W d � n1 s�0 Y dS )a# Converts a bytes string with python source code to unicode. Unicode strings are passed through unchanged. Byte strings are checked for the python source file encoding cookie to determine encoding. txt can be either a bytes buffer or a string containing the source code. �asciir T)�errors�line_buffering�r� N) � isinstance�str�bytesr r �readline�SyntaxError�seekr �mode�join�strip_encoding_cookie�read)�txtr �skip_encoding_cookie�buffer�encoding�_�text� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/IPython/utils/openpy.py�source_to_unicode s r c c sf t | �}z4t|�}t�|�s"|V t|�}t�|�s:|V W n tyP Y dS 0 |D ] }|V qVdS )z{Generator to pull lines from a text-mode file, skipping the encoding cookie if it is found in the first two lines. N)�iter�next�cookie_comment_re�match� StopIteration)Zfilelike�it�first�second�liner r r r + s r c C sj t | �}t|��F}|r2d�t|��W d � S |�� W d � S W d � n1 s\0 Y dS )a� Read a Python file, using the encoding declared inside the file. Parameters ---------- filename : str The path to the file to read. skip_encoding_cookie : bool If True (the default), and the encoding declaration is found in the first two lines, that line will be excluded from the output. Returns ------- A unicode string containing the contents of the file. r N)r r r r r )�filenamer �filepath�fr r r �read_py_file= s r, c C s. ddl m} || �}t�|�� �}t|||�S )aJ Read a Python file from a URL, using the encoding declared inside the file. Parameters ---------- url : str The URL from which to fetch the file. errors : str How to handle decoding errors in the file. Options are the same as for bytes.decode(), but here 'replace' is the default. skip_encoding_cookie : bool If True (the default), and the encoding declaration is found in the first two lines, that line will be excluded from the output. Returns ------- A unicode string containing the contents of the file. r )�urlopen)�urllib.requestr- �ior r r )�urlr r r- �responser r r r �read_py_urlS s r2 )r T)T)r T)�__doc__r/ r r �pathlibr �re�tokenizer r �compile�UNICODE� cookie_rer"