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

Class FileHandler

Lib/urllib/request.py:1452–1483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

_is_local_authorityFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected