2 """XSetBg (WSGI version)
6 __version__ = "$Revision$"[11:-2]
7 __revision__ = "$Id$"[5:-2]
8 __date__ = "$Date$"[7:-2]
10 __author__ = "Oleg Broytman <phd@phdru.name>"
11 __copyright__ = "Copyright (C) 2000-2011 PhiloSoft Design"
12 __license__ = "GNU GPL"
15 from wsgiref import simple_server
16 from wsgiref.handlers import SimpleHandler
17 from wsgiref.simple_server import WSGIServer, make_server
18 simple_server.ServerHandler = SimpleHandler # Stop logging to stdout
20 from xsetbg import host, port, change as _change
26 commands[func.__name__] = func
30 def change(force=False):
39 QuitWSGIServer._quit_flag = True
42 class QuitWSGIServer(WSGIServer):
45 def serve_forever(self):
46 while not self._quit_flag:
49 def app(env, start_response):
50 command = env['PATH_INFO'][1:] # Remove the leading slash
51 if command not in commands:
52 status = '404 Not found'
53 response_headers = [('Content-type', 'text/plain')]
54 start_response(status, response_headers)
55 return ['The command was not found.\n']
61 response_headers = [('Content-type', 'text/plain')]
62 start_response(status, response_headers)
63 return ['Error occured!\n']
66 response_headers = [('Content-type', 'text/plain')]
67 start_response(status, response_headers)
71 httpd = make_server(host, port, app, server_class=QuitWSGIServer)