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

Class FileHandler

Lib/urllib/request.py:1454–1485  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1452 return [part.strip() for part in res]
1453
1454class FileHandler(BaseHandler):
1455 # names for the localhost
1456 names = None
1457 def get_names(self):
1458 if FileHandler.names is None:
1459 try:
1460 FileHandler.names = tuple(
1461 socket.gethostbyname_ex('localhost')[2] +
1462 socket.gethostbyname_ex(socket.gethostname())[2])
1463 except socket.gaierror:
1464 FileHandler.names = (socket.gethostbyname('localhost'),)
1465 return FileHandler.names
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
1487def _is_local_authority(authority, resolve):
1488 # Compare hostnames

Callers 1

_is_local_authorityFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…