コード例 #1
0
 def save(self, target=None, packaging=None):
     """Save the container to the given URI (target) or into this file like
     object (if supported).
     """
     parts = self.__parts
     # Get all parts
     for part in self.get_contents():
         if part not in parts:
             self.get_part(part)
     # Packaging
     if packaging is None:
         packaging = ('flat' if self.mimetype == 'application/xml' else
                      'zip')
     # Get data
     if packaging == 'flat':
         data = self.__make_xml()
     elif packaging == 'zip':
         data = self.__make_zip()
     else:
         raise ValueError, '"%s" packaging type not supported' % packaging
     # Save it
     if target is None:
         container = vfs.open(self.uri, WRITE)
     elif isinstance(target, str):
         container = vfs.open(target, WRITE)
     else:
         container = target
     container.write(data)
コード例 #2
0
 def __get_data(self):
     """Store bytes of the ODF in memory.
     """
     if self.__data is None:
         file = vfs.open(self.uri)
         self.__data = file.read()
         file.close()
     return self.__data
コード例 #3
0
 def add_file(self, uri_or_file):
     if type(uri_or_file) is unicode or type(uri_or_file) is str:
         uri_or_file = uri_or_file.encode('utf_8')
         file = vfs.open(uri_or_file)
     else:
         file = uri_or_file
     name = 'Pictures/%s' % uuid4()
     data= file.read()
     self.container.set_part(name, data)
     return name