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 'rep
(url: str, errors: str = 'replace', skip_encoding_cookie: bool = True)
| 82 | return f.read() |
| 83 | |
| 84 | def read_py_url(url: str, errors: str = 'replace', skip_encoding_cookie: bool = True) -> str: |
| 85 | """Read a Python file from a URL, using the encoding declared inside the file. |
| 86 | |
| 87 | Parameters |
| 88 | ---------- |
| 89 | url : str |
| 90 | The URL from which to fetch the file. |
| 91 | errors : str |
| 92 | How to handle decoding errors in the file. Options are the same as for |
| 93 | bytes.decode(), but here 'replace' is the default. |
| 94 | skip_encoding_cookie : bool |
| 95 | If True (the default), and the encoding declaration is found in the first |
| 96 | two lines, that line will be excluded from the output. |
| 97 | |
| 98 | Returns |
| 99 | ------- |
| 100 | A unicode string containing the contents of the file. |
| 101 | """ |
| 102 | # Deferred import for faster start |
| 103 | from urllib.request import urlopen |
| 104 | response = urlopen(url) |
| 105 | buffer = io.BytesIO(response.read()) |
| 106 | return source_to_unicode(buffer, errors, skip_encoding_cookie) |
nothing calls this directly
no test coverage detected
searching dependent graphs…