本文整理汇总了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)
示例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
)
)
示例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))
示例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()
示例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.
示例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
示例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)
示例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)
示例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()
示例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)
示例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.")
示例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
示例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()
示例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()
示例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.")