Everything after the header is one object in Python’s marshal format,
always the module’s code object. An object is one type byte followed by whatever that
type needs. Containers hold further objects, each with its own type byte. Every length
and number is little-endian. These releases share nothing between objects: each string
and each object is written in full wherever it is used.
Object types
Types are taken from CPython’s Python/marshal.c at the 3.0.1 and 3.2.6
tags. A .pyc file is written with marshal version 2. In Python 3,
s is a bytes object and u is text.
| Byte | Name | What follows |
|---|---|---|
0 | TYPE_NULL | Nothing. Marks the end of a dictionary |
N | TYPE_NONE | Nothing. The value None |
F | TYPE_FALSE | Nothing. The value False |
T | TYPE_TRUE | Nothing. The value True |
S | TYPE_STOPITER | Nothing. The StopIteration exception |
. | TYPE_ELLIPSIS | Nothing. The value Ellipsis |
i | TYPE_INT | A signed 32-bit integer |
I | TYPE_INT64 | A signed 64-bit integer. Written by a Python whose C long is more than 32 bits wide, when the value needs more than 32 bits |
l | TYPE_LONG | A signed 32-bit count of digits, negative for a negative number, then that many unsigned 16-bit digits in base 32768, lowest digit first. Used for integers too big for the forms above |
f | TYPE_FLOAT | One length byte, then the number written as ASCII text. Only written at marshal version 1 or below, so not in a .pyc file |
g | TYPE_BINARY_FLOAT | An 8-byte little-endian IEEE 754 floating-point number |
x | TYPE_COMPLEX | The real part as one length byte and ASCII text, then the imaginary part the same way. Only written at marshal version 1 or below |
y | TYPE_BINARY_COMPLEX | Two 8-byte little-endian floating-point numbers, real then imaginary |
s | TYPE_STRING | A signed 32-bit length, then that many bytes. A bytes object: the bytecode, the line number table and bytes constants |
u | TYPE_UNICODE | A signed 32-bit length in bytes, then text in UTF-8. Names, identifiers and text constants |
( | TYPE_TUPLE | A signed 32-bit item count, then that many objects |
[ | TYPE_LIST | A signed 32-bit item count, then that many objects |
{ | TYPE_DICT | Key and value objects, in pairs, until a 0 byte where a key would be |
< | TYPE_SET | A signed 32-bit count, then that many objects |
> | TYPE_FROZENSET | A signed 32-bit count, then that many objects |
c | TYPE_CODE | The fields of a code object |
? is TYPE_UNKNOWN. CPython writes it for an object it
cannot marshal and reports an error, and it does not occur in a good file.
Bytes no release here writes
The explorer’s reader is shared by every Python version, so it accepts these type bytes in any file. Python 3.0 to 3.2 do not write them; there is no interned-string scheme in these releases and no back-references. The layouts are those other Pythons use.
| Byte | Name | Meaning here |
|---|---|---|
t | TYPE_INTERNED | A 32-bit length, then the text. Read as text |
R | TYPE_STRINGREF | A 32-bit index into a list of earlier strings |
a | TYPE_ASCII | A 32-bit length, then the text |
A | TYPE_ASCII_INTERNED | Laid out like a |
z | TYPE_SHORT_ASCII | One length byte, then the text |
Z | TYPE_SHORT_ASCII_INTERNED | Laid out like z |
) | TYPE_SMALL_TUPLE | One count byte, then that many objects |
r | TYPE_REF | A 32-bit index of an earlier object that was saved |
: | TYPE_SLICE | Three objects: start, stop and step |