XML Layer¶
The low-level document layer. Most users never need it; it powers the byte fidelity contract and the CLI tools.
Parse and save .prproj documents with byte fidelity.
Classes¶
PremiereDocument ¶
A parsed .prproj: the element tree plus its gzip framing.
by_object_id / by_object_uid index the top-level object table (direct
children of PremiereData), built once at parse; mutating the tree does
not update them. Inline object definitions nested deeper (the project
view state and its column classes) reuse IDs from their own scope; they
are not indexed and resolve refuses refs located inside them.
Source code in src/py_premiere/xml/document.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
Attributes¶
Methods:¶
__init__ ¶
Source code in src/py_premiere/xml/document.py
add_object ¶
Append a new top-level object under a freshly minted ObjectID.
Source code in src/py_premiere/xml/document.py
attach_object ¶
Append a top-level object that already carries its identifier.
For objects Premiere keys by ObjectUID, and for graphs whose IDs
were allocated up front so their internal refs could be wired before
anything was spliced in.
Source code in src/py_premiere/xml/document.py
from_bytes
classmethod
¶
Source code in src/py_premiere/xml/document.py
next_object_id ¶
The next free integer ObjectID in the top-level object table.
Answered from a high-water mark kept in step by attach_object, so
creating N objects costs N rather than N times the table size.
Source code in src/py_premiere/xml/document.py
owned_objects ¶
Top-level objects reachable from seeds that nothing else needs.
The graph Premiere deletes along with a panel item (master clip,
template clips, source, media, streams...). A shared object - Media
another item still references, say - survives because its external
referrer keeps it out of the set. Pass index to spend one pass over
the tree across several removals instead of one per call.
Source code in src/py_premiere/xml/document.py
payload ¶
Decode a base64 element's payload, following the hash index.
Premiere stores a given binary payload ONCE and writes every further
copy of it as an empty element carrying the same BinaryHash - a
timeline caption's styled text and a Motion Graphics template's
parameter values are both stored that way. An empty copy therefore
has to be resolved through the hash to the populated one.
None when the element holds no payload and no copy of its hash
does either.
Source code in src/py_premiere/xml/document.py
payload_stored ¶
Whether some element already carries this payload's text.
Writers use this to follow Premiere's store-once rule: the first
occurrence of a payload carries the base64 text, every further copy
is an empty element with the same BinaryHash.
Source code in src/py_premiere/xml/document.py
remove_object ¶
Detach a top-level object and drop it from the indexes.
Source code in src/py_premiere/xml/document.py
resolve ¶
Follow an element's ObjectRef/ObjectURef to its target element.
Source code in src/py_premiere/xml/document.py
save ¶
Write the document to path, overwriting it if it exists.
The document layer carries no policy: Project.save is the one that
refuses to overwrite and keeps the project's own path in step.
Source code in src/py_premiere/xml/document.py
to_bytes ¶
ReferenceIndex ¶
Which top-level objects point at which, from one pass over the tree.
A snapshot, deliberately not cached on the document: every edit that adds or drops a reference invalidates it. A caller removing several objects builds one and hands it to each step instead of paying the pass again.
Source code in src/py_premiere/xml/document.py
Attributes¶
Methods:¶
__init__ ¶
Source code in src/py_premiere/xml/document.py
referrers_outside ¶
Ids of the top-level objects still pointing at target.
Source code in src/py_premiere/xml/document.py
Functions:¶
Gzip framing for .prproj files.
Premiere writes a fixed 10-byte gzip header (flags=0, mtime=0, xfl=0; only the OS byte varies by writer) followed by a stock zlib level-6 deflate stream. Reproducing the file byte-for-byte therefore only requires keeping the original header and compressing with zlib defaults. The round-trip test suite is the tripwire for platforms whose zlib emits different bytes. Headers with optional fields (FNAME etc., e.g. a file re-gzipped by CLI tools) are parsed and preserved verbatim.
Attributes¶
Classes¶
GzipFraming ¶
Raw gzip header of a parsed file, re-emitted verbatim on save.
Source code in src/py_premiere/xml/gzip_io.py
Functions:¶
compress_prproj ¶
Frame an XML payload the way Premiere would have written it.
Source code in src/py_premiere/xml/gzip_io.py
decompress_prproj ¶
Return (xml payload, framing); framing is None for uncompressed files.
Source code in src/py_premiere/xml/gzip_io.py
Serializer reproducing Premiere's exact XML output style.
Premiere's writer is uniform: LF line endings, tab indentation, decimal
character references, self-closing empty elements, and a \n\n epilogue
after the root element. Data newlines exist only inside leaf-element text,
stored as / ; every raw LF byte in the file is formatting.
ElementTree collapses both onto \n at parse time, so escaping decisions
below are made from element shape: leaf text is data (entity-escaped),
branch text and tails are formatting (passed through raw, and refused when
non-whitespace - mixed content would make the distinction ambiguous).
These rules are validated two ways: the byte-identity round-trip suite over
the sample corpus, and a parse-time self-check in
PremiereDocument.from_bytes that refuses any file these rules cannot
reproduce byte-for-byte.
Tree-mutation helpers that preserve Premiere's formatting.
New elements copy the whitespace of the sibling they displace, so the serializer reproduces the file's indentation style without any re-formatting pass.
Functions:¶
append_child ¶
Append element as the last child, preserving indentation.
Matches the whitespace of the existing children; for an empty parent the
child indent is derived by deepening the parent's own closing whitespace
by one tab, or from empty_indent when the parent carries no text to
deepen. Works at any nesting depth (nothing is hard-coded), so the
serializer reproduces the layout with no reflow.
Source code in src/py_premiere/xml/mutations.py
append_leaf ¶
Append <tag>text</tag> as the last child, preserving indentation.
append_pair ¶
Append a <Marker><First>..</First><Second ObjectRef=..></Marker> pair.
container is the inner list element (Markers/Markers); the whitespace
of the existing pairs is matched, with the new pair becoming the last.
Source code in src/py_premiere/xml/mutations.py
append_uniform_child ¶
Append element to a container whose children share their spacing.
Works for the top-level object table (root) and any list element
(Items, ...): children are separated by a uniform tail, and only the
last carries the terminal tail before the closing tag. The appended
element takes over that terminal tail; the previous last takes the
inter-child tail - so the serializer reproduces the layout with no
reformatting pass.
Source code in src/py_premiere/xml/mutations.py
build_leaf ¶
Add <tag>text</tag> to a tree that indent_tree will space later.
The counterpart to append_leaf: this one writes no whitespace, because
the builders lay the whole tree out in one pass at the end. Use
append_leaf to add a leaf to a document that is already formatted.
Source code in src/py_premiere/xml/mutations.py
indent_tree ¶
Lay a freshly built tree out the way Premiere writes one.
Every element in a .prproj sits at one tab per nesting level, with no
exceptions, so a whole tree can be spaced in a single pass. An empty
element is written self-closing ONLY when it is a pure reference;
Premiere spells an empty content element out in full.
For trees built from scratch (models/skeleton.py,
models/sequence_builder.py) - the mutation helpers above are the ones
that edit an already-formatted document in place.
Source code in src/py_premiere/xml/mutations.py
insert_before ¶
Insert an already-built element before the anchor_tag child.
The new element takes over the whitespace that preceded the anchor, so the anchor keeps its indentation and nothing reflows.
Source code in src/py_premiere/xml/mutations.py
insert_leaf_before ¶
Insert <tag>text</tag> before the anchor_tag child of parent.
The new element takes over the whitespace that preceded the anchor (the anchor keeps identical leading whitespace through the new element's tail), so indentation is preserved byte-for-byte around the insertion.
Source code in src/py_premiere/xml/mutations.py
remove_child ¶
Remove element from parent, preserving surrounding whitespace.
The removed element's tail (the whitespace before whatever followed it) is handed to the preceding sibling - or to the parent's text when it was the first child - so the layout closes up with no reformatting.
Source code in src/py_premiere/xml/mutations.py
set_elided_flag ¶
Write <tag>text</tag>, or remove it - the shape Premiere elides.
The format stores most booleans only in their non-default state, so
clearing one means deleting the element rather than writing the opposite
value. present is whether the element should be STORED, which for a
field whose default is the written state (a sync lock, say) is the
inverse of the domain value.