Exemple #1
0
 def write_ext_body(self, xml):
     if self.xml_wrapped:
         try:
             fn = '{}.xml'.format(self.gid)
             self.rel_path = ".{}".format(
                 os.path.join(CommonMethods.get_rel_attachment_dir(), fn))
             fh = codecs.open(os.path.join(self.attachment_directory, fn),
                              "w", "utf-8")
             fh.write(xml)
             fh.close()
         except UnicodeDecodeError as e:
             self.logger.error(e)
         except UnicodeEncodeError as e:
             self.logger.error(e)
Exemple #2
0
 def _build_dedup(self, children):
     """
    :type children : OrderedDict
    :param children:
    :return:
    """
     if CommonMethods.set_ext_hash(self.gid, self.hash):
         chillen = OrderedDict()
         chillen["LocalUniqueID"] = self.gid.__str__()
         for k, v in children.items():
             chillen[k] = str(v).strip("\"")
         chillen["Content"] = self.body_content
         rend = Render("ExternalBodyPart", chillen)
         text = rend.render()
         self.write_ext_body(text)
         self.body_content = None
     else:
         self.gid = CommonMethods.get_ext_gid(self.hash.value)
         self.rel_path = ".{}{}{}{}.xml".format(
             os.sep, CommonMethods.get_rel_attachment_dir(), os.sep,
             self.gid.__str__())
         self.body_content = None
         self.logger.info("Duplicate Attachment: {}".format(
             self.gid.__str__()))