Ticket #5444 enhancement closed wontfix

Opened 17 months ago

Last modified 2 months ago

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
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

1

  Changed 17 months 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?

2

  Changed 17 months ago by cyli

  • branch set to branches/add-stringbodyproducer-5444
  • branch_author set to cyli

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

3

follow-up: ↓ 5   Changed 17 months ago by exarkun

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

4

  Changed 17 months ago by cyli

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

refs #5444

5

in reply to: ↑ 3   Changed 17 months 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.

6

  Changed 17 months ago by cyli

  • keywords review added

7

  Changed 17 months ago by cyli

  • keywords review removed
  • owner changed from cyli to exarkun

8

  Changed 17 months 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?

9

  Changed 11 months ago by amacleod

  • cc allister.macleod@… added

10

  Changed 2 months ago by cyli

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

11

  Changed 2 months ago by cyli

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