网页服务与文件查看器技术解析
网页服务相关内容
在网页服务方面,我们首先来看测试部分。以下是一个用于测试现有路径的函数:
def test_existing_path(fs):
content_str = "actual"
content_bytes = bytes(content_str , "utf-8")
fs.create_file("/actual.txt", contents=content_str)
handler = MockHandler("/actual.txt")
handler.do_GET()
assert handler.status == int(HTTPStatus.OK)
assert handler.headers["Content-Type"] == \
["text/html; charset=utf-8"]
assert handler.headers["Content-Length"] == \
[str(len(content_bytes))]
assert handler.wfile.getvalue() == content_bytes
这个函数创建了一个文件,模拟了一个 GET 请求,并对响应的状态码、内容类型、内容长度和响应内容进行了断言检查。
可运行服务器的主体部分结合了两个类来创建所需的服务:
if __name__ == '__main__