@@ -37,13 +37,26 @@ def __init__(self):
3737 """Establish instance variables with default values"""
3838 self ._content_type = 'application/xml'
3939 self ._extension = 'xml'
40+ self ._indent = 0
4041 self ._namespace = ' xmlns="%s"' % NS .OPC_CONTENT_TYPES
4142
43+ def with_content_type (self , content_type ):
44+ """Set ContentType attribute to *content_type*"""
45+ self ._content_type = content_type
46+ return self
47+
48+ def with_extension (self , extension ):
49+ """Set Extension attribute to *extension*"""
50+ self ._extension = extension
51+ return self
52+
4253 @property
4354 def xml (self ):
4455 """Return Default element"""
45- tmpl = '<Default%s Extension="%s" ContentType="%s"/>\n '
46- return tmpl % (self ._namespace , self ._extension , self ._content_type )
56+ tmpl = '%s<Default%s Extension="%s" ContentType="%s"/>\n '
57+ indent = ' ' * self ._indent
58+ return tmpl % (indent , self ._namespace , self ._extension ,
59+ self ._content_type )
4760
4861
4962class CT_OverrideBuilder (BaseBuilder ):
@@ -111,18 +124,35 @@ class CT_TypesBuilder(BaseBuilder):
111124 """
112125 def __init__ (self ):
113126 """Establish instance variables with default values"""
127+ self ._defaults = (
128+ ('xml' , 'application/xml' ),
129+ ('jpeg' , 'image/jpeg' ),
130+ )
131+ self ._empty = False
114132 self ._overrides = (
115133 ('/docProps/core.xml' , 'app/vnd.type1' ),
116134 ('/ppt/presentation.xml' , 'app/vnd.type2' ),
117135 ('/docProps/thumbnail.jpeg' , 'image/jpeg' ),
118136 )
119137
138+ def empty (self ):
139+ self ._empty = True
140+ return self
141+
120142 @property
121143 def xml (self ):
122144 """
123145 Return XML string based on settings accumulated via method calls
124146 """
147+ if self ._empty :
148+ return '<Types xmlns="%s"/>\n ' % NS .OPC_CONTENT_TYPES
149+
125150 xml = '<Types xmlns="%s">\n ' % NS .OPC_CONTENT_TYPES
151+ for extension , content_type in self ._defaults :
152+ xml += (a_Default ().with_extension (extension )
153+ .with_content_type (content_type )
154+ .with_indent (2 )
155+ .xml )
126156 for partname , content_type in self ._overrides :
127157 xml += (an_Override ().with_partname (partname )
128158 .with_content_type (content_type )
0 commit comments