Debian Codegraph @

pamqp/common.py

raw
1 """
2 Common type aliases and classes.
3
4 """
5
6 import datetime
7 import decimal
8 import struct
9
10 FieldArray = list['FieldValue']
11 """A data structure for holding an array of field values."""
12
13 FieldTable = dict[str, 'FieldValue']
14 """Field tables are data structures that contain packed name-value pairs.
15
16 The name-value pairs are encoded as short string defining the name, and octet
17 defining the values type and then the value itself. The valid field types for
18 tables are an extension of the native integer, bit, string, and timestamp
19 types, and are shown in the grammar. Multi-octet integer fields are always
20 held in network byte order.
21
22 Guidelines for implementers:
23
24 - Field names MUST start with a letter, '$' or '#' and may continue with
25 letters, `$` or `#`, digits, or underlines, to a maximum length of 128
26 characters.
27 - The server SHOULD validate field names and upon receiving an invalid field
28 name, it SHOULD signal a connection exception with reply code 503
29 (syntax error).
30 - Decimal values are not intended to support floating point values, but rather
31 fixed-point business values such as currency rates and amounts. They are
32 encoded as an octet representing the number of places followed by a long
33 signed integer. The 'decimals' octet is not signed.
34 - Duplicate fields are illegal. The behaviour of a peer with respect to a
35 table containing duplicate fields is undefined.
36
37 """
38
39 FieldValue = (
40 bool
41 | bytes
42 | bytearray
43 | decimal.Decimal
44 | FieldArray
45 | FieldTable
46 | float
47 | int
48 | None
49 | str
50 | datetime.datetime
51 )
52 """Defines valid field values for a :const:`FieldTable` and a
53 :const:`FieldValue`
54
55 """
56
57 Arguments = FieldTable | None
58 """Defines an AMQP method arguments argument data type"""
59
60
61 class Struct:
62 """Simple object for getting to the struct objects for
63 :mod:`pamqp.decode` / :mod:`pamqp.encode`.
64
65 """
66
67 byte = struct.Struct('B')
68 double = struct.Struct('>d')
69 float = struct.Struct('>f')
70 integer = struct.Struct('>I')
71 uint = struct.Struct('>i')
72 long_long_int = struct.Struct('>q')
73 short_short_int = struct.Struct('>b')
74 short_short_uint = struct.Struct('>B')
75 timestamp = struct.Struct('>Q')
76 long = struct.Struct('>l')
77 ulong = struct.Struct('>L')
78 short = struct.Struct('>h')
79 ushort = struct.Struct('>H')