def __call_service(self, query):
"""Execute service method implemented by child class.
When either a GET or POST request is received, this method is
called with a string representing the query. Request and response
objects are created for the child's service method, and an answer
is sent back to the client with errors automatically being caught."""
request = _HttpServletRequest(query)
response = _HttpServletResponse()
try:
self.service(request, response)
except Exception:
if self.__debug:
self.send_response(500)
self.send_header('Content-Type', 'text/html')
self.send_header('Connection', 'close')
self.end_headers()
klass, value, trace = sys.exc_info()
# The next function call may raise an exception.
html = cgitb.html((klass, value, trace.tb_next))
self.wfile.write(html.encode())
else:
self.send_error(500)
else:
response_value = response._value
self.send_response(200)
self.send_header('Content-Type', response._type)
self.send_header('Content-Length', str(len(response_value)))
self.end_headers()
self.wfile.write(response_value)
评论列表
文章目录