[Twisted-Python] session

Thomas Weholt 2002 at weholt.org
Sat Feb 15 19:08:04 EST 2003

This is very interesting. I found out much of what was unclear when I posted
my earlier posting to this list by looking at this code. But I have some
more questions :

- how do I send HTTP-headers to the client?

- if I want to create some webservices, both XML-RPC and SOAP-based without
starting a different server using something like the code below, how do I do
that? I want to run one server, providing both webservices and content aimed
at browsers.

- is this the preferred way of doing things? Can I base my work on this
example? Drawbacks? I need the fastest, most scalable method available,
which can handle lots of concurrent users, several downloads and processes
at the same time, both using simple web-pages, webservices like the ones
mentioned earlier and ftp-access for administrators to maintain files served
by the server, both static files and source-code. The server should be able
to reload, using updated source without a complete restart. That would be
the ultimate platform. I'm still a bit unclear on wheter Twisted is a async.
*blocking* framework, making concurrent downloads harder, if at all
possible, or if it is similar to the threaded solution available in the
standard python distr. I've based my solutions on a threaded version of
BaseHTTPServer so far, and been told this is not very scalable. But I need a
non-blocking solution, where one process doesn't lock the entire server
until that process is over before other clients are handled.

Any clues, hints, code or flames appreciated. Thanks so far. Twisted looks
great !! :-)

Best regards,

----- Original Message -----
From: "William Dode" <wilk-ml at flibuste.net>
To: <twisted-python at twistedmatrix.com>
Sent: Saturday, February 15, 2003 7:11 PM
Subject: [Twisted-Python] session

> Hi,
> I did an other litle example to see how can work session. A shop where
> you put some articles in your bag...
> I do request.getSession() and set attribute directly to the session...
> Is it the good way ?
> import twisted.web.resource
> import cgi
> class Shop(twisted.web.resource.Resource):
>     """ ReportRequest with forms and cookies """
>     articles=("chocolate","banana","apple")
>     def isLeaf(self):
>         return true
>     def render(self, request):
>         session = request.getSession()
>         try:
>             bag = session.bag
>         except AttributeError:
>             bag = session.bag={}
>         try:
>             article = request.args["put"][0]
>             bag[article] = session.bag.get(article,0)+1
>         except KeyError:
>             pass # no article to put
>         out = []
>         out.append("""<html><body>What do you want to put in your bag
>         <a href='?put=chocolate'>chocolate</a><br>
>         <a href='?put=banana'>banana</a><br>
>         <a href='?put=apple'>apple</a><br>
>         """)
>         if len(bag) == 0:
>             out.append("Your bag is empty")
>         else:
>             out.append("You have in your bag :<br>")
>             for k,v in bag.items():
>                 out.append("%d %s<br>"%(v,k))
>         return "".join(out)
> from twisted.internet import reactor
> from twisted.web import static, server
> site = server.Site(Shop())
> reactor.listenTCP(8080,site)
> reactor.run()
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

More information about the Twisted-Python mailing list