本文整理汇总了Python中http.server.SimpleHTTPRequestHandler.do_GET方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleHTTPRequestHandler.do_GET方法的具体用法?Python SimpleHTTPRequestHandler.do_GET怎么用?Python SimpleHTTPRequestHandler.do_GET使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http.server.SimpleHTTPRequestHandler
的用法示例。
在下文中一共展示了SimpleHTTPRequestHandler.do_GET方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(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_GET(self)
return
示例2: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
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)
示例3: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self):
params = urlparse(self.path)
if params.path in self.handlers:
self.handlers[params.path](self)
else:
SimpleHTTPRequestHandler.do_GET(self)
示例4: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
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)
示例5: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
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)
示例6: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
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)
示例7: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
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)
示例8: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
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)
示例9: do_POST
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_POST(self):
"""Handle POST request. If web server is enabled,
SimpleHTTPRequestHandler.do_GET will be called."""
if self.only_upgrade:
self.send_error(405, "Method Not Allowed")
else:
# SimpleHTTPRequestHandler has no do_POST function, but we don't need
# anything special, just to respond in the same way as the GET
SimpleHTTPRequestHandler.do_GET(self)
示例10: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self, method='GET'):
#copy all data into a place we can see later.
self.wfile = FileWrapper(self.wfile)
#give the actual work of handling the request to SimpleHTTPRequestHandler
SimpleHTTPRequestHandler.do_GET(self)
#by this time, the shim file object we created previously is
#full of the response data and is ready to display.
print('')
print(self._heading('HTTP Response'))
print(self.wfile)
示例11: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(s):
print(s.path)
if s.path.lower().endswith(".stl"):
filename = "." + s.path
if os.path.exists(filename):
stream_mesh_file(s, filename)
return
# if we get here, we didn't get an stl file to stream
# call the parent's get
C_simple_handler.do_GET(s)
示例12: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET( self ):
urlParams = urlparse(self.path)
if os.access( '.' + os.sep + urlParams.path, os.R_OK ):
SimpleHTTPRequestHandler.do_GET(self);
else:
self.send_response(200)
self.send_header( 'Content-type', 'text/html' )
self.end_headers()
with open('index.html', 'r') as f:
html = f.read()
self.wfile.write( html.encode() )
示例13: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self):
pr = urllib.parse.urlparse(self.path)
if pr.path == '/v':
params = urllib.parse.parse_qs(pr.query)
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(self.getPost(pr.path, params['p'][0]).encode())
self.wfile.flush()
else:
SimpleHTTPRequestHandler.do_GET(self)
示例14: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self):
with open('index.html') as index_file_handle:
url_params = urlparse.urlparse(self.path)
if os.access('.{}{}'.format(
os.sep, url_params.path), os.R_OK
):
SimpleHTTPRequestHandler.do_GET(self)
else:
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(index_file_handle.read().encode('utf8'))
示例15: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self):
if self.path not in ('/', '/termlib.js'):
self.send_response(404)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(b'404')
return
os.chdir(os.path.dirname(__file__))
if PY3:
super().do_GET()
else:
SimpleHTTPRequestHandler.do_GET(self)
os.chdir(cwd)