本文整理汇总了Python中http.server.SimpleHTTPRequestHandler类的典型用法代码示例。如果您正苦于以下问题:Python SimpleHTTPRequestHandler类的具体用法?Python SimpleHTTPRequestHandler怎么用?Python SimpleHTTPRequestHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleHTTPRequestHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, request, client_address, server):
self._logger = get_ws_logger(self)
self.origin = server.origin
self.port = server.port
self.permissive = server.permissive
SimpleHTTPRequestHandler.__init__(self, request,
client_address, server)
示例2: do_POST
def do_POST(self):
params = urlparse(self.path)
if params.path in self.handlers:
self.handlers[params.path](self)
else:
SimpleHTTPRequestHandler.do_POST(self)
示例3: end_headers
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Headers', 'x-request-timestamp, x-signature, electricitymap-token')
self.send_header('Cache-Control', 'no-cache, no-store, must-revalidate')
self.send_header('Pragma', 'no-cache')
self.send_header('Expires', '0')
SimpleHTTPRequestHandler.end_headers(self)
示例4: do_HEAD
def do_HEAD(self):
"""Serve a HEAD request."""
content = self._regenerate(self.path)
if content:
self._send_regenerated_head(content)
else:
SimpleHTTPRequestHandler.do_HEAD(self)
示例5: do_GET
def do_GET(self):
if self.path == "/shutdown/":
self.wfile.write("HTTP/1.1 200 OK\n\nShutting down...".encode())
self.send_response(200)
subprocess.Popen(["shutdown", "-h", "now"]).wait()
else:
SimpleHTTPRequestHandler.do_GET(self)
示例6: __init__
def __init__(self, req, addr, only_upgrade=False, file_only=False,
no_parent=False):
self.only_upgrade = only_upgrade # only allow upgrades
self.webroot = os.path.realpath(".")
self.file_only = file_only
self.no_parent = no_parent
SimpleHTTPRequestHandler.__init__(self, req, addr, object())
示例7: do_HEAD
def do_HEAD(self):
parsed_path = urllib.parse.urlparse(self.path)
if parsed_path.path.startswith("/echo"):
message = '\n'.join(
[
'CLIENT VALUES:',
'client_address=%s (%s)' % (self.client_address, self.address_string()),
'command=%s' % self.command,
'path=%s' % self.path,
'real path=%s' % parsed_path.path,
'query=%s' % parsed_path.query,
'request_version=%s' % self.request_version,
'',
'HEADERS:',
'%s' % self.headers,
]
)
self.send_response(200)
self.end_headers()
self.wfile.write(message.encode('utf-8'))
elif parsed_path.path.startswith("/redirect"):
self.send_response(301)
self.send_header('Location', "/echo")
self.end_headers()
else:
SimpleHTTPRequestHandler.do_HEAD(self)
return
示例8: log_message
def log_message(self, format, *args):
if DEBUG:
try:
SimpleHTTPRequestHandler.log_message(self, format, *args)
except IOError:
pass
else:
return
示例9: do_GET
def do_GET(self):
"""Serve a GET request."""
content = self._regenerate(self.path)
if content:
self._send_regenerated_head(content)
self.wfile.write(content)
else:
SimpleHTTPRequestHandler.do_GET(self)
示例10: do_GET
def do_GET(self):
""" Handle http requests to serve html/image files only """
print( self.path, self.translate_path(self.path))
permitted_extensions = ['.html','.png','.svg','.jpg', '.js']
if not os.path.splitext(self.path)[1] in permitted_extensions:
self.send_error(404, 'File Not Found/Allowed')
else:
SimpleHTTPRequestHandler.do_GET(self)
示例11: do_GET
def do_GET(self,*args,**kwds):
tmp = self.path.split('/')
# redirect?
if (len(tmp) == 3) and (tmp[0] == tmp[2]) and tmp[0] == '':
self.send_response(301)
self.send_header('Location', self.path + 'html/')
else:
SimpleHTTPRequestHandler.do_GET(self,*args,**kwds)
示例12: do_GET
def do_GET(self):
"""Handle GET request. Calls handle_websocket(). If unsuccessful,
and web server is enabled, SimpleHTTPRequestHandler.do_GET will be called."""
if not self.handle_websocket():
if self.only_upgrade:
self.send_error(405, "Method Not Allowed")
else:
SimpleHTTPRequestHandler.do_GET(self)
示例13: do_GET
def do_GET(self):
"""Serve a GET request."""
if not self.allow_path():
self.send_error(403)
elif self.is_brat():
self.run_brat_direct()
else:
SimpleHTTPRequestHandler.do_GET(self)
示例14: do_GET
def do_GET(self):
if self.path == '/+CSCOE+/logon.html':
self.redirect('/+CSCOE+/logon.html?fcadbadd=1')
return
elif self.path.startswith('/+CSCOE+/logon.html?') and 'reason=1' in self.path:
self.wfile.write(self.send_file('logon_failure').getvalue())
return
SimpleHTTPRequestHandler.do_GET(self)
示例15: handle
def handle(self):
# When using run_once, we have a single process, so
# we cannot loop in BaseHTTPRequestHandler.handle; we
# must return and handle new connections
if self.run_once:
self.handle_one_request()
else:
SimpleHTTPRequestHandler.handle(self)