MCPcopy Index your code
hub / github.com/ipython/ipython / read_py_url

Function read_py_url

IPython/utils/openpy.py:84–106  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

82 return f.read()
83
84def 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)

Callers

nothing calls this directly

Calls 2

source_to_unicodeFunction · 0.85
readMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…