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


Python BaseHTTPServer.HTTPServer方法代码示例

本文整理汇总了Python中six.moves.BaseHTTPServer.HTTPServer方法的典型用法代码示例。如果您正苦于以下问题:Python BaseHTTPServer.HTTPServer方法的具体用法?Python BaseHTTPServer.HTTPServer怎么用?Python BaseHTTPServer.HTTPServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.BaseHTTPServer的用法示例。


在下文中一共展示了BaseHTTPServer.HTTPServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BuildServer

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def BuildServer(multiplexer, host, port, logdir):
  """Sets up an HTTP server for running TensorBoard.

  Args:
    multiplexer: An `EventMultiplexer` that the server will query for
      information about events.
    host: The host name.
    port: The port number to bind to, or 0 to pick one automatically.
    logdir: The logdir argument string that tensorboard started up with.
  Returns:
    A `BaseHTTPServer.HTTPServer`.
  """
  names_to_plugins = {'projector': projector_plugin.ProjectorPlugin()}
  factory = functools.partial(handler.TensorboardHandler, multiplexer,
                              names_to_plugins, logdir)
  return ThreadedHTTPServer((host, port), factory) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:18,代码来源:server.py

示例2: _parse_request

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def _parse_request(self):
        """
        Put the request into the HTTPServer's requests queue. Get the response
        from the HTTPServer's response queue. If there is no response send an
        error message back.

        :return: ``None``
        :rtype: ``NoneType``
        """
        response = self.get_response(request=self.path)
        if not isinstance(response, HTTPResponse):
            raise TypeError("Response must be of type HTTPResponse")

        self._send_header(
            status_code=response.status_code, headers=response.headers
        )
        self._send_content(response.content)
        self.server.log_callback(
            "Sent response with:\n  status code {}\n  headers {}".format(
                response.status_code, response.headers
            )
        ) 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:24,代码来源:server.py

示例3: __init__

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def __init__(
        self,
        name,
        host="localhost",
        port=0,
        request_handler=HTTPRequestHandler,
        handler_attributes=None,
        timeout=5,
        interval=0.01,
        **options
    ):
        options.update(self.filter_locals(locals()))
        super(HTTPServer, self).__init__(**options)
        self._host = None
        self._port = None
        self.request_handler = None
        self.handler_attributes = None
        self.timeout = None
        self.interval = None
        self.requests = None
        self.responses = None
        self._server_thread = None
        self._logname = "{0}.log".format(slugify(self.cfg.name)) 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:25,代码来源:server.py

示例4: run

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def run(self):
        """Start the HTTP server thread."""
        self.server = http_server.HTTPServer(
            server_address=(self.host, self.port),
            RequestHandlerClass=self.request_handler,
        )
        self.server.requests = self.requests_queue
        self.server.responses = self.responses_queue
        self.server.handler_attributes = self.handler_attributes
        self.server.timeout = self.timeout
        self.server.interval = self.interval
        nothing = lambda msg: None
        self.server.log_callback = (
            self.logger.debug if self.logger else nothing
        )
        self.server.serve_forever() 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:18,代码来源:server.py

示例5: handle_rpc

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def handle_rpc(self, method, request):
    """Called by _RequestHandler to handle one RPC call.

    Called from internal server thread. May be called even if the server is
    already stopped (due to BaseHTTPServer.HTTPServer implementation that
    stupidly leaks handler threads).

    Args:
      method: name of the invoked RPC method, e.g. "GetOAuthToken".
      request: JSON dict with the request body.

    Returns:
      JSON dict with the response body.

    Raises:
      RPCError to return non-200 HTTP code and an error message as plain text.
    """
    if method == 'GetOAuthToken':
      return self.handle_get_oauth_token(request)
    raise RPCError(404, 'Unknown RPC method "%s".' % method)

  ### RPC method handlers. Called from internal threads. 
开发者ID:luci,项目名称:luci-py,代码行数:24,代码来源:auth_server.py

示例6: run_http_server

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def run_http_server(request_handler_class):
    while True:
        port = get_unused_port()
        try:
            server = BaseHTTPServer.HTTPServer(('', port), request_handler_class)
            break
        except socket.error:
            pass

    def run():
        while True:
            server.handle_request()

    thread = threading.Thread(target=run)
    thread.daemon = True
    thread.start()

    return 'http://127.0.0.1:%d/' % port 
开发者ID:cryzed,项目名称:Selenium-Requests,代码行数:20,代码来源:test_seleniumrequests.py

示例7: run

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def run(cls, service, ticket, username, attributes, port=0):
        """Run a BaseHTTPServer using this class as handler"""
        server_class = BaseHTTPServer.HTTPServer
        httpd = server_class(("127.0.0.1", port), cls)
        httpd.service = service
        httpd.ticket = ticket
        httpd.username = username
        httpd.attributes = attributes
        (host, port) = httpd.socket.getsockname()

        def lauch():
            """routine to lauch in a background thread"""
            httpd.handle_request()
            httpd.server_close()

        httpd_thread = Thread(target=lauch)
        httpd_thread.daemon = True
        httpd_thread.start()
        return (httpd, host, port) 
开发者ID:nitmir,项目名称:django-cas-server,代码行数:21,代码来源:utils.py

示例8: http_serv_obj

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def http_serv_obj():
    """
    Return an HTTP object listening on localhost port 80 for testing
    """
    return HTTPServer(('localhost', 80), SimpleHTTPRequestHandler) 
开发者ID:CRS-support,项目名称:ftw,代码行数:7,代码来源:pytest_plugin.py

示例9: run

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [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:stanfordnlp,项目名称:python-stanford-corenlp,代码行数:16,代码来源:annotator.py

示例10: logpath

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def logpath(self):
        """HTTPServer logfile in runpath."""
        return os.path.join(self.runpath, self._logname) 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:5,代码来源:server.py

示例11: queue_response

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def queue_response(self, response):
        """
        Put an HTTPResponse on to the end of the response queue.

        :param response: A response to be sent.
        :type response: ``HTTPResponse``
        """
        if not isinstance(response, HTTPResponse):
            raise TypeError("Response must be of type HTTPResponse")
        self.responses.put(response)
        self.file_logger.debug("Added response to HTTPServer response queue.") 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:13,代码来源:server.py

示例12: get_request

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def get_request(self):
        """
        Get a request sent to the HTTPServer, if the requests queue is empty
        return None.

        :return: A request from the queue or ``None``
        :rtype: ``str`` or ``NoneType``
        """
        try:
            return self.requests.get(False)
        except queue.Empty:
            return None 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:14,代码来源:server.py

示例13: _stop

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def _stop(self):
        """Stop the HTTPServer."""
        if self._server_thread:
            self._server_thread.stop() 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:6,代码来源:server.py

示例14: stopping

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def stopping(self):
        """Stop the HTTPServer."""
        super(HTTPServer, self).stopping()
        self._stop()
        self.file_logger.debug("Stopped HTTPServer.")
        self._close_file_logger() 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:8,代码来源:server.py

示例15: aborting

# 需要导入模块: from six.moves import BaseHTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
def aborting(self):
        """Abort logic that stops the server."""
        self._stop()
        self.file_logger.debug("Aborted HTTPServer.") 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:6,代码来源:server.py


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