Beispiel #1
0
 def document_name(self):
     name = self.relationships.get(self.namespace.names['DOCUMENT'], None)
     if name is None:
         names = tuple(n for n in self.names if n == 'document.xml' or n.endswith('/document.xml'))
         if not names:
             raise InvalidDOCX('The file %s docx file has no main document' % self.name)
         name = names[0]
     return name
Beispiel #2
0
 def read_content_types(self):
     try:
         raw = self.read('[Content_Types].xml')
     except KeyError:
         raise InvalidDOCX('The file %s docx file has no [Content_Types].xml' % self.name)
     root = fromstring(raw)
     self.content_types = {}
     self.default_content_types = {}
     for item in root.xpath('//*[local-name()="Types"]/*[local-name()="Default" and @Extension and @ContentType]'):
         self.default_content_types[item.get('Extension').lower()] = item.get('ContentType')
     for item in root.xpath('//*[local-name()="Types"]/*[local-name()="Override" and @PartName and @ContentType]'):
         name = item.get('PartName').lstrip('/')
         self.content_types[name] = item.get('ContentType')
Beispiel #3
0
 def read_package_relationships(self):
     try:
         raw = self.read('_rels/.rels')
     except KeyError:
         raise InvalidDOCX('The file %s docx file has no _rels/.rels' % self.name)
     root = fromstring(raw)
     self.relationships = {}
     self.relationships_rmap = {}
     for item in root.xpath('//*[local-name()="Relationships"]/*[local-name()="Relationship" and @Type and @Target]'):
         target = item.get('Target').lstrip('/')
         typ = item.get('Type')
         self.relationships[typ] = target
         self.relationships_rmap[target] = typ
Beispiel #4
0
 def read_package_relationships(self):
     try:
         raw = self.read('_rels/.rels')
     except KeyError:
         raise InvalidDOCX('The file %s docx file has no _rels/.rels' % self.name)
     root = fromstring(raw)
     self.relationships = {}
     self.relationships_rmap = {}
     for item in root.xpath('//*[local-name()="Relationships"]/*[local-name()="Relationship" and @Type and @Target]'):
         target = item.get('Target').lstrip('/')
         typ = item.get('Type')
         if target == 'word/document.xml':
             self.docx_is_transitional = typ != 'http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument'
         self.relationships[typ] = target
         self.relationships_rmap[target] = typ