MCPcopy Index your code
hub / github.com/RustPython/RustPython / open_local_file

Method open_local_file

Lib/urllib/request.py:1466–1481  ·  view source on GitHub ↗
(self, req)

Source from the content-addressed store, hash-verified

1464
1465 # not entirely sure what the rules are here
1466 def open_local_file(self, req):
1467 import email.utils
1468 import mimetypes
1469 localfile = url2pathname(req.full_url, require_scheme=True, resolve_host=True)
1470 try:
1471 stats = os.stat(localfile)
1472 size = stats.st_size
1473 modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
1474 mtype = mimetypes.guess_file_type(localfile)[0]
1475 headers = email.message_from_string(
1476 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
1477 (mtype or 'text/plain', size, modified))
1478 origurl = pathname2url(localfile, add_scheme=True)
1479 return addinfourl(open(localfile, 'rb'), headers, origurl)
1480 except OSError as exp:
1481 raise URLError(exp, exp.filename)
1482
1483 file_open = open_local_file
1484

Callers

nothing calls this directly

Calls 7

addinfourlClass · 0.90
URLErrorClass · 0.90
guess_file_typeMethod · 0.80
url2pathnameFunction · 0.70
pathname2urlFunction · 0.70
openFunction · 0.50
statMethod · 0.45

Tested by

no test coverage detected