docs: def savedocx(
          document, coreprops, appprops, contenttypes, websettings,
          wordrelationships, output, imagefiledict=None):
      """
      Save a modified document
      """
      if imagefiledict is None:
          warn(
              'Using savedocx() without imagefiledict parameter will be deprec'
              'ated in the future.', PendingDeprecationWarning
          )
  
      assert os.path.isdir(template_dir)
      docxfile = zipfile.ZipFile(
          output, mode='w', compression=zipfile.ZIP_DEFLATED)
  
      # Move to the template data path
      prev_dir = os.path.abspath('.')  # save previous working dir
      os.chdir(template_dir)
  
      # Serialize our trees into out zip file
      treesandfiles = {
          document:          'word/document.xml',
          coreprops:         'docProps/core.xml',
          appprops:          'docProps/app.xml',
          contenttypes:      '[Content_Types].xml',
          websettings:       'word/webSettings.xml',
          wordrelationships: 'word/_rels/document.xml.rels'
      }
      for tree in treesandfiles:
          log.info('Saving: %s' % treesandfiles[tree])
          treestring = etree.tostring(tree, pretty_print=True)
          docxfile.writestr(treesandfiles[tree], treestring)
  
      # Add & compress images, if applicable
      if imagefiledict is not None:
          for imagepath, picrelid in imagefiledict.items():
              archivename = 'word/media/%s_%s' % (picrelid, basename(imagepath))
              log.info('Saving: %s', archivename)
              docxfile.write(imagepath, archivename)
  
      # Add & compress support files
      files_to_ignore = ['.DS_Store']  # nuisance from some os's
      for dirpath, dirnames, filenames in os.walk('.'):
          for filename in filenames:
              if filename in files_to_ignore:
                  continue
              templatefile = join(dirpath, filename)
              archivename = templatefile[2:]
              log.info('Saving: %s', archivename)
              docxfile.write(templatefile, archivename)
  
      log.info('Saved new file to: %r', output)
      docxfile.close()
      os.chdir(prev_dir)  # restore previous working dir
      return