class documentation

class MultiPartProducer: (source)

Implements interfaces: twisted.web.iweb.IBodyProducer

View In Hierarchy

: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 pauseProducing Temporarily suspend copying bytes from the input file to the consumer by pausing the `CooperativeTask` which drives that activity.
Method resumeProducing Undo the effects of a previous `pauseProducing` and resume copying bytes to the consumer by resuming the `CooperativeTask` which drives the write activity.
Method startProducing 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 stopProducing Permanently stop writing bytes from the file to the consumer by stopping the underlying `CooperativeTask`.
Instance Variable boundary Undocumented
Instance Variable length Undocumented
Method _calculateLength 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 _getBoundary Returns a boundary line, either final (the one that ends the form data request or a regular, the one that separates the boundaries)
Method _writeField Undocumented
Method _writeFile Undocumented
Method _writeLoop 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 _writeString Undocumented
Instance Variable _cooperate Undocumented
Instance Variable _currentProducer Undocumented
Instance Variable _fields Undocumented
Instance Variable _task Undocumented
def __init__(self, fields, boundary=None, cooperator=task): (source)

Undocumented

def pauseProducing(self): (source)

Temporarily suspend copying bytes from the input file to the consumer by pausing the `CooperativeTask` which drives that activity.

def resumeProducing(self): (source)

Undo the effects of a previous `pauseProducing` and resume copying bytes to the consumer by resuming the `CooperativeTask` which drives the write activity.

def startProducing(self, consumer): (source)

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

def stopProducing(self): (source)

Permanently stop writing bytes from the file to the consumer by stopping the underlying `CooperativeTask`.

boundary = (source)

Undocumented

length = (source)

Undocumented

def _calculateLength(self): (source)

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

def _getBoundary(self, final=False): (source)

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

def _writeField(self, name, value, consumer): (source)

Undocumented

def _writeFile(self, name, filename, content_type, producer, consumer): (source)

Undocumented

def _writeLoop(self, consumer): (source)

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.

def _writeString(self, name, value, consumer): (source)

Undocumented

_cooperate = (source)

Undocumented

_currentProducer = (source)

Undocumented

_fields = (source)

Undocumented

_task = (source)

Undocumented