Go to the latest version of this document.
search in docstrings

Search bar offers the following options:

- Term presence. The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”: `+foo bar -baz`
- Wildcards. The below example searches for documents with words beginning with “foo”: `foo*`
- Search in specific fields. The following search matches all objects in "twisted.mail" that matches “search”: `+qname:twisted.mail.* +search`

  Possible fields: 'name', 'qname' (fully qualified name), 'docstring', and 'kind'. Last two fields are only applicable if "search in docstrings" is enabled.

- Fuzzy matches. The following search matches all documents that have a word within 1 edit distance of “foo”: `foo~1`

Results provided by Lunr.js

# ``twisted`.`internet`.`testing`.`StringTransport``

class documentation

`class StringTransport: (source)`

Known subclasses: `twisted.internet.testing.StringTransportWithDisconnection`

Constructor: `StringTransport(hostAddress, peerAddress, lenient)`

Implements interfaces: `twisted.internet.interfaces.IConsumer`, `twisted.internet.interfaces.IPushProducer`, `twisted.internet.interfaces.ITransport`

View In Hierarchy

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.

Method | `__init__` | Undocumented
Method | `abortConnection` | Abort the connection. Same as `loseConnection`, but also toggles the `aborted` instance variable to `True`.
Method | `clear` | Discard all data written to this transport so far.
Method | `getHost` | Similar to getPeer, but returns an address describing this side of the connection.
Method | `getPeer` | Get the remote address of this connection.
Method | `loseConnection` | Close the connection. Does nothing besides toggle the `disconnecting` instance variable to `True`.
Method | `pauseProducing` | Pause producing data.
Method | `registerProducer` | Register to receive data from a producer.
Method | `resumeProducing` | Resume producing data.
Method | `stopProducing` | Stop producing data.
Method | `unregisterProducer` | Stop consuming data from a producer, without disconnecting.
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 an iterable of byte strings to the physical connection.
Instance Variable | `connected` | Undocumented
Instance Variable | `disconnected` | A `bool` which is `False` until `abortConnection` is called, then `True`.
Instance Variable | `disconnecting` | A `bool` which is `False` until `loseConnection` is called, then `True`.
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 | `io` | A `io.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.
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 | `producer` | If a producer is currently registered, `producer` is a reference to it. Otherwise, `None`.
Instance Variable | `producerState` | The state of this `StringTransport` in its capacity as an `IPushProducer`. One of `'producing'`, `'paused'`, or `'stopped'`.
Instance Variable | `streaming` | If a producer is currently registered, `streaming` refers to the value of the second parameter passed to `registerProducer`.
Method | `_checkState` | Undocumented
Instance Variable | `_lenient` | By default `StringTransport` enforces that `resumeProducing` is not called after the connection is lost. This is to ensure that any code that does call `resumeProducing` after the connection is lost is not blindly expecting ...

def __init__(self, hostAddress=None, peerAddress=None, lenient=False): (source)

Undocumented

def abortConnection(self): (source)

Abort the connection. Same as `loseConnection`, but also toggles the `aborted` instance variable to `True`.

def clear(self): (source)

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.

def getHost(self): (source)
from `twisted.internet.interfaces.ITransport`

Similar to getPeer, but returns an address describing this side of the connection.

Returns
An `IAddress` provider.

def getPeer(self): (source)
from `twisted.internet.interfaces.ITransport`

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.

def loseConnection(self): (source)
from `twisted.internet.interfaces.ITransport`
overridden in `twisted.internet.testing.StringTransportWithDisconnection`

Close the connection. Does nothing besides toggle the `disconnecting` instance variable to `True`.

def pauseProducing(self): (source)
from `twisted.internet.interfaces.IPushProducer`

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.

def registerProducer(self, producer, streaming): (source)
from `twisted.internet.interfaces.IConsumer`

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. The consumer will only call `resumeProducing` to balance a previous `pauseProducing` call; the producer is assumed to start in an un-paused state.

Parameters
producer | Undocumented
streaming | `True` if `producer` provides `IPushProducer`, `False` if `producer` provides `IPullProducer`.
Raises
`RuntimeError` | If a producer is already registered.

def resumeProducing(self): (source)
from `twisted.internet.interfaces.IPushProducer`

Resume producing data.

This tells a producer to re-add itself to the main loop and produce more data for its consumer.

def stopProducing(self): (source)
from `twisted.internet.interfaces.IProducer`

Stop producing data.

This tells a producer that its consumer has died, so it must stop producing data for good.

def unregisterProducer(self): (source)
from `twisted.internet.interfaces.IConsumer`

Stop consuming data from a producer, without disconnecting.

def value(self): (source)

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
`bytes` | A `bytes` giving all data written to this transport since the last call to `clear`.

def write(self, data): (source)
from `twisted.internet.interfaces.ITransport`

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.

Parameters
data | The data to write.

def writeSequence(self, data): (source)
from `twisted.internet.interfaces.ITransport`

Write an iterable of byte 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 byte string.

Parameters
data | The data to write.

connected: `bool` = (source)
overridden in `twisted.internet.testing.StringTransportWithDisconnection`

Undocumented

disconnected: `bool` = (source)

A `bool` which is `False` until `abortConnection` is called, then `True`.

disconnecting: `bool` = (source)

A `bool` which is `False` until `loseConnection` is called, then `True`.

hostAddr = (source)

`None` or an object which will be returned as the host address of this transport. If `None`, a nasty tuple will be returned instead.

io = (source)

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

peerAddr = (source)

`None` or an object which will be returned as the peer address of this transport. If `None`, a nasty tuple will be returned instead.

producer = (source)

If a producer is currently registered, `producer` is a reference to it. Otherwise, `None`.

producerState: `str` = (source)

The state of this `StringTransport` in its capacity as an `IPushProducer`. One of `'producing'`, `'paused'`, or `'stopped'`.

streaming = (source)

If a producer is currently registered, `streaming` refers to the value of the second parameter passed to `registerProducer`.

def _checkState(self): (source)

Undocumented

_lenient = (source)

By default `StringTransport` enforces that `resumeProducing` is not called after the connection is lost. This is to ensure that any code that does call `resumeProducing` after the connection is lost is not blindly expecting `resumeProducing` to have any impact.

However, if your test case is calling `resumeProducing` after connection close on purpose, and you know it won't block expecting further data to show up, this flag may safely be set to `True`.

Defaults to `False`.