Generator to pull lines from a text-mode file, skipping the encoding cookie if it is found in the first two lines.
(filelike)
| 40 | return text.read() |
| 41 | |
| 42 | def 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 | |
| 60 | def read_py_file(filename, skip_encoding_cookie=True): |
| 61 | """Read a Python file, using the encoding declared inside the file. |
no outgoing calls
no test coverage detected