本文整理汇总了Python中six.moves.BaseHTTPServer.HTTPServer.serve_forever方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPServer.serve_forever方法的具体用法?Python HTTPServer.serve_forever怎么用?Python HTTPServer.serve_forever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.BaseHTTPServer.HTTPServer
的用法示例。
在下文中一共展示了HTTPServer.serve_forever方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import serve_forever [as 别名]
def main(ikey, skey, akey, host, port=8080):
server = HTTPServer(('', port), RequestHandler)
server.ikey = ikey
server.skey = skey
server.akey = akey
server.host = host
print("Visit the root URL with a 'user' argument, e.g.")
print("'http://localhost:%d/?user=myname'." % port)
server.serve_forever()
示例2: start_webserver
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import serve_forever [as 别名]
def start_webserver():
"""Start the webserver.
"""
path = os.path.dirname(__file__)
os.chdir(path)
server_address = ("127.0.0.1", 0)
httpd = HTTPServer(server_address, CGIHTTPRequestHandler)
print("http://127.0.0.1:%d" % httpd.server_port)
httpd.serve_forever()
示例3: HelpServer
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import serve_forever [as 别名]
def HelpServer():
global server
while 1:
try:
server = HTTPServer(('localhost', PORT_NUMBER), HelpHandler)
server.serve_forever( poll_interval = 2 )
except Exception as e:
server = None
time.sleep( 5 )
示例4: ProxyThread
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import serve_forever [as 别名]
class ProxyThread(threading.Thread):
def __init__(self, token):
self.proxy = HTTPServer(('localhost', 0), ProxyHandler)
self.proxy._dcos_auth_token = token
super(ProxyThread, self).__init__()
def run(self):
self.proxy.serve_forever()
def port(self):
return self.proxy.socket.getsockname()[1]
示例5: run
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import serve_forever [as 别名]
def run(self):
"""
Runs the server using Python's simple HTTPServer.
TODO: make this multithreaded.
"""
httpd = HTTPServer((self.host, self.port), self._Handler)
sa = httpd.socket.getsockname()
serve_message = "Serving HTTP on {host} port {port} (http://{host}:{port}/) ..."
print(serve_message.format(host=sa[0], port=sa[1]))
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nKeyboard interrupt received, exiting.")
httpd.shutdown()
示例6: run_echo_server
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import serve_forever [as 别名]
def run_echo_server():
class Handler(BaseHTTPRequestHandler):
def _do(self):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
parsed = urlparse(self.path)
query_parameters = parse_qs(parsed.query)
response = {
'path': parsed.path,
'headers': dict(self.headers)
}
if query_parameters:
response['query_params'] = query_parameters
try:
try: # py2
raw_content_len = self.headers.getheader('content-length')
except AttributeError: # py3
raw_content_len = self.headers.get('content-length')
content_len = int(raw_content_len)
except TypeError:
content_len = 0
if content_len:
body = self.rfile.read(content_len)
try: # py3
body = body.decode('UTF-8')
except AttributeError: # py2
pass
if body:
response['body'] = body
print(response)
encoded_json = json.dumps(response)
self.wfile.write(b(encoded_json))
return
do_GET = _do
do_POST = _do
do_PUT = _do
do_HEAD = _do
do_PATCH = _do
do_OPTIONS = _do
do_DELETE = _do
do_TRACE = _do
do_CONNECT = _do
server_address = ('', PORT)
httpd = HTTPServer(server_address, Handler)
httpd.serve_forever()
示例7: main
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import serve_forever [as 别名]
def main(argv):
import getopt, imp
def usage():
print ('usage: %s [-h host] [-p port] [-n name] module.class' % argv[0])
return 100
try:
(opts, args) = getopt.getopt(argv[1:], 'h:p:n:')
except getopt.GetoptError:
return usage()
host = ''
port = 8080
name = 'WebApp'
for (k, v) in opts:
if k == '-h': host = v
elif k == '-p': port = int(v)
elif k == '-n': name = v
if not args: return usage()
path = args.pop(0)
module = imp.load_source('app', path)
WebAppHandler.APP_CLASS = getattr(module, name)
print ('Listening %s:%d...' % (host,port))
httpd = HTTPServer((host,port), WebAppHandler)
httpd.serve_forever()
return
示例8: print
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import serve_forever [as 别名]
resp_data['primary_calendar_events'] = (
primary_calendar_events.data)
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(json.dumps(resp_data).encode('utf8'))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('app_id', type=str,
help='You can access app_id via https://developers.klo'
'udless.com/applications/*/details')
parser.add_argument('api_key', type=str,
help='You can access api_key via https://developers.klo'
'udless.com/applications/*/details')
parser.add_argument('--port', type=int, default=8020,
help='Port number to run the server, default to 8020')
args = parser.parse_args()
app_id = args.app_id
api_key = args.api_key
port = args.port
print('Listening on localhost:%s' % port)
httpd = HTTPServer(('', port), RequestHandler)
httpd.serve_forever()
示例9: serve_forever
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import serve_forever [as 别名]
def serve_forever(self, *args, **kwargs):
self.listening_event.set()
return HTTPServer.serve_forever(self, *args, **kwargs)
示例10: _multiproc_serve_path_via_http
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import serve_forever [as 别名]
def _multiproc_serve_path_via_http(hostname, path_to_serve_from, queue): # pragma: no cover
chpwd(path_to_serve_from)
httpd = HTTPServer((hostname, 0), SilentHTTPHandler)
queue.put(httpd.server_port)
httpd.serve_forever()
示例11: Exception
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import serve_forever [as 别名]
raise Exception("%s failed to start" % (appname, ))
# Nothing failed, let's say we've started and then signal we're up by
# serving the webserver.
_print("Synapse started!")
class WebHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write("OK")
return
PORT_NUMBER = int(args["--addr"].split(":")[1])
server = HTTPServer(('', PORT_NUMBER), WebHandler)
server.serve_forever()
except KeyboardInterrupt:
pass
except BaseException as e:
# Log a traceback for debug
import traceback
traceback.print_exc()
# If we get told to shut down, log it
_print("Told to quit because %s" % (repr(e)))
# Otherwise, something bad has happened.
sys.exit(1)
finally:
subprocess.run(["pkill", "-9", "-f", "synapse.app"])