[Twisted-Python] Http PUT
Dear Twisted authors, I need to realise an HTTP server capable of serving PUT request. There seems to be no standard twisted implementation for it. Is it possible to realise and include it into the standard twisted contribution? I have no solid idea were to start with it. Thanks, VV
Voznesensky Vladimir napisał(a):
I need to realise an HTTP server capable of serving PUT request. There seems to be no standard twisted implementation for it. Is it possible to realise and include it into the standard twisted contribution? I have no solid idea were to start with it.
Start at twisted.web Just write a resource class (subclass of twisted.web.resource.Resource) that handles PUT requests by implementing render_PUT method. -- Jarek Zgoda Skype: jzgoda | GTalk: zgoda@jabber.aster.pl | voice: +48228430101 "We read Knuth so you don't have to." (Tim Peters)
Here's some sample code to get you started: def render_PUT(self,request): print "Got PUT" dataPage=request.content.getvalue() pageNumber=request.args.get("pagenumber",(0,))[0] (responseCode,message) = self._savePage(request.args["keynumber"][0], self.userId,pageNumber,dataPage) request.setResponseCode(responseCode) return message notice how you get at the PUT data via request.content.getvalue() I remember needing a while to find that. render_PUT can be added to twisted.web.resource.Resource or a subclass as Jarek says. -Andy Fundinger On 10/12/07, Jarek Zgoda <jarek.zgoda@sensisoft.com> wrote:
Voznesensky Vladimir napisał(a):
I need to realise an HTTP server capable of serving PUT request. There seems to be no standard twisted implementation for it. Is it possible to realise and include it into the standard twisted contribution? I have no solid idea were to start with it.
Start at twisted.web
Just write a resource class (subclass of twisted.web.resource.Resource) that handles PUT requests by implementing render_PUT method.
-- Jarek Zgoda Skype: jzgoda | GTalk: zgoda@jabber.aster.pl | voice: +48228430101
"We read Knuth so you don't have to." (Tim Peters)
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- Blog: http://channel3b.wordpress.com Second Life Name: Ciemaar Flintoff I am a sig Virus. Please put me in your sig so that I can continue to replicate.
Twisted is event driven. So how do I send Data through a client? All the example demonstrate is how to receive events. I suppose what I am asking is how do I refer to a client protocol from another class? My variable: loop = = gatewayClient().start() opens a reconnectingClientFactory, which opens a client protocol. How do i make that client protocol global enough to use from anywhere in my app? The ironic thing is, its easy with sockets :) Si
On Fri, Oct 12, 2007 at 08:16:18PM +0100, Simon Pickles wrote:
Twisted is event driven.
So how do I send Data through a client? All the example demonstrate is how to receive events.
I suppose what I am asking is how do I refer to a client protocol from another class?
There are a number of tutorials on this in Twisted Network Programming Esentials, by Abe Fettig. Sam
On 10/12/07, Simon Pickles <sipickles@hotmail.com> wrote:
Twisted is event driven.
So how do I send Data through a client? All the example demonstrate is how to receive events.
I don't know what you mean by "through", but whether you mean "to" or "from" the answer is the same: transport.write. ('transport' will be an attribute of your Protocol instances).
I suppose what I am asking is how do I refer to a client protocol from another class?
This is really just a basic program structuring question, and not really related to Twisted. -- Christopher Armstrong International Man of Twistery http://radix.twistedmatrix.com/ http://twistedmatrix.com/ http://canonical.com/
Simon Pickles wrote:
Twisted is event driven.
So how do I send Data through a client? All the example demonstrate is how to receive events.
I suppose what I am asking is how do I refer to a client protocol from another class?
My variable:
loop = = gatewayClient().start()
opens a reconnectingClientFactory, which opens a client protocol. How do i make that client protocol global enough to use from anywhere in my app? you "import MyFactory from mymodule" and use it as shown in example. You can do that anywhere in your app.
The ironic thing is, its easy with sockets :) I'd say the ironic thing is that sockets are so often used in a different way, imposing lots of unnecessary problems (apart from the fact that this is a rtfm question) :). What twisted gives you for free is a rock-stable way to do all networking asynchronous, which is no
Here is just one of the examples available, it's actually googles first hit for "twisted client example": http://twistedmatrix.com/projects/core/documentation/howto/tutorial/client.h... The function "finger" shows what is needed to start up a client. trivial task to achieve using sockets (i.e. writing a twisted equivalent from scratch). When you get used to it, it won't be harder to do simple things, and way easier to do complex things. It's certainly worth the effort. Johann
On Fri, 2007-10-12 at 20:16 +0100, Simon Pickles wrote:
Twisted is event driven.
So how do I send Data through a client? All the example demonstrate is how to receive events.
I suppose what I am asking is how do I refer to a client protocol from another class?
My variable:
loop = = gatewayClient().start()
opens a reconnectingClientFactory, which opens a client protocol. How do i make that client protocol global enough to use from anywhere in my app?
That's a python question. It's nothing to do with Twisted.
participants (8)
-
Andy Fundinger
-
Christopher Armstrong
-
Jarek Zgoda
-
Johann Borck
-
Phil Mayers
-
Sam Roberts
-
Simon Pickles
-
Voznesensky Vladimir