Python http.server.server_close() Examples
The following are 2
code examples of http.server.server_close().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
http.server
, or try the search function
.
Example #1
Source File: test_xmlrpc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_keepalive_disconnect(self): class RequestHandler(http.server.BaseHTTPRequestHandler): protocol_version = "HTTP/1.1" handled = False def do_POST(self): length = int(self.headers.get("Content-Length")) self.rfile.read(length) if self.handled: self.close_connection = True return response = xmlrpclib.dumps((5,), methodresponse=True) response = response.encode() self.send_response(http.HTTPStatus.OK) self.send_header("Content-Length", len(response)) self.end_headers() self.wfile.write(response) self.handled = True self.close_connection = False def run_server(): server.socket.settimeout(float(1)) # Don't hang if client fails server.handle_request() # First request and attempt at second server.handle_request() # Retried second request server = http.server.HTTPServer((support.HOST, 0), RequestHandler) self.addCleanup(server.server_close) thread = threading.Thread(target=run_server) thread.start() self.addCleanup(thread.join) url = "http://{}:{}/".format(*server.server_address) with xmlrpclib.ServerProxy(url) as p: self.assertEqual(p.method(), 5) self.assertEqual(p.method(), 5)
Example #2
Source File: test_xmlrpc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_xmlrpcserver_has_use_builtin_types_flag(self): server = xmlrpc.server.SimpleXMLRPCServer(("localhost", 0), use_builtin_types=True) server.server_close() self.assertTrue(server.use_builtin_types)