ps-python-docx 1.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. docx/__init__.py +68 -0
  2. docx/api.py +37 -0
  3. docx/blkcntnr.py +101 -0
  4. docx/comments.py +163 -0
  5. docx/dml/__init__.py +0 -0
  6. docx/dml/color.py +112 -0
  7. docx/document.py +275 -0
  8. docx/drawing/__init__.py +59 -0
  9. docx/enum/__init__.py +0 -0
  10. docx/enum/base.py +150 -0
  11. docx/enum/dml.py +103 -0
  12. docx/enum/section.py +86 -0
  13. docx/enum/shape.py +19 -0
  14. docx/enum/style.py +452 -0
  15. docx/enum/table.py +136 -0
  16. docx/enum/text.py +367 -0
  17. docx/exceptions.py +18 -0
  18. docx/image/__init__.py +23 -0
  19. docx/image/bmp.py +43 -0
  20. docx/image/constants.py +172 -0
  21. docx/image/exceptions.py +13 -0
  22. docx/image/gif.py +38 -0
  23. docx/image/helpers.py +86 -0
  24. docx/image/image.py +234 -0
  25. docx/image/jpeg.py +425 -0
  26. docx/image/png.py +253 -0
  27. docx/image/tiff.py +289 -0
  28. docx/opc/__init__.py +0 -0
  29. docx/opc/constants.py +306 -0
  30. docx/opc/coreprops.py +142 -0
  31. docx/opc/exceptions.py +12 -0
  32. docx/opc/oxml.py +247 -0
  33. docx/opc/package.py +219 -0
  34. docx/opc/packuri.py +109 -0
  35. docx/opc/part.py +247 -0
  36. docx/opc/parts/__init__.py +0 -0
  37. docx/opc/parts/coreprops.py +48 -0
  38. docx/opc/phys_pkg.py +119 -0
  39. docx/opc/pkgreader.py +254 -0
  40. docx/opc/pkgwriter.py +115 -0
  41. docx/opc/rel.py +153 -0
  42. docx/opc/shared.py +31 -0
  43. docx/opc/spec.py +24 -0
  44. docx/oxml/__init__.py +261 -0
  45. docx/oxml/comments.py +124 -0
  46. docx/oxml/coreprops.py +298 -0
  47. docx/oxml/document.py +88 -0
  48. docx/oxml/drawing.py +11 -0
  49. docx/oxml/exceptions.py +10 -0
  50. docx/oxml/ns.py +109 -0
  51. docx/oxml/numbering.py +109 -0
  52. docx/oxml/parser.py +62 -0
  53. docx/oxml/section.py +537 -0
  54. docx/oxml/settings.py +138 -0
  55. docx/oxml/shape.py +299 -0
  56. docx/oxml/shared.py +52 -0
  57. docx/oxml/simpletypes.py +434 -0
  58. docx/oxml/styles.py +341 -0
  59. docx/oxml/table.py +977 -0
  60. docx/oxml/text/__init__.py +0 -0
  61. docx/oxml/text/font.py +333 -0
  62. docx/oxml/text/hyperlink.py +45 -0
  63. docx/oxml/text/pagebreak.py +278 -0
  64. docx/oxml/text/paragraph.py +106 -0
  65. docx/oxml/text/parfmt.py +392 -0
  66. docx/oxml/text/run.py +307 -0
  67. docx/oxml/xmlchemy.py +696 -0
  68. docx/package.py +110 -0
  69. docx/parts/__init__.py +0 -0
  70. docx/parts/comments.py +51 -0
  71. docx/parts/document.py +182 -0
  72. docx/parts/hdrftr.py +53 -0
  73. docx/parts/image.py +80 -0
  74. docx/parts/numbering.py +32 -0
  75. docx/parts/settings.py +50 -0
  76. docx/parts/story.py +95 -0
  77. docx/parts/styles.py +42 -0
  78. docx/parts/theme.py +53 -0
  79. docx/py.typed +0 -0
  80. docx/section.py +479 -0
  81. docx/settings.py +35 -0
  82. docx/shape.py +103 -0
  83. docx/shared.py +382 -0
  84. docx/styles/__init__.py +40 -0
  85. docx/styles/latent.py +198 -0
  86. docx/styles/style.py +264 -0
  87. docx/styles/styles.py +147 -0
  88. docx/table.py +537 -0
  89. docx/templates/default-comments.xml +12 -0
  90. docx/templates/default-docx-template/[Content_Types].xml +17 -0
  91. docx/templates/default-docx-template/_rels/.rels +7 -0
  92. docx/templates/default-docx-template/customXml/_rels/item1.xml.rels +4 -0
  93. docx/templates/default-docx-template/customXml/item1.xml +2 -0
  94. docx/templates/default-docx-template/customXml/itemProps1.xml +6 -0
  95. docx/templates/default-docx-template/docProps/app.xml +36 -0
  96. docx/templates/default-docx-template/docProps/core.xml +13 -0
  97. docx/templates/default-docx-template/docProps/thumbnail.jpeg +0 -0
  98. docx/templates/default-docx-template/word/_rels/document.xml.rels +11 -0
  99. docx/templates/default-docx-template/word/document.xml +11 -0
  100. docx/templates/default-docx-template/word/fontTable.xml +61 -0
  101. docx/templates/default-docx-template/word/numbering.xml +201 -0
  102. docx/templates/default-docx-template/word/settings.xml +53 -0
  103. docx/templates/default-docx-template/word/styles.xml +11844 -0
  104. docx/templates/default-docx-template/word/stylesWithEffects.xml +11800 -0
  105. docx/templates/default-docx-template/word/theme/theme1.xml +318 -0
  106. docx/templates/default-docx-template/word/webSettings.xml +5 -0
  107. docx/templates/default-footer.xml +27 -0
  108. docx/templates/default-header.xml +27 -0
  109. docx/templates/default-settings.xml +26 -0
  110. docx/templates/default-styles.xml +190 -0
  111. docx/templates/default.docx +0 -0
  112. docx/text/__init__.py +0 -0
  113. docx/text/font.py +472 -0
  114. docx/text/hyperlink.py +121 -0
  115. docx/text/pagebreak.py +104 -0
  116. docx/text/paragraph.py +173 -0
  117. docx/text/parfmt.py +286 -0
  118. docx/text/run.py +257 -0
  119. docx/text/tabstops.py +123 -0
  120. docx/theme.py +67 -0
  121. docx/types.py +34 -0
  122. ps_python_docx-1.3.0.dist-info/METADATA +77 -0
  123. ps_python_docx-1.3.0.dist-info/RECORD +126 -0
  124. ps_python_docx-1.3.0.dist-info/WHEEL +5 -0
  125. ps_python_docx-1.3.0.dist-info/licenses/LICENSE +20 -0
  126. ps_python_docx-1.3.0.dist-info/top_level.txt +1 -0
docx/oxml/shape.py ADDED
@@ -0,0 +1,299 @@
1
+ """Custom element classes for shape-related elements like `<w:inline>`."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, cast
6
+
7
+ from docx.oxml.ns import nsdecls
8
+ from docx.oxml.parser import parse_xml
9
+ from docx.oxml.simpletypes import (
10
+ ST_Coordinate,
11
+ ST_DrawingElementId,
12
+ ST_PositiveCoordinate,
13
+ ST_RelationshipId,
14
+ XsdString,
15
+ XsdToken,
16
+ )
17
+ from docx.oxml.xmlchemy import (
18
+ BaseOxmlElement,
19
+ OneAndOnlyOne,
20
+ OptionalAttribute,
21
+ RequiredAttribute,
22
+ ZeroOrOne,
23
+ )
24
+
25
+ if TYPE_CHECKING:
26
+ from docx.shared import Length
27
+
28
+
29
+ class CT_Anchor(BaseOxmlElement):
30
+ """`<wp:anchor>` element, container for a "floating" shape."""
31
+
32
+
33
+ class CT_Blip(BaseOxmlElement):
34
+ """``<a:blip>`` element, specifies image source and adjustments such as alpha and
35
+ tint."""
36
+
37
+ embed: str | None = OptionalAttribute( # pyright: ignore[reportAssignmentType]
38
+ "r:embed", ST_RelationshipId
39
+ )
40
+ link: str | None = OptionalAttribute( # pyright: ignore[reportAssignmentType]
41
+ "r:link", ST_RelationshipId
42
+ )
43
+
44
+
45
+ class CT_BlipFillProperties(BaseOxmlElement):
46
+ """``<pic:blipFill>`` element, specifies picture properties."""
47
+
48
+ blip: CT_Blip = ZeroOrOne( # pyright: ignore[reportAssignmentType]
49
+ "a:blip", successors=("a:srcRect", "a:tile", "a:stretch")
50
+ )
51
+
52
+
53
+ class CT_GraphicalObject(BaseOxmlElement):
54
+ """``<a:graphic>`` element, container for a DrawingML object."""
55
+
56
+ graphicData: CT_GraphicalObjectData = OneAndOnlyOne( # pyright: ignore[reportAssignmentType]
57
+ "a:graphicData"
58
+ )
59
+
60
+
61
+ class CT_GraphicalObjectData(BaseOxmlElement):
62
+ """``<a:graphicData>`` element, container for the XML of a DrawingML object."""
63
+
64
+ pic: CT_Picture = ZeroOrOne("pic:pic") # pyright: ignore[reportAssignmentType]
65
+ uri: str = RequiredAttribute("uri", XsdToken) # pyright: ignore[reportAssignmentType]
66
+
67
+
68
+ class CT_Inline(BaseOxmlElement):
69
+ """`<wp:inline>` element, container for an inline shape."""
70
+
71
+ extent: CT_PositiveSize2D = OneAndOnlyOne("wp:extent") # pyright: ignore[reportAssignmentType]
72
+ docPr: CT_NonVisualDrawingProps = OneAndOnlyOne( # pyright: ignore[reportAssignmentType]
73
+ "wp:docPr"
74
+ )
75
+ graphic: CT_GraphicalObject = OneAndOnlyOne( # pyright: ignore[reportAssignmentType]
76
+ "a:graphic"
77
+ )
78
+
79
+ @classmethod
80
+ def new(cls, cx: Length, cy: Length, shape_id: int, pic: CT_Picture) -> CT_Inline:
81
+ """Return a new ``<wp:inline>`` element populated with the values passed as
82
+ parameters."""
83
+ inline = cast(CT_Inline, parse_xml(cls._inline_xml()))
84
+ inline.extent.cx = cx
85
+ inline.extent.cy = cy
86
+ inline.docPr.id = shape_id
87
+ inline.docPr.name = "Picture %d" % shape_id
88
+ inline.graphic.graphicData.uri = "http://schemas.openxmlformats.org/drawingml/2006/picture"
89
+ inline.graphic.graphicData._insert_pic(pic)
90
+ return inline
91
+
92
+ @classmethod
93
+ def new_pic_inline(
94
+ cls, shape_id: int, rId: str, filename: str, cx: Length, cy: Length
95
+ ) -> CT_Inline:
96
+ """Create `wp:inline` element containing a `pic:pic` element.
97
+
98
+ The contents of the `pic:pic` element is taken from the argument values.
99
+ """
100
+ pic_id = 0 # Word doesn't seem to use this, but does not omit it
101
+ pic = CT_Picture.new(pic_id, filename, rId, cx, cy)
102
+ inline = cls.new(cx, cy, shape_id, pic)
103
+ return inline
104
+
105
+ @classmethod
106
+ def _inline_xml(cls):
107
+ return (
108
+ "<wp:inline %s>\n"
109
+ ' <wp:extent cx="914400" cy="914400"/>\n'
110
+ ' <wp:docPr id="666" name="unnamed"/>\n'
111
+ " <wp:cNvGraphicFramePr>\n"
112
+ ' <a:graphicFrameLocks noChangeAspect="1"/>\n'
113
+ " </wp:cNvGraphicFramePr>\n"
114
+ " <a:graphic>\n"
115
+ ' <a:graphicData uri="URI not set"/>\n'
116
+ " </a:graphic>\n"
117
+ "</wp:inline>" % nsdecls("wp", "a", "pic", "r")
118
+ )
119
+
120
+
121
+ class CT_NonVisualDrawingProps(BaseOxmlElement):
122
+ """Used for ``<wp:docPr>`` element, and perhaps others.
123
+
124
+ Specifies the id and name of a DrawingML drawing.
125
+ """
126
+
127
+ id = RequiredAttribute("id", ST_DrawingElementId)
128
+ name = RequiredAttribute("name", XsdString)
129
+
130
+
131
+ class CT_NonVisualPictureProperties(BaseOxmlElement):
132
+ """``<pic:cNvPicPr>`` element, specifies picture locking and resize behaviors."""
133
+
134
+
135
+ class CT_Picture(BaseOxmlElement):
136
+ """``<pic:pic>`` element, a DrawingML picture."""
137
+
138
+ nvPicPr: CT_PictureNonVisual = OneAndOnlyOne( # pyright: ignore[reportAssignmentType]
139
+ "pic:nvPicPr"
140
+ )
141
+ blipFill: CT_BlipFillProperties = OneAndOnlyOne( # pyright: ignore[reportAssignmentType]
142
+ "pic:blipFill"
143
+ )
144
+ spPr: CT_ShapeProperties = OneAndOnlyOne("pic:spPr") # pyright: ignore[reportAssignmentType]
145
+
146
+ @classmethod
147
+ def new(cls, pic_id: int, filename: str, rId: str, cx: Length, cy: Length) -> CT_Picture:
148
+ """A new minimum viable `<pic:pic>` (picture) element."""
149
+ pic = parse_xml(cls._pic_xml())
150
+ pic.nvPicPr.cNvPr.id = pic_id
151
+ pic.nvPicPr.cNvPr.name = filename
152
+ pic.blipFill.blip.embed = rId
153
+ pic.spPr.cx = cx
154
+ pic.spPr.cy = cy
155
+ return pic
156
+
157
+ @classmethod
158
+ def _pic_xml(cls):
159
+ return (
160
+ "<pic:pic %s>\n"
161
+ " <pic:nvPicPr>\n"
162
+ ' <pic:cNvPr id="666" name="unnamed"/>\n'
163
+ " <pic:cNvPicPr/>\n"
164
+ " </pic:nvPicPr>\n"
165
+ " <pic:blipFill>\n"
166
+ " <a:blip/>\n"
167
+ " <a:stretch>\n"
168
+ " <a:fillRect/>\n"
169
+ " </a:stretch>\n"
170
+ " </pic:blipFill>\n"
171
+ " <pic:spPr>\n"
172
+ " <a:xfrm>\n"
173
+ ' <a:off x="0" y="0"/>\n'
174
+ ' <a:ext cx="914400" cy="914400"/>\n'
175
+ " </a:xfrm>\n"
176
+ ' <a:prstGeom prst="rect"/>\n'
177
+ " </pic:spPr>\n"
178
+ "</pic:pic>" % nsdecls("pic", "a", "r")
179
+ )
180
+
181
+
182
+ class CT_PictureNonVisual(BaseOxmlElement):
183
+ """``<pic:nvPicPr>`` element, non-visual picture properties."""
184
+
185
+ cNvPr = OneAndOnlyOne("pic:cNvPr")
186
+
187
+
188
+ class CT_Point2D(BaseOxmlElement):
189
+ """Used for ``<a:off>`` element, and perhaps others.
190
+
191
+ Specifies an x, y coordinate (point).
192
+ """
193
+
194
+ x = RequiredAttribute("x", ST_Coordinate)
195
+ y = RequiredAttribute("y", ST_Coordinate)
196
+
197
+
198
+ class CT_PositiveSize2D(BaseOxmlElement):
199
+ """Used for ``<wp:extent>`` element, and perhaps others later.
200
+
201
+ Specifies the size of a DrawingML drawing.
202
+ """
203
+
204
+ cx: Length = RequiredAttribute( # pyright: ignore[reportAssignmentType]
205
+ "cx", ST_PositiveCoordinate
206
+ )
207
+ cy: Length = RequiredAttribute( # pyright: ignore[reportAssignmentType]
208
+ "cy", ST_PositiveCoordinate
209
+ )
210
+
211
+
212
+ class CT_PresetGeometry2D(BaseOxmlElement):
213
+ """``<a:prstGeom>`` element, specifies an preset autoshape geometry, such as
214
+ ``rect``."""
215
+
216
+
217
+ class CT_RelativeRect(BaseOxmlElement):
218
+ """``<a:fillRect>`` element, specifying picture should fill containing rectangle
219
+ shape."""
220
+
221
+
222
+ class CT_ShapeProperties(BaseOxmlElement):
223
+ """``<pic:spPr>`` element, specifies size and shape of picture container."""
224
+
225
+ xfrm = ZeroOrOne(
226
+ "a:xfrm",
227
+ successors=(
228
+ "a:custGeom",
229
+ "a:prstGeom",
230
+ "a:ln",
231
+ "a:effectLst",
232
+ "a:effectDag",
233
+ "a:scene3d",
234
+ "a:sp3d",
235
+ "a:extLst",
236
+ ),
237
+ )
238
+
239
+ @property
240
+ def cx(self):
241
+ """Shape width as an instance of Emu, or None if not present."""
242
+ xfrm = self.xfrm
243
+ if xfrm is None:
244
+ return None
245
+ return xfrm.cx
246
+
247
+ @cx.setter
248
+ def cx(self, value):
249
+ xfrm = self.get_or_add_xfrm()
250
+ xfrm.cx = value
251
+
252
+ @property
253
+ def cy(self):
254
+ """Shape height as an instance of Emu, or None if not present."""
255
+ xfrm = self.xfrm
256
+ if xfrm is None:
257
+ return None
258
+ return xfrm.cy
259
+
260
+ @cy.setter
261
+ def cy(self, value):
262
+ xfrm = self.get_or_add_xfrm()
263
+ xfrm.cy = value
264
+
265
+
266
+ class CT_StretchInfoProperties(BaseOxmlElement):
267
+ """``<a:stretch>`` element, specifies how picture should fill its containing
268
+ shape."""
269
+
270
+
271
+ class CT_Transform2D(BaseOxmlElement):
272
+ """``<a:xfrm>`` element, specifies size and shape of picture container."""
273
+
274
+ off = ZeroOrOne("a:off", successors=("a:ext",))
275
+ ext = ZeroOrOne("a:ext", successors=())
276
+
277
+ @property
278
+ def cx(self):
279
+ ext = self.ext
280
+ if ext is None:
281
+ return None
282
+ return ext.cx
283
+
284
+ @cx.setter
285
+ def cx(self, value):
286
+ ext = self.get_or_add_ext()
287
+ ext.cx = value
288
+
289
+ @property
290
+ def cy(self):
291
+ ext = self.ext
292
+ if ext is None:
293
+ return None
294
+ return ext.cy
295
+
296
+ @cy.setter
297
+ def cy(self, value):
298
+ ext = self.get_or_add_ext()
299
+ ext.cy = value
docx/oxml/shared.py ADDED
@@ -0,0 +1,52 @@
1
+ """Objects shared by modules in the docx.oxml subpackage."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import cast
6
+
7
+ from docx.oxml.ns import qn
8
+ from docx.oxml.parser import OxmlElement
9
+ from docx.oxml.simpletypes import ST_DecimalNumber, ST_OnOff, ST_String
10
+ from docx.oxml.xmlchemy import BaseOxmlElement, OptionalAttribute, RequiredAttribute
11
+
12
+
13
+ class CT_DecimalNumber(BaseOxmlElement):
14
+ """Used for ``<w:numId>``, ``<w:ilvl>``, ``<w:abstractNumId>`` and several others,
15
+ containing a text representation of a decimal number (e.g. 42) in its ``val``
16
+ attribute."""
17
+
18
+ val: int = RequiredAttribute("w:val", ST_DecimalNumber) # pyright: ignore[reportAssignmentType]
19
+
20
+ @classmethod
21
+ def new(cls, nsptagname: str, val: int):
22
+ """Return a new ``CT_DecimalNumber`` element having tagname `nsptagname` and
23
+ ``val`` attribute set to `val`."""
24
+ return OxmlElement(nsptagname, attrs={qn("w:val"): str(val)})
25
+
26
+
27
+ class CT_OnOff(BaseOxmlElement):
28
+ """Used for `w:b`, `w:i` elements and others.
29
+
30
+ Contains a bool-ish string in its `val` attribute, xsd:boolean plus "on" and
31
+ "off". Defaults to `True`, so `<w:b>` for example means "bold is turned on".
32
+ """
33
+
34
+ val: bool = OptionalAttribute( # pyright: ignore[reportAssignmentType]
35
+ "w:val", ST_OnOff, default=True
36
+ )
37
+
38
+
39
+ class CT_String(BaseOxmlElement):
40
+ """Used for `w:pStyle` and `w:tblStyle` elements and others.
41
+
42
+ In those cases, it containing a style name in its `val` attribute.
43
+ """
44
+
45
+ val: str = RequiredAttribute("w:val", ST_String) # pyright: ignore[reportAssignmentType]
46
+
47
+ @classmethod
48
+ def new(cls, nsptagname: str, val: str):
49
+ """A new `CT_String`` element with tagname `nsptagname` and `val` attribute set to `val`."""
50
+ elm = cast(CT_String, OxmlElement(nsptagname))
51
+ elm.val = val
52
+ return elm