Porting 2.x to 3.3: BaseHTTPServer

Chris Angelico rosuav at gmail.com
Sun Apr 21 10:13:48 EDT 2013


On Mon, Apr 22, 2013 at 12:01 AM, Roy Smith <roy at panix.com> wrote:
> In article <mailman.879.1366551990.3114.python-list at python.org>,
>  Chris Angelico <rosuav at gmail.com> wrote:
>
>> In the current version of the code, I use BaseHTTPServer as the main
>> structure of the request handler. 2to3 translated this into
>> http.server, which seems to be the nearest direct translation. But is
>> that the best way to go about making a simple HTTP server?
>
> For most purposes, I would suggest one of the third-party web
> frameworks.  For simple things, I'm partial to Tornado, but it's not the
> only choice.  The advantage of these frameworks is they give you a lot
> of boilerplate code that handles all the low-level protocol gunk and
> lets you concentrate on writing your application logic.
>
> My gut feeling is that nobody should ever be using BaseHTTPServer for
> anything other than as a learning exercise (or as a base on which to
> build other frameworks).  It's just too low level.  I haven't used the
> 3.x http.server, but http.server looks like much of the same.

Have a look at the code in question:

https://github.com/Rosuav/Yosemite/blob/master/Yosemite.py#L81

It's REALLY simple. I don't need any sort of framework; it's basically
just using a web browser as its UI, to save on writing a client. So
I'm looking for the simplest possible option; I don't need security or
anything (this is designed for a trusted LAN), nor scaleability (we're
talking queries per hour, not per second).

I'm actually looking at cutting it back even further. There are
os.system() calls that I'm thinking should possibly become popen(),
and maybe copy a binary into /tmp and giving a full path to it, as
sometimes this is used on a low-end system and needs to perform
actions with low latency.

ChrisA



More information about the Python-list mailing list