MCPcopy Create free account
hub / github.com/scanny/python-pptx / factory

Method factory

src/pptx/parts/embeddedpackage.py:25–48  ·  view source on GitHub ↗

Return a new |EmbeddedPackagePart| subclass instance added to *package*. The subclass is determined by `prog_id` which corresponds to the "application" used to open the "file-type" of `object_blob`. The returned part contains the bytes of `object_blob` and has the content-ty

(cls, prog_id: PROG_ID | str, object_blob: bytes, package: Package)

Source from the content-addressed store, hash-verified

23
24 @classmethod
25 def factory(cls, prog_id: PROG_ID | str, object_blob: bytes, package: Package):
26 """Return a new |EmbeddedPackagePart| subclass instance added to *package*.
27
28 The subclass is determined by `prog_id` which corresponds to the "application"
29 used to open the "file-type" of `object_blob`. The returned part contains the
30 bytes of `object_blob` and has the content-type also determined by `prog_id`.
31 """
32 # --- a generic OLE object has no subclass ---
33 if not isinstance(prog_id, PROG_ID):
34 return cls(
35 package.next_partname("/ppt/embeddings/oleObject%d.bin"),
36 CT.OFC_OLE_OBJECT,
37 package,
38 object_blob,
39 )
40
41 # --- A Microsoft Office file-type is a distinguished package object ---
42 EmbeddedPartCls = {
43 PROG_ID.DOCX: EmbeddedDocxPart,
44 PROG_ID.PPTX: EmbeddedPptxPart,
45 PROG_ID.XLSX: EmbeddedXlsxPart,
46 }[prog_id]
47
48 return EmbeddedPartCls.new(object_blob, package)
49
50 @classmethod
51 def new(cls, blob: bytes, package: Package):

Callers 1

Calls 2

next_partnameMethod · 0.80
newMethod · 0.45

Tested by

no test coverage detected