class MultiPartProducer: (source)
Implements interfaces: twisted.web.iweb.IBodyProducer
:class:`MultiPartProducer` takes parameters for a HTTP request and produces bytes in multipart/form-data format defined in :rfc:`2388` and :rfc:`2046`. The encoded request is produced incrementally and the bytes are written to a consumer. Fields should have form: ``[(parameter name, value), ...]`` Accepted values: * Unicode strings (in this case parameter will be encoded with utf-8) * Tuples with (file name, content-type, :class:`~twisted.web.iweb.IBodyProducer` objects) Since :class:`MultiPartProducer` can accept objects like :class:`~twisted.web.iweb.IBodyProducer` which cannot be read from in an event-driven manner it uses uses a :class:`~twisted.internet.task.Cooperator` instance to schedule reads from the underlying producers. Reading is also paused and resumed based on notifications from the :class:`IConsumer` provider being written to. :ivar _fields: Sorted parameters, where all strings are enforced to be unicode and file objects stacked on bottom (to produce a human readable form-data request) :ivar _cooperate: A method like `Cooperator.cooperate` which is used to schedule all reads. :ivar boundary: The generated boundary used in form-data encoding :type boundary: `bytes`
Method | __init__ |
Undocumented |
Method | pause |
Temporarily suspend copying bytes from the input file to the consumer by pausing the `CooperativeTask` which drives that activity. |
Method | resume |
Undo the effects of a previous `pauseProducing` and resume copying bytes to the consumer by resuming the `CooperativeTask` which drives the write activity. |
Method | start |
Start a cooperative task which will read bytes from the input file and write them to `consumer`. Return a `Deferred` which fires after all bytes have been written. |
Method | stop |
Permanently stop writing bytes from the file to the consumer by stopping the underlying `CooperativeTask`. |
Instance Variable | boundary |
Undocumented |
Instance Variable | length |
Undocumented |
Method | _calculate |
Determine how many bytes the overall form post would consume. The easiest way is to calculate is to generate of `fObj` (assuming it is not modified from this point on). If the determination cannot be made, return `UNKNOWN_LENGTH`. |
Method | _get |
Returns a boundary line, either final (the one that ends the form data request or a regular, the one that separates the boundaries) |
Method | _write |
Undocumented |
Method | _write |
Undocumented |
Method | _write |
Return an iterator which generates the multipart/form-data request including the encoded objects and writes them to the consumer for each time it is iterated. |
Method | _write |
Undocumented |
Instance Variable | _cooperate |
Undocumented |
Instance Variable | _current |
Undocumented |
Instance Variable | _fields |
Undocumented |
Instance Variable | _task |
Undocumented |
Temporarily suspend copying bytes from the input file to the consumer by pausing the `CooperativeTask` which drives that activity.
Undo the effects of a previous `pauseProducing` and resume copying bytes to the consumer by resuming the `CooperativeTask` which drives the write activity.
Start a cooperative task which will read bytes from the input file and write them to `consumer`. Return a `Deferred` which fires after all bytes have been written. :param consumer: Any `IConsumer` provider
Permanently stop writing bytes from the file to the consumer by stopping the underlying `CooperativeTask`.
Determine how many bytes the overall form post would consume. The easiest way is to calculate is to generate of `fObj` (assuming it is not modified from this point on). If the determination cannot be made, return `UNKNOWN_LENGTH`.
Returns a boundary line, either final (the one that ends the form data request or a regular, the one that separates the boundaries) --this-is-my-boundary