Opened 3 years ago

Closed 21 months ago

#5444 enhancement closed wontfix (wontfix)

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

Reported by: cyli Owned by: cyli
Priority: normal Milestone:
Component: core Keywords:
Cc: allister.macleod@… Branch: branches/add-stringbodyproducer-5444
(diff, github, buildbot, log)
Author: cyli Launchpad Bug:

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 3 years ago by wulczer

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 3 years ago by cyli

  • Author set to cyli
  • Branch set to branches/add-stringbodyproducer-5444

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

comment:3 follow-up: Changed 3 years ago by exarkun

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

comment:4 Changed 3 years ago by cyli

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

refs #5444

comment:5 in reply to: ↑ 3 Changed 3 years ago by cyli

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 3 years ago by cyli

  • Keywords review added

comment:7 Changed 3 years ago by cyli

  • Keywords review removed
  • Owner changed from cyli to exarkun

comment:8 Changed 3 years ago by exarkun

  • Owner changed from exarkun to cyli

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 2 years ago by amacleod

  • Cc allister.macleod@… added

comment:10 Changed 21 months ago by cyli

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

comment:11 Changed 21 months ago by cyli

  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.