diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-12-03 18:02:13 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-12-03 18:02:13 +0000 |
| commit | 2cbb7baa6615835b7d4cb81dd2300569c0bafd4a (patch) | |
| tree | 3d59006b1728045eebdfedda13a82461d235e6fb /mammoth/docx | |
| parent | 61bc4fdd82a04da73aa61a5416ac2fa65fb9e237 (diff) | |
Read default content types
Diffstat (limited to 'mammoth/docx')
| -rw-r--r-- | mammoth/docx/content_types_xml.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/mammoth/docx/content_types_xml.py b/mammoth/docx/content_types_xml.py new file mode 100644 index 0000000..a2da8e0 --- /dev/null +++ b/mammoth/docx/content_types_xml.py @@ -0,0 +1,21 @@ +def read_content_types_xml_element(element): + extension_defaults = dict(map( + _read_default, + element.find_children("content-types:Default")) + ) + return ContentTypes(extension_defaults) + + +def _read_default(element): + extension = element.attributes["Extension"] + content_type = element.attributes["ContentType"] + return extension, content_type + + +class ContentTypes(object): + def __init__(self, extension_defaults): + self._extension_defaults = extension_defaults + + def find_content_type(self, path): + extension = path.rpartition(".")[2] + return self._extension_defaults.get(extension) |
