def list_directory(self, path):
"""Helper to produce a directory listing (absent index.html).
Return value is either a file object, or None (indicating an
error). In either case, the headers are sent, making the
interface the same as for send_head().
"""
try:
list = os.listdir(path)
except OSError:
self.send_error(
HTTPStatus.NOT_FOUND,
"No permission to list directory")
return None
list.sort(key=lambda a: a.lower())
r = []
try:
displaypath = urllib.parse.unquote(self.path,
errors='surrogatepass')
except UnicodeDecodeError:
displaypath = urllib.parse.unquote(path)
displaypath = html.escape(displaypath)
enc = "gb18030"; # sys.g
Windows 10上修改Python 3.5的server.py,使得其http server脚本可以正确处理中文目录文件名
最新推荐文章于 2021-06-22 10:48:18 发布
该博客主要介绍了如何在Windows 10上修改Python 3.5的server.py脚本,以正确处理包含中文的目录和文件名。在默认情况下,脚本可能会因为Unicode编码问题导致错误,特别是对于一些特殊的CJK字符。通过调整编码设置,可以确保http server能够正常工作。
摘要由CSDN通过智能技术生成