Indrio Development Continues Apace: HTTP Server

For this particular application I don’t care where the user interface is displayed. In fact it would be cooler if the UI could go somewhere other than where iTunes is. In fact it would also be cool if a couple of people on different computers could access the thing at the same time, bonus. So I decided to send the UI out over an HTTP server to a browser and use a bit of AJAX to make this snappy. This brought development to an impasse, where do you get an HTTP server for python. Apache was out of the question, I’m not having users install that thing just to run this little app, way overkill. In fact what I wanted was fairly specific:

  • Small; as in not large, as in less than 1 MB compiled
  • Embedded; must run from inside the app, no external servers please
  • Must not stop me from talking to COM
  • Must be nice to Unicode strings
  • Must be nice to AJAX
  • Must serve some static files
  • Must server some dynamic content probably composed with a template system

Turns out there was only one system that I could locate that fit the bill, CherryPy. Getting the demo up and running was easy. Getting it to talk to COM was trickier. Its got something to do with threads and CoInitialize-ing them. The docs there almost have the magic formula, you have to hook on to whatever COM object you are calling after you call CoInitialize(). This means you can’t start up COM in the built in __init__ function of your root class in CherryPy, you have to call it from in the InitializeCOM()function, after the call to CoInitialize(). With that sorted I got the HTTP server to stop giving 501 errors and spit out the version of iTunes; “ “. So far so good.

Now I am a big believer in the MVC pattern, code should stay in the code, and the view should be just the view. So next I wanted a template language to put together with CherryPy to complete my tool set. There seem to be a lot of these out there, mainly that want to mess with the HTML your writing to make sure your doing it right. Now, writing XHTML strict isn’t a problem and there is the posibility that I might generate some JavaScript code. The template engine has to be general, small size is a plus, easy to learn is a plus. Cheetah looks almost exactly like Velocity to me, and I’ve worked with Velocity before so its a good fit for a rapid prototype.



Comments are closed.