ps-python-pptx 1.1.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 (117) hide show
  1. pptx/__init__.py +84 -0
  2. pptx/action.py +270 -0
  3. pptx/api.py +49 -0
  4. pptx/chart/__init__.py +0 -0
  5. pptx/chart/axis.py +523 -0
  6. pptx/chart/category.py +200 -0
  7. pptx/chart/chart.py +280 -0
  8. pptx/chart/data.py +864 -0
  9. pptx/chart/datalabel.py +288 -0
  10. pptx/chart/legend.py +79 -0
  11. pptx/chart/marker.py +70 -0
  12. pptx/chart/plot.py +412 -0
  13. pptx/chart/point.py +101 -0
  14. pptx/chart/series.py +258 -0
  15. pptx/chart/xlsx.py +272 -0
  16. pptx/chart/xmlwriter.py +1840 -0
  17. pptx/dml/__init__.py +0 -0
  18. pptx/dml/chtfmt.py +40 -0
  19. pptx/dml/color.py +301 -0
  20. pptx/dml/effect.py +41 -0
  21. pptx/dml/fill.py +468 -0
  22. pptx/dml/line.py +100 -0
  23. pptx/enum/__init__.py +0 -0
  24. pptx/enum/action.py +71 -0
  25. pptx/enum/base.py +175 -0
  26. pptx/enum/chart.py +492 -0
  27. pptx/enum/dml.py +405 -0
  28. pptx/enum/lang.py +685 -0
  29. pptx/enum/shapes.py +1029 -0
  30. pptx/enum/text.py +371 -0
  31. pptx/exc.py +23 -0
  32. pptx/media.py +197 -0
  33. pptx/opc/__init__.py +0 -0
  34. pptx/opc/constants.py +331 -0
  35. pptx/opc/oxml.py +188 -0
  36. pptx/opc/package.py +762 -0
  37. pptx/opc/packuri.py +109 -0
  38. pptx/opc/serialized.py +296 -0
  39. pptx/opc/shared.py +20 -0
  40. pptx/opc/spec.py +44 -0
  41. pptx/oxml/__init__.py +492 -0
  42. pptx/oxml/action.py +53 -0
  43. pptx/oxml/chart/__init__.py +0 -0
  44. pptx/oxml/chart/axis.py +297 -0
  45. pptx/oxml/chart/chart.py +282 -0
  46. pptx/oxml/chart/datalabel.py +252 -0
  47. pptx/oxml/chart/legend.py +72 -0
  48. pptx/oxml/chart/marker.py +61 -0
  49. pptx/oxml/chart/plot.py +345 -0
  50. pptx/oxml/chart/series.py +254 -0
  51. pptx/oxml/chart/shared.py +219 -0
  52. pptx/oxml/coreprops.py +288 -0
  53. pptx/oxml/dml/__init__.py +0 -0
  54. pptx/oxml/dml/color.py +111 -0
  55. pptx/oxml/dml/fill.py +197 -0
  56. pptx/oxml/dml/line.py +12 -0
  57. pptx/oxml/ns.py +129 -0
  58. pptx/oxml/presentation.py +130 -0
  59. pptx/oxml/shapes/__init__.py +19 -0
  60. pptx/oxml/shapes/autoshape.py +455 -0
  61. pptx/oxml/shapes/connector.py +107 -0
  62. pptx/oxml/shapes/graphfrm.py +342 -0
  63. pptx/oxml/shapes/groupshape.py +280 -0
  64. pptx/oxml/shapes/picture.py +270 -0
  65. pptx/oxml/shapes/shared.py +523 -0
  66. pptx/oxml/simpletypes.py +740 -0
  67. pptx/oxml/slide.py +347 -0
  68. pptx/oxml/table.py +588 -0
  69. pptx/oxml/text.py +748 -0
  70. pptx/oxml/theme.py +29 -0
  71. pptx/oxml/xmlchemy.py +717 -0
  72. pptx/package.py +222 -0
  73. pptx/parts/__init__.py +0 -0
  74. pptx/parts/chart.py +95 -0
  75. pptx/parts/coreprops.py +167 -0
  76. pptx/parts/embeddedpackage.py +93 -0
  77. pptx/parts/image.py +275 -0
  78. pptx/parts/media.py +37 -0
  79. pptx/parts/presentation.py +126 -0
  80. pptx/parts/slide.py +297 -0
  81. pptx/parts/theme.py +13 -0
  82. pptx/presentation.py +113 -0
  83. pptx/py.typed +0 -0
  84. pptx/shapes/__init__.py +26 -0
  85. pptx/shapes/autoshape.py +355 -0
  86. pptx/shapes/base.py +293 -0
  87. pptx/shapes/connector.py +297 -0
  88. pptx/shapes/freeform.py +337 -0
  89. pptx/shapes/graphfrm.py +166 -0
  90. pptx/shapes/group.py +69 -0
  91. pptx/shapes/picture.py +203 -0
  92. pptx/shapes/placeholder.py +407 -0
  93. pptx/shapes/shapetree.py +1190 -0
  94. pptx/shared.py +82 -0
  95. pptx/slide.py +577 -0
  96. pptx/spec.py +632 -0
  97. pptx/table.py +520 -0
  98. pptx/templates/default.pptx +0 -0
  99. pptx/templates/docx-icon.emf +0 -0
  100. pptx/templates/generic-icon.emf +0 -0
  101. pptx/templates/notes.xml +23 -0
  102. pptx/templates/notesMaster.xml +352 -0
  103. pptx/templates/pptx-icon.emf +0 -0
  104. pptx/templates/theme.xml +321 -0
  105. pptx/templates/xlsx-icon.emf +0 -0
  106. pptx/text/__init__.py +0 -0
  107. pptx/text/fonts.py +399 -0
  108. pptx/text/layout.py +325 -0
  109. pptx/text/text.py +770 -0
  110. pptx/theme.py +135 -0
  111. pptx/types.py +36 -0
  112. pptx/util.py +284 -0
  113. ps_python_pptx-1.1.0.dist-info/METADATA +75 -0
  114. ps_python_pptx-1.1.0.dist-info/RECORD +117 -0
  115. ps_python_pptx-1.1.0.dist-info/WHEEL +5 -0
  116. ps_python_pptx-1.1.0.dist-info/licenses/LICENSE +20 -0
  117. ps_python_pptx-1.1.0.dist-info/top_level.txt +1 -0
pptx/opc/constants.py ADDED
@@ -0,0 +1,331 @@
1
+ """Constant values related to the Open Packaging Convention.
2
+
3
+ In particular, this includes content (MIME) types and relationship types.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+
9
+ class CONTENT_TYPE:
10
+ """Content type URIs (like MIME-types) that specify a part's format."""
11
+
12
+ ASF = "video/x-ms-asf"
13
+ AVI = "video/avi"
14
+ BMP = "image/bmp"
15
+ DML_CHART = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
16
+ DML_CHARTSHAPES = "application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml"
17
+ DML_DIAGRAM_COLORS = "application/vnd.openxmlformats-officedocument.drawingml.diagramColors+xml"
18
+ DML_DIAGRAM_DATA = "application/vnd.openxmlformats-officedocument.drawingml.diagramData+xml"
19
+ DML_DIAGRAM_DRAWING = "application/vnd.ms-office.drawingml.diagramDrawing+xml"
20
+ DML_DIAGRAM_LAYOUT = "application/vnd.openxmlformats-officedocument.drawingml.diagramLayout+xml"
21
+ DML_DIAGRAM_STYLE = "application/vnd.openxmlformats-officedocument.drawingml.diagramStyle+xml"
22
+ GIF = "image/gif"
23
+ INK = "application/inkml+xml"
24
+ JPEG = "image/jpeg"
25
+ MOV = "video/quicktime"
26
+ MP4 = "video/mp4"
27
+ MPG = "video/mpeg"
28
+ MS_PHOTO = "image/vnd.ms-photo"
29
+ MS_VIDEO = "video/msvideo"
30
+ OFC_CHART_COLORS = "application/vnd.ms-office.chartcolorstyle+xml"
31
+ OFC_CHART_EX = "application/vnd.ms-office.chartex+xml"
32
+ OFC_CHART_STYLE = "application/vnd.ms-office.chartstyle+xml"
33
+ OFC_CUSTOM_PROPERTIES = "application/vnd.openxmlformats-officedocument.custom-properties+xml"
34
+ OFC_CUSTOM_XML_PROPERTIES = (
35
+ "application/vnd.openxmlformats-officedocument.customXmlProperties+xml"
36
+ )
37
+ OFC_DRAWING = "application/vnd.openxmlformats-officedocument.drawing+xml"
38
+ OFC_EXTENDED_PROPERTIES = (
39
+ "application/vnd.openxmlformats-officedocument.extended-properties+xml"
40
+ )
41
+ OFC_OLE_OBJECT = "application/vnd.openxmlformats-officedocument.oleObject"
42
+ OFC_PACKAGE = "application/vnd.openxmlformats-officedocument.package"
43
+ OFC_THEME = "application/vnd.openxmlformats-officedocument.theme+xml"
44
+ OFC_THEME_OVERRIDE = "application/vnd.openxmlformats-officedocument.themeOverride+xml"
45
+ OFC_VML_DRAWING = "application/vnd.openxmlformats-officedocument.vmlDrawing"
46
+ OPC_CORE_PROPERTIES = "application/vnd.openxmlformats-package.core-properties+xml"
47
+ OPC_DIGITAL_SIGNATURE_CERTIFICATE = (
48
+ "application/vnd.openxmlformats-package.digital-signature-certificate"
49
+ )
50
+ OPC_DIGITAL_SIGNATURE_ORIGIN = "application/vnd.openxmlformats-package.digital-signature-origin"
51
+ OPC_DIGITAL_SIGNATURE_XMLSIGNATURE = (
52
+ "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"
53
+ )
54
+ OPC_RELATIONSHIPS = "application/vnd.openxmlformats-package.relationships+xml"
55
+ PML_COMMENTS = "application/vnd.openxmlformats-officedocument.presentationml.comments+xml"
56
+ PML_COMMENT_AUTHORS = (
57
+ "application/vnd.openxmlformats-officedocument.presentationml.commentAuthors+xml"
58
+ )
59
+ PML_HANDOUT_MASTER = (
60
+ "application/vnd.openxmlformats-officedocument.presentationml.handoutMaster+xml"
61
+ )
62
+ PML_NOTES_MASTER = (
63
+ "application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml"
64
+ )
65
+ PML_NOTES_SLIDE = "application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml"
66
+ PML_PRESENTATION = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
67
+ PML_PRESENTATION_MAIN = (
68
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"
69
+ )
70
+ PML_PRES_MACRO_MAIN = "application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml"
71
+ PML_PRES_PROPS = "application/vnd.openxmlformats-officedocument.presentationml.presProps+xml"
72
+ PML_PRINTER_SETTINGS = (
73
+ "application/vnd.openxmlformats-officedocument.presentationml.printerSettings"
74
+ )
75
+ PML_SLIDE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml"
76
+ PML_SLIDESHOW_MAIN = (
77
+ "application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml"
78
+ )
79
+ PML_SLIDE_LAYOUT = (
80
+ "application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"
81
+ )
82
+ PML_SLIDE_MASTER = (
83
+ "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"
84
+ )
85
+ PML_SLIDE_UPDATE_INFO = (
86
+ "application/vnd.openxmlformats-officedocument.presentationml.slideUpdateInfo+xml"
87
+ )
88
+ PML_TABLE_STYLES = (
89
+ "application/vnd.openxmlformats-officedocument.presentationml.tableStyles+xml"
90
+ )
91
+ PML_TAGS = "application/vnd.openxmlformats-officedocument.presentationml.tags+xml"
92
+ PML_TEMPLATE_MAIN = (
93
+ "application/vnd.openxmlformats-officedocument.presentationml.template.main+xml"
94
+ )
95
+ PML_VIEW_PROPS = "application/vnd.openxmlformats-officedocument.presentationml.viewProps+xml"
96
+ PNG = "image/png"
97
+ SML_CALC_CHAIN = "application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml"
98
+ SML_CHARTSHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml"
99
+ SML_COMMENTS = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"
100
+ SML_CONNECTIONS = "application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml"
101
+ SML_CUSTOM_PROPERTY = (
102
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.customProperty"
103
+ )
104
+ SML_DIALOGSHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.dialogsheet+xml"
105
+ SML_EXTERNAL_LINK = (
106
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml"
107
+ )
108
+ SML_PIVOT_CACHE_DEFINITION = (
109
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"
110
+ )
111
+ SML_PIVOT_CACHE_RECORDS = (
112
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"
113
+ )
114
+ SML_PIVOT_TABLE = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
115
+ SML_PRINTER_SETTINGS = (
116
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings"
117
+ )
118
+ SML_QUERY_TABLE = "application/vnd.openxmlformats-officedocument.spreadsheetml.queryTable+xml"
119
+ SML_REVISION_HEADERS = (
120
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.revisionHeaders+xml"
121
+ )
122
+ SML_REVISION_LOG = "application/vnd.openxmlformats-officedocument.spreadsheetml.revisionLog+xml"
123
+ SML_SHARED_STRINGS = (
124
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"
125
+ )
126
+ SML_SHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
127
+ SML_SHEET_MAIN = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
128
+ SML_SHEET_METADATA = (
129
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml"
130
+ )
131
+ SML_STYLES = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
132
+ SML_TABLE = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
133
+ SML_TABLE_SINGLE_CELLS = (
134
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml"
135
+ )
136
+ SML_TEMPLATE_MAIN = (
137
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"
138
+ )
139
+ SML_USER_NAMES = "application/vnd.openxmlformats-officedocument.spreadsheetml.userNames+xml"
140
+ SML_VOLATILE_DEPENDENCIES = (
141
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.volatileDependencies+xml"
142
+ )
143
+ SML_WORKSHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
144
+ SWF = "application/x-shockwave-flash"
145
+ TIFF = "image/tiff"
146
+ VIDEO = "video/unknown"
147
+ WML_COMMENTS = "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"
148
+ WML_DOCUMENT = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
149
+ WML_DOCUMENT_GLOSSARY = (
150
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml"
151
+ )
152
+ WML_DOCUMENT_MAIN = (
153
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"
154
+ )
155
+ WML_ENDNOTES = "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"
156
+ WML_FONT_TABLE = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"
157
+ WML_FOOTER = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml"
158
+ WML_FOOTNOTES = "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"
159
+ WML_HEADER = "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml"
160
+ WML_NUMBERING = "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"
161
+ WML_PRINTER_SETTINGS = (
162
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.printerSettings"
163
+ )
164
+ WML_SETTINGS = "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"
165
+ WML_STYLES = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"
166
+ WML_WEB_SETTINGS = (
167
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"
168
+ )
169
+ WMV = "video/x-ms-wmv"
170
+ XML = "application/xml"
171
+ X_EMF = "image/x-emf"
172
+ X_FONTDATA = "application/x-fontdata"
173
+ X_FONT_TTF = "application/x-font-ttf"
174
+ X_MS_VIDEO = "video/x-msvideo"
175
+ X_WMF = "image/x-wmf"
176
+
177
+
178
+ class NAMESPACE:
179
+ """Constant values for OPC XML namespaces"""
180
+
181
+ DML_WORDPROCESSING_DRAWING = (
182
+ "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
183
+ )
184
+ OFC_RELATIONSHIPS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
185
+ OPC_RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships"
186
+ OPC_CONTENT_TYPES = "http://schemas.openxmlformats.org/package/2006/content-types"
187
+ WML_MAIN = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
188
+
189
+
190
+ class RELATIONSHIP_TARGET_MODE:
191
+ """Open XML relationship target modes"""
192
+
193
+ EXTERNAL = "External"
194
+ INTERNAL = "Internal"
195
+
196
+
197
+ class RELATIONSHIP_TYPE:
198
+ AUDIO = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/audio"
199
+ A_F_CHUNK = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk"
200
+ CALC_CHAIN = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain"
201
+ CERTIFICATE = (
202
+ "http://schemas.openxmlformats.org/package/2006/relationships/digital-signatu"
203
+ "re/certificate"
204
+ )
205
+ CHART = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
206
+ CHARTSHEET = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet"
207
+ CHART_COLOR_STYLE = "http://schemas.microsoft.com/office/2011/relationships/chartColorStyle"
208
+ CHART_USER_SHAPES = (
209
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartUserShapes"
210
+ )
211
+ COMMENTS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
212
+ COMMENT_AUTHORS = (
213
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/commentAuthors"
214
+ )
215
+ CONNECTIONS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/connections"
216
+ CONTROL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/control"
217
+ CORE_PROPERTIES = (
218
+ "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
219
+ )
220
+ CUSTOM_PROPERTIES = (
221
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties"
222
+ )
223
+ CUSTOM_PROPERTY = (
224
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customProperty"
225
+ )
226
+ CUSTOM_XML = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml"
227
+ CUSTOM_XML_PROPS = (
228
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps"
229
+ )
230
+ DIAGRAM_COLORS = (
231
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramColors"
232
+ )
233
+ DIAGRAM_DATA = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramData"
234
+ DIAGRAM_LAYOUT = (
235
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramLayout"
236
+ )
237
+ DIAGRAM_QUICK_STYLE = (
238
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramQuickStyle"
239
+ )
240
+ DIALOGSHEET = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/dialogsheet"
241
+ DRAWING = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
242
+ ENDNOTES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes"
243
+ EXTENDED_PROPERTIES = (
244
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
245
+ )
246
+ EXTERNAL_LINK = (
247
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink"
248
+ )
249
+ FONT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/font"
250
+ FONT_TABLE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"
251
+ FOOTER = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"
252
+ FOOTNOTES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"
253
+ GLOSSARY_DOCUMENT = (
254
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument"
255
+ )
256
+ HANDOUT_MASTER = (
257
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/handoutMaster"
258
+ )
259
+ HEADER = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"
260
+ HYPERLINK = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
261
+ IMAGE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
262
+ MEDIA = "http://schemas.microsoft.com/office/2007/relationships/media"
263
+ NOTES_MASTER = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster"
264
+ NOTES_SLIDE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide"
265
+ NUMBERING = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"
266
+ OFFICE_DOCUMENT = (
267
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
268
+ )
269
+ OLE_OBJECT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"
270
+ ORIGIN = "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin"
271
+ PACKAGE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"
272
+ PIVOT_CACHE_DEFINITION = (
273
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCac"
274
+ "heDefinition"
275
+ )
276
+ PIVOT_CACHE_RECORDS = (
277
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/spreadsh"
278
+ "eetml/pivotCacheRecords"
279
+ )
280
+ PIVOT_TABLE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable"
281
+ PRES_PROPS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps"
282
+ PRINTER_SETTINGS = (
283
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings"
284
+ )
285
+ QUERY_TABLE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/queryTable"
286
+ REVISION_HEADERS = (
287
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/revisionHeaders"
288
+ )
289
+ REVISION_LOG = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/revisionLog"
290
+ SETTINGS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"
291
+ SHARED_STRINGS = (
292
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
293
+ )
294
+ SHEET_METADATA = (
295
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sheetMetadata"
296
+ )
297
+ SIGNATURE = (
298
+ "http://schemas.openxmlformats.org/package/2006/relationships/digital-signatu"
299
+ "re/signature"
300
+ )
301
+ SLIDE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide"
302
+ SLIDE_LAYOUT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"
303
+ SLIDE_MASTER = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster"
304
+ SLIDE_UPDATE_INFO = (
305
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideUpdateInfo"
306
+ )
307
+ STYLES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
308
+ TABLE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
309
+ TABLE_SINGLE_CELLS = (
310
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells"
311
+ )
312
+ TABLE_STYLES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles"
313
+ TAGS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags"
314
+ THEME = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"
315
+ THEME_OVERRIDE = (
316
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/themeOverride"
317
+ )
318
+ THUMBNAIL = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail"
319
+ USERNAMES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/usernames"
320
+ VIDEO = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/video"
321
+ VIEW_PROPS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/viewProps"
322
+ VML_DRAWING = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing"
323
+ VOLATILE_DEPENDENCIES = (
324
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/volatile"
325
+ "Dependencies"
326
+ )
327
+ WEB_SETTINGS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"
328
+ WORKSHEET_SOURCE = (
329
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheetSource"
330
+ )
331
+ XML_MAPS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/xmlMaps"
pptx/opc/oxml.py ADDED
@@ -0,0 +1,188 @@
1
+ """OPC-local oxml module to handle OPC-local concerns like relationship parsing."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, Callable, cast
6
+
7
+ from lxml import etree
8
+
9
+ from pptx.opc.constants import NAMESPACE as NS
10
+ from pptx.opc.constants import RELATIONSHIP_TARGET_MODE as RTM
11
+ from pptx.oxml import parse_xml, register_element_cls
12
+ from pptx.oxml.simpletypes import (
13
+ ST_ContentType,
14
+ ST_Extension,
15
+ ST_TargetMode,
16
+ XsdAnyUri,
17
+ XsdId,
18
+ )
19
+ from pptx.oxml.xmlchemy import (
20
+ BaseOxmlElement,
21
+ OptionalAttribute,
22
+ RequiredAttribute,
23
+ ZeroOrMore,
24
+ )
25
+
26
+ if TYPE_CHECKING:
27
+ from pptx.opc.packuri import PackURI
28
+
29
+ nsmap = {
30
+ "ct": NS.OPC_CONTENT_TYPES,
31
+ "pr": NS.OPC_RELATIONSHIPS,
32
+ "r": NS.OFC_RELATIONSHIPS,
33
+ }
34
+
35
+
36
+ def oxml_to_encoded_bytes(
37
+ element: BaseOxmlElement,
38
+ encoding: str = "utf-8",
39
+ pretty_print: bool = False,
40
+ standalone: bool | None = None,
41
+ ) -> bytes:
42
+ return etree.tostring(
43
+ element, encoding=encoding, pretty_print=pretty_print, standalone=standalone
44
+ )
45
+
46
+
47
+ def oxml_tostring(
48
+ elm: BaseOxmlElement,
49
+ encoding: str | None = None,
50
+ pretty_print: bool = False,
51
+ standalone: bool | None = None,
52
+ ):
53
+ return etree.tostring(elm, encoding=encoding, pretty_print=pretty_print, standalone=standalone)
54
+
55
+
56
+ def serialize_part_xml(part_elm: BaseOxmlElement) -> bytes:
57
+ """Produce XML-file bytes for `part_elm`, suitable for writing directly to a `.xml` file.
58
+
59
+ Includes XML-declaration header.
60
+ """
61
+ return etree.tostring(part_elm, encoding="UTF-8", standalone=True)
62
+
63
+
64
+ class CT_Default(BaseOxmlElement):
65
+ """`<Default>` element.
66
+
67
+ Specifies the default content type to be applied to a part with the specified extension.
68
+ """
69
+
70
+ extension: str = RequiredAttribute( # pyright: ignore[reportAssignmentType]
71
+ "Extension", ST_Extension
72
+ )
73
+ contentType: str = RequiredAttribute( # pyright: ignore[reportAssignmentType]
74
+ "ContentType", ST_ContentType
75
+ )
76
+
77
+
78
+ class CT_Override(BaseOxmlElement):
79
+ """`<Override>` element.
80
+
81
+ Specifies the content type to be applied for a part with the specified partname.
82
+ """
83
+
84
+ partName: str = RequiredAttribute( # pyright: ignore[reportAssignmentType]
85
+ "PartName", XsdAnyUri
86
+ )
87
+ contentType: str = RequiredAttribute( # pyright: ignore[reportAssignmentType]
88
+ "ContentType", ST_ContentType
89
+ )
90
+
91
+
92
+ class CT_Relationship(BaseOxmlElement):
93
+ """`<Relationship>` element.
94
+
95
+ Represents a single relationship from a source to a target part.
96
+ """
97
+
98
+ rId: str = RequiredAttribute("Id", XsdId) # pyright: ignore[reportAssignmentType]
99
+ reltype: str = RequiredAttribute("Type", XsdAnyUri) # pyright: ignore[reportAssignmentType]
100
+ target_ref: str = RequiredAttribute( # pyright: ignore[reportAssignmentType]
101
+ "Target", XsdAnyUri
102
+ )
103
+ targetMode: str = OptionalAttribute( # pyright: ignore[reportAssignmentType]
104
+ "TargetMode", ST_TargetMode, default=RTM.INTERNAL
105
+ )
106
+
107
+ @classmethod
108
+ def new(
109
+ cls, rId: str, reltype: str, target_ref: str, target_mode: str = RTM.INTERNAL
110
+ ) -> CT_Relationship:
111
+ """Return a new `<Relationship>` element.
112
+
113
+ `target_ref` is either a partname or a URI.
114
+ """
115
+ relationship = cast(CT_Relationship, parse_xml(f'<Relationship xmlns="{nsmap["pr"]}"/>'))
116
+ relationship.rId = rId
117
+ relationship.reltype = reltype
118
+ relationship.target_ref = target_ref
119
+ relationship.targetMode = target_mode
120
+ return relationship
121
+
122
+
123
+ class CT_Relationships(BaseOxmlElement):
124
+ """`<Relationships>` element, the root element in a .rels file."""
125
+
126
+ relationship_lst: list[CT_Relationship]
127
+ _insert_relationship: Callable[[CT_Relationship], CT_Relationship]
128
+
129
+ relationship = ZeroOrMore("pr:Relationship")
130
+
131
+ def add_rel(
132
+ self, rId: str, reltype: str, target: str, is_external: bool = False
133
+ ) -> CT_Relationship:
134
+ """Add a child `<Relationship>` element with attributes set as specified."""
135
+ target_mode = RTM.EXTERNAL if is_external else RTM.INTERNAL
136
+ relationship = CT_Relationship.new(rId, reltype, target, target_mode)
137
+ return self._insert_relationship(relationship)
138
+
139
+ @classmethod
140
+ def new(cls) -> CT_Relationships:
141
+ """Return a new `<Relationships>` element."""
142
+ return cast(CT_Relationships, parse_xml(f'<Relationships xmlns="{nsmap["pr"]}"/>'))
143
+
144
+ @property
145
+ def xml_file_bytes(self) -> bytes:
146
+ """Return XML bytes, with XML-declaration, for this `<Relationships>` element.
147
+
148
+ Suitable for saving in a .rels stream, not pretty printed and with an XML declaration at
149
+ the top.
150
+ """
151
+ return oxml_to_encoded_bytes(self, encoding="UTF-8", standalone=True)
152
+
153
+
154
+ class CT_Types(BaseOxmlElement):
155
+ """`<Types>` element.
156
+
157
+ The container element for Default and Override elements in [Content_Types].xml.
158
+ """
159
+
160
+ default_lst: list[CT_Default]
161
+ override_lst: list[CT_Override]
162
+
163
+ _add_default: Callable[..., CT_Default]
164
+ _add_override: Callable[..., CT_Override]
165
+
166
+ default = ZeroOrMore("ct:Default")
167
+ override = ZeroOrMore("ct:Override")
168
+
169
+ def add_default(self, ext: str, content_type: str) -> CT_Default:
170
+ """Add a child `<Default>` element with attributes set to parameter values."""
171
+ return self._add_default(extension=ext, contentType=content_type)
172
+
173
+ def add_override(self, partname: PackURI, content_type: str) -> CT_Override:
174
+ """Add a child `<Override>` element with attributes set to parameter values."""
175
+ return self._add_override(partName=partname, contentType=content_type)
176
+
177
+ @classmethod
178
+ def new(cls) -> CT_Types:
179
+ """Return a new `<Types>` element."""
180
+ return cast(CT_Types, parse_xml(f'<Types xmlns="{nsmap["ct"]}"/>'))
181
+
182
+
183
+ register_element_cls("ct:Default", CT_Default)
184
+ register_element_cls("ct:Override", CT_Override)
185
+ register_element_cls("ct:Types", CT_Types)
186
+
187
+ register_element_cls("pr:Relationship", CT_Relationship)
188
+ register_element_cls("pr:Relationships", CT_Relationships)