# ``twisted`.`protocols`.`amp`.`AmpBox``

class documentation

`class AmpBox(dict): (source)`

Known subclasses: `twisted.protocols.amp.QuitBox`, `twisted.protocols.amp._SwitchBox`, `twisted.protocols.amp._TLSBox`

View In Hierarchy

I am a packet in the AMP protocol, much like a regular bytes:bytes dictionary.

Method | `__init__` | Initialize a new `AmpBox`.
Method | `__repr__` | Undocumented
Method | `copy` | Return another AmpBox just like me.
Method | `serialize` | Convert me into a wire-encoded string.
Class Variable | `__slots__` | Undocumented
Method | `_sendTo` | Serialize and send this box to an Amp instance. By the time it is being sent, several keys are required. I must have exactly ONE of:

def __init__(self, *args, **kw): (source)
overridden in `twisted.protocols.amp._SwitchBox`, `twisted.protocols.amp._TLSBox`

Initialize a new `AmpBox`.

In Python 3, keyword arguments MUST be Unicode/native strings whereas in Python 2 they could be either byte strings or Unicode strings.

However, all keys of an `AmpBox` MUST be byte strings, or possible to transparently coerce into byte strings (i.e. Python 2).

In Python 3, therefore, native string keys are coerced to byte strings by encoding as ASCII. This can result in `UnicodeEncodeError` being raised.

Parameters
*args | See `dict`, but all keys and values should be `bytes`. On Python 3, native strings may be used as keys provided they contain only ASCII characters.
**kw | See `dict`, but all keys and values should be `bytes`. On Python 3, native strings may be used as keys provided they contain only ASCII characters.
Raises
`UnicodeEncodeError` | When a native string key cannot be coerced to an ASCII byte string (Python 3 only).

def __repr__(self): (source)
overridden in `twisted.protocols.amp.QuitBox`, `twisted.protocols.amp._SwitchBox`

Undocumented

Returns
`str` | Undocumented

def copy(self): (source)
Return another AmpBox just like me.
def serialize(self): (source)
Convert me into a wire-encoded string.

Returns
a `bytes` encoded according to the rules described in the module docstring.

__slots__: `List[str]` = (source)
overridden in `twisted.protocols.amp.QuitBox`, `twisted.protocols.amp._TLSBox`

Undocumented

def _sendTo(self, proto): (source)
overridden in `twisted.protocols.amp.QuitBox`, `twisted.protocols.amp._SwitchBox`, `twisted.protocols.amp._TLSBox`

Serialize and send this box to an Amp instance. By the time it is being sent, several keys are required. I must have exactly ONE of:

        _ask
        _answer
        _error

If the '_ask' key is set, then the '_command' key must also be set.

Parameters
proto | an AMP instance.