當前位置: 首頁>>代碼示例>>Python>>正文


Python BaseHTTPServer.HTTPServer類代碼示例

本文整理匯總了Python中six.moves.BaseHTTPServer.HTTPServer的典型用法代碼示例。如果您正苦於以下問題:Python HTTPServer類的具體用法?Python HTTPServer怎麽用?Python HTTPServer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了HTTPServer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

    def __init__(self, boat, behaviour_manager,
                 server_address, RequestHandlerClass, bind_and_activate=True):

        HTTPServer.__init__(self, server_address, RequestHandlerClass,
                            bind_and_activate)
        log.info('boatd api listening on %s:%s', *server_address)

        self.boat = boat
        self.behaviour_manager = behaviour_manager
        self.running = True

        # set API endpoints for GETs
        self.handles = {
            '/': self.boatd_info,
            '/boat': self.boat_attr,
            '/wind': self.wind,
            '/active': self.boat_active,
            '/behaviours': self.behaviours,
        }

        # set API endpoints for POSTs
        self.post_handles = {
            '/': self.boatd_post,
            '/behaviours': self.behaviours_post,
        }
開發者ID:zuzak,項目名稱:boatd,代碼行數:25,代碼來源:api.py

示例2: __init__

 def __init__(self, server_address, RequestHandlerClass,
              ssl_context=None, request_queue_size=None):
     # This overrides the implementation of __init__ in python's
     # SocketServer.TCPServer (which BaseHTTPServer.HTTPServer
     # does not override, thankfully).
     HTTPServer.__init__(self, server_address, RequestHandlerClass)
     self.socket = socket.socket(self.address_family,
                                 self.socket_type)
     self.ssl_context = ssl_context
     if ssl_context:
         class TSafeConnection(tsafe.Connection):
             def settimeout(self, *args):
                 self._lock.acquire()
                 try:
                     return self._ssl_conn.settimeout(*args)
                 finally:
                     self._lock.release()
             def gettimeout(self):
                 self._lock.acquire()
                 try:
                     return self._ssl_conn.gettimeout()
                 finally:
                     self._lock.release()
         self.socket = TSafeConnection(ssl_context, self.socket)
     self.server_bind()
     if request_queue_size:
         self.socket.listen(request_queue_size)
     self.server_activate()
開發者ID:crystallovemama,項目名稱:hue,代碼行數:28,代碼來源:httpserver.py

示例3: HTTPLogServer

class HTTPLogServer(threading.Thread):
    class RequestHandler(BaseHTTPRequestHandler):
        INDENT = 4

        def do_GET(self):
            if self.path == "/summary":
                self.send_response(200)
                self.end_headers()
                with self.server.state_lock:
                    status = {
                        "complete": self.server.state["complete"],
                        "running" : self.server.state["running"],
                        "total"   : self.server.state["total"],
                        "results" : self.server.state["summary"],
                    }
                self.wfile.write(json.dumps(status, indent=self.INDENT))
            else:
                self.send_response(404)
                self.end_headers()

    def __init__(self, state, state_lock):
        super(HTTPLogServer, self).__init__()
        port = int(PIGLIT_CONFIG.safe_get("http", "port", fallback=8080))
        self._httpd = HTTPServer(("", port), HTTPLogServer.RequestHandler)
        self._httpd.state = state
        self._httpd.state_lock = state_lock

    def run(self):
        while True:
            with self._httpd.state_lock:
                # stop handling requests after the request for the final results
                if self._httpd.state["complete"] == self._httpd.state["total"]:
                    break;
            self._httpd.handle_request()
開發者ID:chadversary,項目名稱:piglit,代碼行數:34,代碼來源:log.py

示例4: __init__

 def __init__(self, addr, handler, root, userpwd):
     HTTPServer.__init__(self, addr, handler)
     self.root = root
     self.userpwd = userpwd      # WebDAV Auth user:passwd 
     if len(userpwd)>0:
         self.auth_enable = True
     else:
         self.auth_enable = False
開發者ID:prince-0203,項目名稱:TinyWebDav,代碼行數:8,代碼來源:WebDAV.py

示例5: __init__

 def __init__(self, patroni, config):
     self.connection_string = 'http://{}/patroni'.format(config.get('connect_address', None) or config['listen'])
     host, port = config['listen'].split(':')
     HTTPServer.__init__(self, (host, int(port)), RestApiHandler)
     Thread.__init__(self, target=self.serve_forever)
     self._set_fd_cloexec(self.socket)
     self.patroni = patroni
     self.daemon = True
開發者ID:radek-senfeld,項目名稱:patroni,代碼行數:8,代碼來源:api.py

示例6: start_webserver

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,代碼行數:9,代碼來源:cgi_server.py

示例7: __init__

 def __init__(self, server_address, handler, impl, meta):
     '''
     :param server_address: address of the server
     :param handler: handler for requests
     :param impl: reference to the implementation object
     '''
     HTTPServer.__init__(self, server_address, handler)
     self.impl = impl
     self.meta = meta
開發者ID:LucaBongiorni,項目名稱:kitty,代碼行數:9,代碼來源:rpc.py

示例8: HelpServer

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,代碼行數:9,代碼來源:HelpSearch.py

示例9: __init__

    def __init__(self, store, *args, **kwargs):
        HTTPServer.__init__(self, *args, **kwargs)
        self.sessions = {}
        self.store = store

        if self.server_port != 80:
            self.base_url = ('http://%s:%s/' %
                             (self.server_name, self.server_port))
        else:
            self.base_url = 'http://%s/' % (self.server_name,)
開發者ID:ziima,項目名稱:python-openid,代碼行數:10,代碼來源:consumer.py

示例10: ProxyThread

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,代碼行數:11,代碼來源:spark_submit.py

示例11: __init__

    def __init__(self, *args, **kwargs):
        HTTPServer.__init__(self, *args, **kwargs)

        if self.server_port != 80:
            self.base_url = ('http://%s:%s/' %
                             (self.server_name, self.server_port))
        else:
            self.base_url = 'http://%s/' % (self.server_name,)

        self.openid = None
        self.approved = {}
        self.lastCheckIDRequest = {}
開發者ID:ziima,項目名稱:python-openid,代碼行數:12,代碼來源:server.py

示例12: run

 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,代碼行數:14,代碼來源:annotator.py

示例13: run_echo_server

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,代碼行數:48,代碼來源:util.py

示例14: get_request

 def get_request(self):
     socket, client_address = HTTPServer.get_request(self)
     socket = ssl.wrap_socket(socket,
                              keyfile=HttpsTestServerLayer.CERT_FILE,
                              certfile=HttpsTestServerLayer.CERT_FILE,
                              server_side=True)
     return socket, client_address
開發者ID:cloudtrainings,項目名稱:crate-workshop,代碼行數:7,代碼來源:tests.py

示例15: __initialize

    def __initialize(self, config):
        self.__ssl_options = self.__get_ssl_options(config)
        self.__listen = config['listen']
        host, port = config['listen'].rsplit(':', 1)
        HTTPServer.__init__(self, (host, int(port)), RestApiHandler)
        Thread.__init__(self, target=self.serve_forever)
        self._set_fd_cloexec(self.socket)

        self.__protocol = 'http'

        # wrap socket with ssl if 'certfile' is defined in a config.yaml
        # Sometime it's also needed to pass reference to a 'keyfile'.
        if self.__ssl_options.get('certfile'):
            import ssl
            self.socket = ssl.wrap_socket(self.socket, server_side=True, **self.__ssl_options)
            self.__protocol = 'https'
        self.__set_connection_string(config.get('connect_address'))
開發者ID:jberkus,項目名稱:patroni,代碼行數:17,代碼來源:api.py


注:本文中的six.moves.BaseHTTPServer.HTTPServer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。