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

Function read_py_url

IPython/utils/openpy.py:81–103  ·  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 'repla

(url, errors='replace', skip_encoding_cookie=True)

Source from the content-addressed store, hash-verified

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