| 1452 | return [part.strip() for part in res] |
| 1453 | |
| 1454 | class 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 | |
| 1487 | def _is_local_authority(authority, resolve): |
| 1488 | # Compare hostnames |
no outgoing calls
no test coverage detected
searching dependent graphs…