[albatross-users] Standalone HTTP Albatross server

Dave Cole djc at object-craft.com.au
Sun Jun 29 21:02:17 EST 2003


> Attached is the first cut at a simple, standalone HTTP server script
> for Albatross apps. It's been written for 1.10pre1 although there
> seems to be a bug in that version which stops it actually
> working. See my post of 19 Jun 2003 for more on the bug and a
> possible solution.

I finally got enough things out of the way to have a bit of a play
with this stuff.

> The script is working ok for me but it has only had minimal testing
> and has some known limitations:
> 
>       * No file upload support. I will try to sort that out soon.

That would be cool but not essential.

>       * It uses the standard BaseHTTPServer module so it's not much more
>         that a toy. It's ok for local development and as a very low use
>         server i.e. for single user, web-based apps.

That is not big deal.  Greg (one of the programmers here) used
Albatross in an embedded control system.  This code would have been
very useful in further reducing the memory footprint.

> I'm posting this now in the hope that it is useful in its current
> form (i.e. without file upload) and maybe to get some feedback.

I did the simplest thing I could think of and copied some of the
sample code from the manual to test this:

I saved your code as httpd.py

It works like a bought one.  Extremely cool.

Andrew, do you think we should put this into Albatross now?

- Dave

- - cheeky.py - - - - - - - - - - - - - - - - - - - - - - - - - - - -
from albatross import SimpleApp
import httpd

class Form:
    def page_enter(self, ctx):
        ctx.locals.text = ctx.locals.singleton = ctx.locals.group = \
                          ctx.locals.radio = ctx.locals.select = None
        ctx.locals.num = 0
        ctx.add_session_vars('num')

    def page_display(self, ctx):
        ctx.locals.num += 1
        ctx.run_template('form.html')

app = SimpleApp(base_url = 'cheeky.py',
                template_path = '.',
                start_page = 'form',
                secret = '-=-secret-=-')
app.register_page('form', Form())

server = httpd.HTTPServer(app, 8080)
server.serve_forever()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - form.html (from albatross documentation) - - - - - - - - - - - - -
<html>
 <head>
  <title>Display Form Input</title>
 </head>
 <body>
  Input some values to the following form and press the submit button.
  <al-form method="post">
   Text field: <al-input name="text"><br>
   Singleton checkbox: <al-input type="checkbox" name="singleton"><br>
   Checkbox group:
   <al-input type="checkbox" name="group" list value="check1">
   <al-input type="checkbox" name="group" list value="check2"><br>
   Radio buttons:
   <al-input type="radio" name="radio" value="radio1">
   <al-input type="radio" name="radio" value="radio2"><br>
   Option menu:
   <al-select name="select">
    <al-option>option1</al-option>
    <al-option>option2</al-option>
    <al-option>option3</al-option>
   </al-select>
   <al-input type="submit" name="submit" value="submit">
  </al-form>
  number of requests: <al-value expr="num"><br>
  text: <al-value expr="text"><br>
  singleton: <al-value expr="singleton"><br>
  group: <al-value expr="group"><br>
  radio: <al-value expr="radio"><br>
  select: <al-value expr="select"><br>
 </body>
</html>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list