I spent last week at The developer meeting in Denmark, this has been a great meeting, wonderfully organised and followed by an astonishing hackfest! Here is are some short notes about my work during the hackfest.
During the hackfest I’ve been working on the refactoring of the server component, aimed to wrap the server into a class and create python bindings for the new classes. This work is now in the PR queue and brings a first working python test for the server itself.
The server can now be invoked directly from python, like in the example below:
#!/usr/bin/env python """ Super simple QgsServer. """ from qgis.server import * from BaseHTTPServer import * class handler (BaseHTTPRequestHandler): server = QgsServer() def _doHeaders(self, response): l = response.pop(0) while l: h = l.split(':') self.send_header(h, ':'.join(h[1:])) self.log_message( "send_header %s - %s" % (h, ':'.join(h[1:]))) l = response.pop(0) self.end_headers() def do_HEAD(self): self.send_response(200) response = str(handler.server.handleRequestGetHeaders(self.path[2:])).split('\n') self._doHeaders(response) def do_GET(self): response = str(handler.server.handleRequest(self.path[2:])).split('\n') i = 0 self.send_response(200) self._doHeaders(response) self.wfile.write(('\n'.join(response[i:])).strip()) def do_OPTIONS(s): handler.do_GET(s) httpd = HTTPServer( ('', 8000), handler) while True: httpd.handle_request()
The python bindings capture the server output instead of printing it on FCGI stdout and allow to pass the request parameters
QUERY_STRING directly to the request handler as a string, this makes writing python tests very easy.