2 """XSetBg (WSGI version)
6 __author__ = "Oleg Broytman <phd@phdru.name>"
7 __copyright__ = "Copyright (C) 2000-2012 PhiloSoft Design"
8 __license__ = "GNU GPL"
11 from wsgiref import simple_server
12 from wsgiref.handlers import SimpleHandler
13 from wsgiref.simple_server import WSGIServer, make_server
14 simple_server.ServerHandler = SimpleHandler # Stop logging to stdout
16 from xsetbg import host, port, change as _change
22 commands[func.__name__] = func
26 def change(force=False):
35 QuitWSGIServer._quit_flag = True
38 class QuitWSGIServer(WSGIServer):
41 def serve_forever(self):
42 while not self._quit_flag:
45 def app(env, start_response):
46 command = env['PATH_INFO'][1:] # Remove the leading slash
47 if command not in commands:
48 status = '404 Not found'
49 response_headers = [('Content-type', 'text/plain')]
50 start_response(status, response_headers)
51 return ['The command was not found.\n']
57 response_headers = [('Content-type', 'text/plain')]
58 start_response(status, response_headers)
59 return ['Error occured!\n']
62 response_headers = [('Content-type', 'text/plain')]
63 start_response(status, response_headers)
67 httpd = make_server(host, port, app, server_class=QuitWSGIServer)