MCPcopy Index your code
hub / github.com/python-openxml/python-docx / _next_image_partname

Method _next_image_partname

src/docx/package.py:95–110  ·  view source on GitHub ↗

The next available image partname, starting from ``/word/media/image1.{ext}`` where unused numbers are reused. The partname is unique by number, without regard to the extension. `ext` does not include the leading period.

(self, ext: str)

Source from the content-addressed store, hash-verified

93 return None
94
95 def _next_image_partname(self, ext: str) -> PackURI:
96 """The next available image partname, starting from ``/word/media/image1.{ext}``
97 where unused numbers are reused.
98
99 The partname is unique by number, without regard to the extension. `ext` does
100 not include the leading period.
101 """
102
103 def image_partname(n: int) -> PackURI:
104 return PackURI("/word/media/image%d.%s" % (n, ext))
105
106 used_numbers = [image_part.partname.idx for image_part in self]
107 for n in range(1, len(self) + 1):
108 if n not in used_numbers:
109 return image_partname(n)
110 return image_partname(len(self) + 1)

Calls

no outgoing calls