MCPcopy Create free account
hub / github.com/ipython/ipython / strip_encoding_cookie

Function strip_encoding_cookie

IPython/utils/openpy.py:42–58  ·  view source on GitHub ↗

Generator to pull lines from a text-mode file, skipping the encoding cookie if it is found in the first two lines.

(filelike)

Source from the content-addressed store, hash-verified

40 return text.read()
41
42def strip_encoding_cookie(filelike):
43 """Generator to pull lines from a text-mode file, skipping the encoding
44 cookie if it is found in the first two lines.
45 """
46 it = iter(filelike)
47 try:
48 first = next(it)
49 if not cookie_comment_re.match(first):
50 yield first
51 second = next(it)
52 if not cookie_comment_re.match(second):
53 yield second
54 except StopIteration:
55 return
56
57 for line in it:
58 yield line
59
60def read_py_file(filename, skip_encoding_cookie=True):
61 """Read a Python file, using the encoding declared inside the file.

Callers 2

source_to_unicodeFunction · 0.85
read_py_fileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected