Opened 5 years ago

Closed 4 years ago

#5444 enhancement closed wontfix (wontfix)

Add a string version of IBodyProducer to twisted.web.client

Reported by: Ying Li Owned by: Ying Li
Priority: normal Milestone:
Component: core Keywords:
Cc: Allister MacLeod Branch: branches/add-stringbodyproducer-5444
branch-diff, diff-cov, branch-cov, buildbot
Author: cyli

Description

twisted.web.client has a FileBodyProducer, but no StringBodyProducer, even though it seems like it would be pretty commonly useful and an example is already provided in the howto:

http://twistedmatrix.com/documents/11.1.0/web/howto/client.html

Change History (11)

comment:1 Changed 5 years ago by Jan Urbański

Seems like a good idea, I know I wrote my own implementation that's byte-for-byte identical to the one from the howto (without reading the howto) with one exception: to fully implement IBodyProducer shouldn't it have a resumeProducing method?

comment:2 Changed 5 years ago by Ying Li

Author: cyli
Branch: branches/add-stringbodyproducer-5444

(In [33408]) Branching to 'add-stringbodyproducer-5444'

comment:3 Changed 5 years ago by Jean-Paul Calderone

FileBodyProducer(StringIO(text)) pretty much covers this case, though.

comment:4 Changed 5 years ago by Ying Li

(In [33409]) Add StringBodyProducer to twisted.web.client

refs #5444

comment:5 in reply to:  3 Changed 5 years ago by Ying Li

In that case the howto should probably be modified. At any rate, I had this code lying around anyway, so feel free to reject/close the ticket.

Buildbot: http://buildbot.twistedmatrix.com/boxes-supported?branch=/branches/add-stringbodyproducer-5444

Replying to exarkun:

FileBodyProducer(StringIO(text)) pretty much covers this case, though.

comment:6 Changed 5 years ago by Ying Li

Keywords: review added

comment:7 Changed 5 years ago by Ying Li

Keywords: review removed
Owner: changed from Ying Li to Jean-Paul Calderone

comment:8 Changed 5 years ago by Jean-Paul Calderone

Owner: changed from Jean-Paul Calderone to Ying Li

I'm not going to object to the addition of this. I don't think it's very strongly necessary, given FileBodyProducer. Perhaps some people will find the pure-string based version easier to find or use, though.

The documentation should definitely be updated to talk about FileBodyProducer (and the StringIO trick) or StringBodyProducer once that's added. I do not think the howto should have its producer implementation completely deleted - it seems to me that it is useful to shove the implementation, simple as it is, in the face of people trying to learn this. We might update the implementation in the howto to be identical to the real implementation though, or maybe just link to the real implementation somehow (we don't have a good mechanism for linking to source though, I think).

And I think the implementation of StringBodyProducer, should we decide to add it, needs to be simpler. How about:

    class StringBodyProducer(FileBodyProducer):
        def __init__(self, bytes):
            FileBodyProducer.__init__(self, StringIO(bytes))

That does the trick, right?

comment:9 Changed 4 years ago by Allister MacLeod

Cc: Allister MacLeod added

comment:10 Changed 4 years ago by Ying Li

http://twistedmatrix.com/documents/current/web/howto/client.html has an example of FileBodyProducer(StringIO()) so going go close this?

comment:11 Changed 4 years ago by Ying Li

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.