wL iD dZddlZddlmZmZddlmZddlZddlmZm Z ejdejZ ejdejZ d dZd Zd d Zd d Zy)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) TextIOWrapperBytesIO)Path)opendetect_encodingzcoding[:=]\s*([-\w.]+)z^\s*#.*coding[:=]\s*([-\w.]+)ct|tr|St|tr t|}n|} t |j \}}|jdt|||d5}d|_ |r#djt|cdddS|jcdddS#t $rd}YswxYw#1swYyxYw)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. asciirT)errorsline_bufferingrN) isinstancestrbytesrrreadline SyntaxErrorseekrmodejoinstrip_encoding_cookieread)txtr skip_encoding_cookiebufferencoding_texts Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/IPython/utils/openpy.pysource_to_unicoders#s #u%foo6 ! KKN vxt LPT 881$78 99;  s#B0*#CC0 B>=B>C c#Kt|} t|}tj|s|t|}tj|s||Ed{y#t$rYywxYw7w)z{Generator to pull lines from a text-mode file, skipping the encoding cookie if it is found in the first two lines. N)iternextcookie_comment_rematch StopIteration)filelikeitfirstseconds rrr+sp hBR &&u-Kb &&v.LMM s5 A3AA"A3A1A3" A.+A3-A..A3ct|}t|5}|r#djt|cdddS|j cdddS#1swYyxYw)aRead 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)rrrrr)filenamerfilepathfs r read_py_filer.<sUH~H h1 77034668 sAAAc~ddlm}||}tj|j }t |||S)aJRead 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.requestr0iorrr)urlr rr0responsers r read_py_urlr5Rs4&'s|H ZZ  (F VV-A BB)replaceT)T)__doc__r2rrpathlibrretokenizerrcompileUNICODE cookie_rer#rrr.r5r6rr@s_ % * BJJ0"** = BJJ?L4",Cr6