MCPcopy Index your code
hub / github.com/python/cpython / open_local_file

Method open_local_file

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

Source from the content-addressed store, hash-verified

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

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