[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):
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:
-- 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 10/12/07, Simon Pickles <sipickles@hotmail.com> wrote:
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:
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

Voznesensky Vladimir napisał(a):
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:
-- 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 10/12/07, Simon Pickles <sipickles@hotmail.com> wrote:
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:
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
participants (8)
-
Andy Fundinger
-
Christopher Armstrong
-
Jarek Zgoda
-
Johann Borck
-
Phil Mayers
-
Sam Roberts
-
Simon Pickles
-
Voznesensky Vladimir