pkgreader
pkgreader
¶
Low-level, read-only API to a serialized Open Packaging Convention (OPC) package.
PackageReader
¶
Provides access to the contents of a zip-format OPC package via its
serialized_parts and pkg_srels attributes.
Source code in src/docx/opc/pkgreader.py
from_file
staticmethod
¶
Return a PackageReader instance loaded with contents of pkg_file.
Source code in src/docx/opc/pkgreader.py
iter_sparts
¶
Generate a 4-tuple (partname, content_type, reltype, blob) for each of the
serialized parts in the package.
iter_srels
¶
Generate a 2-tuple (source_uri, srel) for each of the relationships in the
package.
Source code in src/docx/opc/pkgreader.py
_ContentTypeMap
¶
Value type providing dictionary semantics for looking up content type by part
name, e.g. content_type = cti['/ppt/presentation.xml'].
Source code in src/docx/opc/pkgreader.py
from_xml
staticmethod
¶
Return a new _ContentTypeMap instance populated with the contents of
content_types_xml.
Source code in src/docx/opc/pkgreader.py
_SerializedPart
¶
Value object for an OPC package part.
Provides access to the partname, content type, blob, and serialized relationships for the part.
Source code in src/docx/opc/pkgreader.py
_SerializedRelationship
¶
Value object representing a serialized relationship in an OPC package.
Serialized, in this case, means any target part is referred to via its partname rather than a direct link to an in-memory Part object.
Source code in src/docx/opc/pkgreader.py
rId
property
¶
Relationship id, like 'rId9', corresponds to the Id attribute on the
CT_Relationship element.
target_mode
property
¶
String in TargetMode attribute of CT_Relationship element, one of
RTM.INTERNAL or RTM.EXTERNAL.
target_ref
property
¶
String in Target attribute of CT_Relationship element, a relative
part reference for internal target mode or an arbitrary URI, e.g. an HTTP URL,
for external target mode.
target_partname
property
¶
PackURI instance containing partname targeted by this relationship.
Raises ValueError on reference if target_mode is 'External'. Use
target_mode to check before referencing.
_SerializedRelationships
¶
Read-only sequence of _SerializedRelationship instances corresponding to the relationships item XML passed to constructor.
Source code in src/docx/opc/pkgreader.py
drop
¶
Remove srel from this collection.
Used to discard a relationship whose target part is missing from the package, so the collection never hands out an rId that cannot be resolved to a part.
Source code in src/docx/opc/pkgreader.py
load_from_xml
staticmethod
¶
Return _SerializedRelationships instance loaded with the relationships
contained in rels_item_xml.
Returns an empty collection if rels_item_xml is None.