File tree 3 files changed +38
-0
lines changed
3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,22 @@ class CT_Types(OxmlBaseElement):
180
180
``<Types>`` element, the container element for Default and Override
181
181
elements in [Content_Types].xml.
182
182
"""
183
+ def add_default (self , ext , content_type ):
184
+ """
185
+ Add a child ``<Default>`` element with attributes set to parameter
186
+ values.
187
+ """
188
+ default = CT_Default .new (ext , content_type )
189
+ self .append (default )
190
+
191
+ def add_override (self , partname , content_type ):
192
+ """
193
+ Add a child ``<Override>`` element with attributes set to parameter
194
+ values.
195
+ """
196
+ override = CT_Override .new (partname , content_type )
197
+ self .append (override )
198
+
183
199
@property
184
200
def defaults (self ):
185
201
try :
Original file line number Diff line number Diff line change @@ -74,3 +74,13 @@ def it_can_construct_a_new_types_element(self):
74
74
types = CT_Types .new ()
75
75
expected_xml = a_Types ().empty ().xml
76
76
assert types .xml == expected_xml
77
+
78
+ def it_can_build_types_element_incrementally (self ):
79
+ types = CT_Types .new ()
80
+ types .add_default ('.xml' , 'application/xml' )
81
+ types .add_default ('.jpeg' , 'image/jpeg' )
82
+ types .add_override ('/docProps/core.xml' , 'app/vnd.type1' )
83
+ types .add_override ('/ppt/presentation.xml' , 'app/vnd.type2' )
84
+ types .add_override ('/docProps/thumbnail.jpeg' , 'image/jpeg' )
85
+ expected_types_xml = a_Types ().xml
86
+ assert types .xml == expected_types_xml
Original file line number Diff line number Diff line change @@ -50,6 +50,11 @@ def with_extension(self, extension):
50
50
self ._extension = extension
51
51
return self
52
52
53
+ def without_namespace (self ):
54
+ """Don't include an 'xmlns=' attribute"""
55
+ self ._namespace = ''
56
+ return self
57
+
53
58
@property
54
59
def xml (self ):
55
60
"""Return Default element"""
@@ -81,6 +86,11 @@ def with_partname(self, partname):
81
86
self ._partname = partname
82
87
return self
83
88
89
+ def without_namespace (self ):
90
+ """Don't include an 'xmlns=' attribute"""
91
+ self ._namespace = ''
92
+ return self
93
+
84
94
@property
85
95
def xml (self ):
86
96
"""Return Override element"""
@@ -152,11 +162,13 @@ def xml(self):
152
162
xml += (a_Default ().with_extension (extension )
153
163
.with_content_type (content_type )
154
164
.with_indent (2 )
165
+ .without_namespace ()
155
166
.xml )
156
167
for partname , content_type in self ._overrides :
157
168
xml += (an_Override ().with_partname (partname )
158
169
.with_content_type (content_type )
159
170
.with_indent (2 )
171
+ .without_namespace ()
160
172
.xml )
161
173
xml += '</Types>\n '
162
174
return xml
You can’t perform that action at this time.
0 commit comments