[albatross-users] New version of the standalone http server

Matt Goodall matt at pollenation.net
Fri Jul 4 19:52:20 EST 2003


Please feel free to include it in Albatross, that would obviously 
benefit me. I think the only thing that is missing is the file upload 
support but I still hope to fix that.

I don't really have a strong feeling on your change but it seems that 
making the application's module create an app object may make it less 
flexible although your solution is definitely the simplest and, as you 
point out, involves only a trivial change to the code.

An even better solution might be to split al-httpd into a module, say 
albatross.server.httpd, leaving only the __main__ code in al-httpd 
itself. Applications could then create an instance of the http server 
manually *if necessary* or use al-httpd in the same way as now. I see 
the mod_python vs cgi vs fcgi vs httpd as a deployment decision and 
nothing much to do with the application code itself or in other words 
... who hows how someone might want to deploy an application based on 
Albatross on their server.

I'm not sure if I have explained that too well but what I can imagine 
doing is having a series of startup scripts for the application 
depending on how I'm using it (i.e. dev vs prod). Sometime like this 
(completely untested):

-- standalone.py --
from albatross.server import httpd
import myapp

app = myapp.App(base_url = '/', base_dir = '/home/matt/src/myapp')

httpd = httpd.HTTPServer(app, 8000)
httpd.serve_forever()
--

-- app.py --
from albatross import cgiapp
import myapp

app = myapp.App(base_url = '/dev/myapp/app.py', base_dir = 
'/home/matt/src/myapp')
app.run(cgiapp.Request())
--

etc

What are your thoughts on this? I will split the al-httpd script up 
today, as detailed above, if you think it's a good approach, or if you 
want to keep it simple, I'm happy with that too.

Cheers, Matt

Dave Cole wrote:

>>Attached is an updated version of the standalone server with the
>>following changes:
>>
>>      * Fixed to support forms containing input fields with a "list"
>>        attribute. It only ever returned the first value in the get or
>>        post data before.
>>      * Added the current working directory to the path so that the
>>        httpd.py script can live anywhere.
>>      * changed the filename to al-httpd. An even better name might be
>>        al-simple-server.
>>    
>>
>
>It works beautifully.  I would love to add this to Albatross to sit
>next to your FastCGI code.
>
>I made one small change to your code to make it a bit more flexible (I
>hope).  I let the application mainline construct the application
>object.
>
>--- al-httpd-orig	2003-07-03 23:09:30.000000000 +1000
>+++ al-httpd	2003-07-03 23:07:18.000000000 +1000
>@@ -149,7 +149,7 @@
> 
>     # Load the application's module and create an application instance
>     module = __import__(appClass[:appClass.rindex('.')])
>-    app = getattr(module,appClass[appClass.rindex('.')+1:])()
>+    app = getattr(module,appClass[appClass.rindex('.')+1:])
> 
>     # Create the HTTP server
>     httpd = HTTPServer(app, port)
>
>Now with the most trivial change to the form4 Albatross sample it
>works fantastically.
>
>--- samples/form4/form.py	2002-08-17 23:14:36.000000000 +1000
>+++ form.py	2003-07-03 23:13:40.000000000 +1000
>@@ -19,4 +19,5 @@
>                 secret = '-=-secret-=-')
> app.register_page('form', Form())
> 
>-app.run(Request())
>+if __name__ == '__main__':
>+    app.run(Request())
>
>Now due to you code I can do this:
>
>$ al-httpd form.app 8080
>
>That is cool!
>
>- Dave
>
>  
>

-- 
Matt Goodall, Pollenation Internet Ltd
e: matt at pollenationinternet.com
t: 0113 2252500





More information about the Albatross-users mailing list