class documentation

class Argument: (source)

Known subclasses: twisted.protocols.amp.AmpList, twisted.protocols.amp.Boolean, twisted.protocols.amp.DateTime, twisted.protocols.amp.Decimal, twisted.protocols.amp.Float, twisted.protocols.amp.Integer, twisted.protocols.amp.ListOf, twisted.protocols.amp.String

Implements interfaces: twisted.protocols.amp.IArgumentType

View In Hierarchy

Base-class of all objects that take values from Amp packets and convert them into objects for Python functions.

This implementation of IArgumentType provides several higher-level hooks for subclasses to override. See toString and fromString which will be used to define the behavior of IArgumentType.toBox and IArgumentType.fromBox, respectively.

Method __init__ Create an Argument.
Method fromBox Populate an 'out' dictionary with mapping names to Python values decoded from an 'in' AmpBox mapping strings to string values.
Method fromString Convert a string to a Python object. Subclasses must implement this.
Method fromStringProto Convert a string to a Python value.
Method retrieve Retrieve the given key from the given dictionary, removing it if found.
Method toBox Populate an 'out' AmpBox with strings encoded from an 'in' dictionary mapping names to Python values.
Method toString Convert a Python object into a string for passing over the network.
Method toStringProto Convert a Python object to a string.
Instance Variable optional Undocumented
def __init__(self, optional=False): (source)
Create an Argument.
Parameters
optionala boolean indicating whether this argument can be omitted in the protocol.
def fromBox(self, name, strings, objects, proto): (source)
Populate an 'out' dictionary with mapping names to Python values decoded from an 'in' AmpBox mapping strings to string values.
Parameters
name:bytesthe argument name to retrieve
strings:AmpBoxThe AmpBox to read string(s) from, a mapping of argument names to string values.
objects:dictThe dictionary to write object(s) to, a mapping of names to Python objects. Keys will be native strings.
protoan AMP instance.
def fromString(self, inString): (source)
Convert a string to a Python object. Subclasses must implement this.
Parameters
inString:bytesthe string to convert.
Returns
the decoded value from inString
def fromStringProto(self, inString, proto): (source)
Convert a string to a Python value.
Parameters
inString:bytesthe string to convert.
proto:AMPthe protocol we are converting for.
Returns
a Python object.
def retrieve(self, d, name, proto): (source)
Retrieve the given key from the given dictionary, removing it if found.
Parameters
da dictionary.
namea key in d.
protoan instance of an AMP.
Returns
d[name].
Raises
KeyErrorif I am not optional and no value was found.
def toBox(self, name, strings, objects, proto): (source)
Populate an 'out' AmpBox with strings encoded from an 'in' dictionary mapping names to Python values.
Parameters
name:bytesthe argument name to retrieve
strings:AmpBoxThe AmpBox to write string(s) to, a mapping of argument names to string values.
objects:dictThe dictionary to read object(s) from, a mapping of names to Python objects. Keys should be native strings.
proto:AMPthe protocol we are converting for.
def toString(self, inObject): (source)
Convert a Python object into a string for passing over the network.
Parameters
inObjectan object of the type that this Argument is intended to deal with.
Returns
bytesthe wire encoding of inObject
def toStringProto(self, inObject, proto): (source)
Convert a Python object to a string.
Parameters
inObjectthe object to convert.
proto:AMPthe protocol we are converting for.
optional = (source)

Undocumented