[Twisted-web] [Twisted-Python] http.Request and JSON

Phil Mayers p.mayers at imperial.ac.uk
Tue Jun 30 11:38:38 EDT 2009


Reza Lotun wrote:
> On Tue, Jun 30, 2009 at 1:41 PM, Jean-Paul Calderone<exarkun at divmod.com> wrote:
>>> If that's true then there really should be a .get_body() method on the
>>> request object.
>> Why can't you seek and read?
> 
> I can, but it's not "nice". I realize that on some level twisted.web
> is a bit low-level, but having to remember to do a seek then read is a
> bit annoying. I'm sure those of us using twisted.web to, say,
> implement a REST interface end up writing some sort of convenience
> method anyway to do it.
> 
> Perhaps there are other complications I haven't considered, but why
> can't you add a get_body method?

A file-like is a python-esque idiom. You can pass it to all kinds of 
things e.g. JSON parsers, XML parsers.

What if the body is a 1 gigabyte string? Do you want twisted to read the 
results in from the tempfile, instantiate a python string, and probably 
get killed due to an out-of-memory condition?

I vote for the file-like.



More information about the Twisted-web mailing list