当前位置: 首页>>代码示例>>Python>>正文


Python HTTPServer.serve_forever方法代码示例

本文整理汇总了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()
开发者ID:,项目名称:,代码行数:11,代码来源:

示例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()
开发者ID:scriptharness,项目名称:python-scriptharness,代码行数:11,代码来源:cgi_server.py

示例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 )
开发者ID:esitarski,项目名称:CrossMgr,代码行数:11,代码来源:HelpSearch.py

示例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]
开发者ID:balasubram,项目名称:dcos-spark,代码行数:13,代码来源:spark_submit.py

示例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()
开发者ID:gaoxuesong,项目名称:python-stanford-corenlp,代码行数:16,代码来源:annotator.py

示例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()
开发者ID:bartoszhernas,项目名称:silk,代码行数:50,代码来源:util.py

示例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
开发者ID:goulu,项目名称:pdfminer,代码行数:26,代码来源:runapp.py

示例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()
开发者ID:Kloudless,项目名称:kloudless-python,代码行数:32,代码来源:demo_server.py

示例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)
开发者ID:hozn,项目名称:stravalib,代码行数:5,代码来源:auth_responder.py

示例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()
开发者ID:WurstWorks,项目名称:datalad,代码行数:7,代码来源:utils.py

示例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"])
开发者ID:matrix-org,项目名称:sytest,代码行数:33,代码来源:pydron.py


注:本文中的six.moves.BaseHTTPServer.HTTPServer.serve_forever方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。