Significant portions of nucleon.amqp are code generated from various AMQP specifications and templates.
The actual specifications used are:
In principle the JSON document could be eliminated as I believe the XML file contains a superset of information, eg. documentation that is used in docstrings.
The templates used are in templates/.
Simply run:
$ make
in the root of the project. This should clone the rabbitmq-codegen Mercurial repo if it does not already exist locally.
This ultimately invokes a method in codegen.py to generate each of the necessary files.
The output of the code generation are two files spec.py and spec_exception.py.
spec.py contains classes corresponding to all of the method frames in the AMQP specification.
Each frame has these properties and methods:
- class Frame¶
- METHOD_ID¶
A numeric constant; the ID of the type of frame as it appears on the wire.
- name¶
A string that is the protocol-level name of the frame, eg. queue.declare-ok
- has_content¶
Whether or not the frame has content, ie. a message. Such a frame is followed on the wire by a properties/header frame and then zero or more payload frames.
- static decode(buffer)¶
Decode an instance of the frame from the data encoded in buffer.
- encode()¶
Encode the frame instance. This returns an iterable of tuples of the form (frame_type, payload).
Because Frame classes are intended for performance and are not expected to be subclasses, they define appropriate __slots__ and therefore do not possess an instance dictionary.
Also defined in spec.py are functions for encoding and decoding message properties:
Finally, and most importantly, there is defined the FrameWriter abstract class, which defines all of the AMQP methods as method calls.
- @nucleon.amqp.spec.syncmethod(*responses)[source]¶
This decorator is used to add blocking semantics to FrameWriter methods that are defined as synchronous. Synchronous methods are not invoked directly, but are instead passed to self._call_sync with the responses specified in the decorator.
This file contains exceptions for each of the error codes defined in the specification.