Example #1
0
 def save(self, root, namespace_project, namespace_common):
     xmlVocabulary = etree.SubElement(root, "{" + namespace_project + "}vocabulary")
     # Messages
     xmlMessages = etree.SubElement(xmlVocabulary, "{" + namespace_project + "}messages")
     for message in self.messages:
         AbstractMessageFactory.save(message, xmlMessages, namespace_project, namespace_common)
     # Symbols
     xmlSymbols = etree.SubElement(xmlVocabulary, "{" + namespace_project + "}symbols")
     for symbol in self.symbols:
         symbol.save(xmlSymbols, namespace_project, namespace_common)
     # Sessions
     xmlSessions = etree.SubElement(xmlVocabulary, "{" + namespace_project + "}sessions")
     for session in self.sessions:
         session.save(xmlSessions, namespace_project, namespace_common)
Example #2
0
    def save(self,
             root,
             namespace_workspace,
             namespace_common,
             pathOfTraces,
             override=False):
        xmlTrace = etree.SubElement(root, "{" + namespace_workspace + "}trace")
        xmlTrace.set(
            "date",
            str(TypeConvertor.pythonDatetime2XSDDatetime(self.getDate())))
        xmlTrace.set("type", str(self.getType()))
        xmlTrace.set("description", str(self.getDescription()))
        xmlTrace.set("name", str(self.getName()))
        xmlTrace.set("id", str(self.getID()))

        # Register the namespace (2 way depending on the version)
        try:
            etree.register_namespace('netzob-common', namespace_common)
        except AttributeError:
            etree._namespace_map[namespace_common] = 'netzob-common'

        # Save the messages
        root = etree.Element("{" + namespace_workspace + "}trace")
        root.set("id", str(self.getID()))
        xmlMessages = etree.SubElement(root,
                                       "{" + namespace_workspace + "}messages")
        for message in self.getMessages():
            AbstractMessageFactory.save(message, xmlMessages,
                                        namespace_workspace, namespace_common)

        # Save the sessions
        xmlSessions = etree.SubElement(root,
                                       "{" + namespace_workspace + "}sessions")
        for session in self.getSessions():
            session.save(xmlSessions, namespace_workspace, namespace_common)

        contentOfFile = str(etree.tostring(root))

        # Creation of the XML File (in buffer)
        # Compress it using gzip and save the .gz
        tracesFile = os.path.join(pathOfTraces, str(self.getID()) + ".gz")
        if not os.path.isfile(tracesFile) or override:
            logging.debug("Save the trace " + str(self.getID()) + " in " +
                          tracesFile)
            # Compress and write the file
            gzipFile = gzip.open(tracesFile, 'wb')
            gzipFile.write(contentOfFile)
            gzipFile.close()
Example #3
0
    def save(self, root, namespace_workspace, namespace_common, pathOfTraces):
        xmlTrace = etree.SubElement(root, "{" + namespace_workspace + "}trace")
        xmlTrace.set("date", str(TypeConvertor.pythonDatetime2XSDDatetime(self.getDate())))
        xmlTrace.set("type", str(self.getType()))
        xmlTrace.set("description", str(self.getDescription()))
        xmlTrace.set("name", str(self.getName()))
        xmlTrace.set("id", str(self.getID()))

        # Creation of the XML File (in buffer)
        # Compress it using gzip and save the .gz
        tracesFile = os.path.join(pathOfTraces, str(self.getID()) + ".gz")
        logging.info("Save the trace " + str(self.getID()) + " in " + tracesFile)

        # Register the namespace (2 way depending on the version)
        try:
            etree.register_namespace('netzob-common', namespace_common)
        except AttributeError:
            etree._namespace_map[namespace_common] = 'netzob-common'

        # Save the messages
        root = etree.Element("{" + namespace_workspace + "}trace")
        root.set("id", str(self.getID()))
        xmlMessages = etree.SubElement(root, "{" + namespace_workspace + "}messages")
        for message in self.getMessages():
            AbstractMessageFactory.save(message, xmlMessages, namespace_workspace, namespace_common)

        # Save the sessions
        xmlSessions = etree.SubElement(root, "{" + namespace_workspace + "}sessions")
        for session in self.getSessions():
            session.save(xmlSessions, namespace_workspace, namespace_common)

        tree = ElementTree(root)
        contentOfFile = str(etree.tostring(tree.getroot()))

        # if outputfile already exists we delete it
        if os.path.isfile(tracesFile):
            logging.debug("The compressed version (" + tracesFile + ") of the file already exists, we replace it with the new one")
            os.remove(tracesFile)

        # Compress and write the file
        gzipFile = gzip.open(tracesFile, 'wb')
        gzipFile.write(contentOfFile)
        gzipFile.close()
Example #4
0
 def save(self, root, namespace_project, namespace_common):
     xmlVocabulary = etree.SubElement(
         root, "{" + namespace_project + "}vocabulary")
     # Messages
     xmlMessages = etree.SubElement(xmlVocabulary,
                                    "{" + namespace_project + "}messages")
     for message in self.messages:
         AbstractMessageFactory.save(message, xmlMessages,
                                     namespace_project, namespace_common)
     # Symbols
     xmlSymbols = etree.SubElement(xmlVocabulary,
                                   "{" + namespace_project + "}symbols")
     for symbol in self.symbols:
         symbol.save(xmlSymbols, namespace_project, namespace_common)
     # Sessions
     xmlSessions = etree.SubElement(xmlVocabulary,
                                    "{" + namespace_project + "}sessions")
     for session in self.sessions:
         session.save(xmlSessions, namespace_project, namespace_common)