twisted.test.proto_helpers.StringTransport
class documentationtwisted.test.proto_helpers
View Source
(View In Hierarchy)
Known subclasses: twisted.test.proto_helpers.StringTransportWithDisconnection
Implements interfaces: twisted.internet.interfaces.IConsumer, twisted.internet.interfaces.IPushProducer, twisted.internet.interfaces.ITransport
A transport implementation which buffers data in memory and keeps track of its other state without providing any behavior.
StringTransport
has a number of attributes which are not part of any of the interfaces it
claims to implement. These attributes are provided for testing purposes.
Implementation code should not use any of these attributes; they are not
provided by other transports.
Instance Variable | disconnecting | A bool which is False until loseConnection
is called, then True . |
Instance Variable | producer | If a producer is currently registered, producer is a reference
to it. Otherwise, None . |
Instance Variable | streaming | If a producer is currently registered, streaming refers to the
value of the second parameter passed to registerProducer . |
Instance Variable | hostAddr | None or an object which will be returned as the host address
of this transport. If None , a nasty tuple will be returned
instead. |
Instance Variable | peerAddr | None or an object which will be returned as the peer address
of this transport. If None , a nasty tuple will be returned
instead. |
Instance Variable | producerState | The state of this StringTransport
in its capacity as an IPushProducer .
One of 'producing' , 'paused' , or
'stopped' . |
Instance Variable | io | A BytesIO which holds the data which has been written to this
transport since the last call to clear .
Use value
instead of accessing this directly. |
Method | __init__ | Undocumented |
Method | clear | Discard all data written to this transport so far. |
Method | value | Retrieve all data which has been buffered by this transport. |
Method | write | Write some data to the physical connection, in sequence, in a non-blocking fashion. |
Method | writeSequence | Write a list of strings to the physical connection. |
Method | loseConnection | Close the connection. Does nothing besides toggle the
disconnecting instance variable to True . |
Method | abortConnection | Abort the connection. Same as loseConnection . |
Method | getPeer | Get the remote address of this connection. |
Method | getHost | Similar to getPeer, but returns an address describing this side of the connection. |
Method | registerProducer | Register to receive data from a producer. |
Method | unregisterProducer | Stop consuming data from a producer, without disconnecting. |
Method | _checkState | Undocumented |
Method | pauseProducing | Pause producing data. |
Method | stopProducing | Stop producing data. |
Method | resumeProducing | Resume producing data. |
streaming
refers to the
value of the second parameter passed to registerProducer
.
None
or an object which will be returned as the host address
of this transport. If None
, a nasty tuple will be returned
instead.
None
or an object which will be returned as the peer address
of this transport. If None
, a nasty tuple will be returned
instead.
StringTransport
in its capacity as an IPushProducer
.
One of 'producing'
, 'paused'
, or
'stopped'
.
Discard all data written to this transport so far.
This is not a transport method. It is intended for tests. Do not use it in implementation code.
Retrieve all data which has been buffered by this transport.
This is not a transport method. It is intended for tests. Do not use it in implementation code.
Returns | A bytes giving all data written to this transport since the
last call to clear . (type: bytes ) |
Write some data to the physical connection, in sequence, in a non-blocking fashion.
If possible, make sure that it is all written. No data will ever be lost, although (obviously) the connection may be closed before it all gets through.
Write a list of strings to the physical connection.
If possible, make sure that all of the data is written to the socket at once, without first copying it all into a single string.
Close the connection. Does nothing besides toggle the
disconnecting
instance variable to True
.
Get the remote address of this connection.
Treat this method with caution. It is the unfortunate result of the CGI and Jabber standards, but should not be considered reliable for the usual host of reasons; port forwarding, proxying, firewalls, IP masquerading, etc.
Returns | An IAddress
provider. |
Similar to getPeer, but returns an address describing this side of the connection.
Returns | An IAddress
provider. |
Register to receive data from a producer.
This sets self to be a consumer for a producer. When this object runs out of data (as when a send(2) call on a socket succeeds in moving the last data from a userspace buffer into a kernelspace buffer), it will ask the producer to resumeProducing().
For IPullProducer
providers, resumeProducing
will be called once each time data
is required.
For IPushProducer
providers, pauseProducing
will be called whenever the write
buffer fills up and resumeProducing
will only be called when
it empties.
Parameters | streaming | True if producer provides IPushProducer ,
False if producer provides IPullProducer . (type: bool ) |
Returns | None | |
Raises | RuntimeError | If a producer is already registered. |
Pause producing data.
Tells a producer that it has produced too much data to process for the time being, and to stop until resumeProducing() is called.
Stop producing data.
This tells a producer that its consumer has died, so it must stop producing data for good.
Resume producing data.
This tells a producer to re-add itself to the main loop and produce more data for its consumer.