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-2010 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
24 func._wsgi_published = True
28 def change(force=False):
37 QuitWSGIServer._quit_flag = True
41 commands = dict([(name, g[name]) for name in g
42 if getattr(g[name], '_wsgi_published', False)])
45 class QuitWSGIServer(WSGIServer):
48 def serve_forever(self):
49 while not self._quit_flag:
52 def app(env, start_response):
53 command = env['PATH_INFO'][1:] # Remove the leading slash
54 if command not in commands:
55 status = '404 Not found'
56 response_headers = [('Content-type', 'text/plain')]
57 start_response(status, response_headers)
58 return ['The command was not found.\n']
64 response_headers = [('Content-type', 'text/plain')]
65 start_response(status, response_headers)
66 return ['Error occured!\n']
69 response_headers = [('Content-type', 'text/plain')]
70 start_response(status, response_headers)
74 httpd = make_server(host, port, app, server_class=QuitWSGIServer)