代码拉取完成,页面将自动刷新
同步操作将从 现任明教教主-乾颐堂/qytang_Python 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/python
# from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
import argparse
import string
import os
import sys
import gzip
from io import StringIO
from io import BytesIO
from http.server import BaseHTTPRequestHandler,HTTPServer
DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 8080
HTML_CONTENT = """<html><body><h1>Compressed Hello World!</h1></body></html>"""
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text/html')
self.send_header('Content-Encoding', 'gzip')
zbuf = self.compress_buffer(HTML_CONTENT)
sys.stdout.write("Content-Encoding: gzip\r\n")
self.send_header('Content-Length', len(zbuf))
self.end_headers()
zbuf = self.compress_buffer(HTML_CONTENT)
sys.stdout.write("Content-Encoding: gzip\r\n")
sys.stdout.write("Content-Length: %d\r\n" % (len(zbuf)))
sys.stdout.write("\r\n")
self.wfile.write(zbuf)
return
def compress_buffer(self, buf):
zbuf = BytesIO()
zfile = gzip.GzipFile(mode = 'wb', fileobj = zbuf, compresslevel = 6)
zfile.write(buf.encode())
zfile.close()
return zbuf.getvalue()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description = 'Simple HTTP Server Example')
parser.add_argument('--port', action = 'store', dest = 'port', type = int, default = DEFAULT_PORT)
given_args = parser.parse_args()
port = given_args.port
server_address = (DEFAULT_HOST, port)
server = HTTPServer(server_address, RequestHandler)
server.serve_forever()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。