当前位置: 首页>>代码示例>>Python>>正文


Python TypeConvertor.pythonDatetime2XSDDatetime方法代码示例

本文整理汇总了Python中netzob.Common.Type.TypeConvertor.TypeConvertor.pythonDatetime2XSDDatetime方法的典型用法代码示例。如果您正苦于以下问题:Python TypeConvertor.pythonDatetime2XSDDatetime方法的具体用法?Python TypeConvertor.pythonDatetime2XSDDatetime怎么用?Python TypeConvertor.pythonDatetime2XSDDatetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在netzob.Common.Type.TypeConvertor.TypeConvertor的用法示例。


在下文中一共展示了TypeConvertor.pythonDatetime2XSDDatetime方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generateXMLConfigFile

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import pythonDatetime2XSDDatetime [as 别名]
    def generateXMLConfigFile(self):
        # Register the namespace
        etree.register_namespace("netzob", PROJECT_NAMESPACE)
        etree.register_namespace("netzob-common", COMMON_NAMESPACE)

        # Dump the file
        root = etree.Element("{" + PROJECT_NAMESPACE + "}project")
        root.set("id", str(self.getID()))
        root.set("path", str(self.getPath()))
        # Warning, changed because of project = Project.createProject(self.netzob.getCurrentWorkspace(), projectName)
        if isinstance(self.getCreationDate(), types.TupleType):
            root.set("creation_date", TypeConvertor.pythonDatetime2XSDDatetime(self.getCreationDate()[0]))
        else:
            root.set("creation_date", TypeConvertor.pythonDatetime2XSDDatetime(self.getCreationDate()))
        root.set("name", str(self.getName()))

        if self.description:
            root.set("description", str(self.description))

        # Save the configuration in it
        self.getConfiguration().save(root, PROJECT_NAMESPACE)

        # Save the vocabulary in it
        self.getVocabulary().save(root, PROJECT_NAMESPACE, COMMON_NAMESPACE)

        # Save the grammar in it
        if self.getGrammar() is not None:
            self.getGrammar().save(root, PROJECT_NAMESPACE)

        # Save the simulator in it
        self.getSimulator().save(root, PROJECT_NAMESPACE)

        return root
开发者ID:otetard,项目名称:netzob,代码行数:35,代码来源:Project.py

示例2: save

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import pythonDatetime2XSDDatetime [as 别名]
    def save(message, xmlMessages, namespace_project, namespace_common):
        root = etree.SubElement(xmlMessages, "{" + namespace_common + "}message")
        root.set("id", str(message.getID()))
        root.set("timestamp", str(message.getTimestamp()))
        root.set("{http://www.w3.org/2001/XMLSchema-instance}type", "netzob-common:FileMessage")
        # data
        subData = etree.SubElement(root, "{" + namespace_common + "}data")
        subData.text = str(message.getData())
        # line number
        subLineNumber = etree.SubElement(root, "{" + namespace_common + "}lineNumber")
        subLineNumber.text = str(message.getLineNumber())
        # filename
        subFilename = etree.SubElement(root, "{" + namespace_common + "}filename")
        subFilename.text = message.getFilename()
        # creationDate
        subCreationDate = etree.SubElement(root, "{" + namespace_common + "}creationDate")
        subCreationDate.text = TypeConvertor.pythonDatetime2XSDDatetime(message.getCreationDate())
        # creationDate
        subModificationDate = etree.SubElement(root, "{" + namespace_common + "}modificationDate")
        subModificationDate.text = TypeConvertor.pythonDatetime2XSDDatetime(message.getModificationDate())

        # owner
        subOwner = etree.SubElement(root, "{" + namespace_common + "}owner")
        subOwner.text = message.getOwner()
        # size
        subSize = etree.SubElement(root, "{" + namespace_common + "}size")
        subSize.text = str(message.getSize())
开发者ID:KurSh,项目名称:netzob,代码行数:29,代码来源:FileMessageFactory.py

示例3: saveConfigFile

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import pythonDatetime2XSDDatetime [as 别名]
    def saveConfigFile(self, overrideTraces=[]):
        """This functions allows to save the current (and only)
        instance of the Workspace. You can supply a list of traces
        that should be written on-disk through the `overrideTraces`
        variable. This allows to override specific traces that where
        modified.

        :param overrideTraces: a list of trace identifiers that should
        be written on-disk, even if they already exists.
        """

        workspaceFile = os.path.join(self.path, Workspace.CONFIGURATION_FILENAME)

        logging.info("Save the config file of the workspace {0} in {1}".format(self.getName(), workspaceFile))

        # Register the namespace
        etree.register_namespace('netzob', WORKSPACE_NAMESPACE)
        etree.register_namespace('netzob-common', COMMON_NAMESPACE)

        # Dump the file
        root = etree.Element("{" + WORKSPACE_NAMESPACE + "}workspace")
        root.set("creation_date", TypeConvertor.pythonDatetime2XSDDatetime(self.getCreationDate()))
        root.set("name", str(self.getName()))

        xmlWorkspaceConfig = etree.SubElement(root, "{" + WORKSPACE_NAMESPACE + "}configuration")

        relTracePath = os.path.relpath(self.getPathOfTraces(), self.path)
        xmlTraces = etree.SubElement(xmlWorkspaceConfig, "{" + WORKSPACE_NAMESPACE + "}traces")
        xmlTraces.text = str(self.getPathOfTraces())

        xmlLogging = etree.SubElement(xmlWorkspaceConfig, "{" + WORKSPACE_NAMESPACE + "}logging")
        xmlLogging.text = str(self.getPathOfLogging())

        xmlPrototypes = etree.SubElement(xmlWorkspaceConfig, "{" + WORKSPACE_NAMESPACE + "}prototypes")
        xmlPrototypes.text = str(self.getPathOfPrototypes())

        xmlPrototypes = etree.SubElement(xmlWorkspaceConfig, "{" + WORKSPACE_NAMESPACE + "}enable_bug_reporting")
        xmlPrototypes.text = str(self.enableBugReporting).lower()

        xmlWorkspaceProjects = etree.SubElement(root, "{" + WORKSPACE_NAMESPACE + "}projects")
        for projectPath in self.getProjectsPath():
            xmlProject = etree.SubElement(xmlWorkspaceProjects, "{" + WORKSPACE_NAMESPACE + "}project")
            xmlProject.set("path", projectPath)

        xmlWorkspaceImported = etree.SubElement(root, "{" + WORKSPACE_NAMESPACE + "}traces")
        for importedTrace in self.getImportedTraces():
            # overrideTraces variable contains the list of
            # ImportedTraces that should be overriden. This is useful
            # in case of message removal for example.
            forceOverride = (importedTrace.id in overrideTraces)

            importedTrace.save(xmlWorkspaceImported, WORKSPACE_NAMESPACE, COMMON_NAMESPACE,
                               os.path.join(self.path, self.getPathOfTraces()), forceOverride)

        xmlWorkspaceFunctions = etree.SubElement(root, "{" + WORKSPACE_NAMESPACE + "}functions")
        for function in self.getCustomFunctions():
            function.save(xmlWorkspaceFunctions, WORKSPACE_NAMESPACE)

        tree = ElementTree(root)
        tree.write(workspaceFile, pretty_print=True)
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:62,代码来源:Workspace.py

示例4: save

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import pythonDatetime2XSDDatetime [as 别名]
    def save(message, xmlMessage, namespace_project, namespace_common):
        xmlMessage.set("{http://www.w3.org/2001/XMLSchema-instance}type", FileMessageFactory.XML_SCHEMA_TYPE)

        # line number
        subLineNumber = etree.SubElement(xmlMessage, "{" + namespace_common + "}lineNumber")
        subLineNumber.text = str(message.getLineNumber())
        # filename
        subFilename = etree.SubElement(xmlMessage, "{" + namespace_common + "}filename")
        subFilename.text = message.getFilename().decode('utf-8')
        # creationDate
        subCreationDate = etree.SubElement(xmlMessage, "{" + namespace_common + "}creationDate")
        subCreationDate.text = TypeConvertor.pythonDatetime2XSDDatetime(message.getCreationDate())
        # creationDate
        subModificationDate = etree.SubElement(xmlMessage, "{" + namespace_common + "}modificationDate")
        subModificationDate.text = TypeConvertor.pythonDatetime2XSDDatetime(message.getModificationDate())

        # owner
        subOwner = etree.SubElement(xmlMessage, "{" + namespace_common + "}owner")
        subOwner.text = message.getOwner()
        # size
        subSize = etree.SubElement(xmlMessage, "{" + namespace_common + "}size")
        subSize.text = str(message.getSize())
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:24,代码来源:FileMessageFactory.py

示例5: save

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import pythonDatetime2XSDDatetime [as 别名]
    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()
开发者ID:KurSh,项目名称:netzob,代码行数:45,代码来源:ImportedTrace.py

示例6: saveConfigFile

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import pythonDatetime2XSDDatetime [as 别名]
    def saveConfigFile(self):
        workspaceFile = os.path.join(self.path, Workspace.CONFIGURATION_FILENAME)

        logging.info("Save the config file of the workspace " + self.getName() + " in " + workspaceFile)

        # Register the namespace
        etree.register_namespace('netzob', WORKSPACE_NAMESPACE)
        etree.register_namespace('netzob-common', COMMON_NAMESPACE)

        # Dump the file
        root = etree.Element("{" + WORKSPACE_NAMESPACE + "}workspace")
        root.set("creation_date", TypeConvertor.pythonDatetime2XSDDatetime(self.getCreationDate()))
        root.set("name", str(self.getName()))

        xmlWorkspaceConfig = etree.SubElement(root, "{" + WORKSPACE_NAMESPACE + "}configuration")

        relTracePath = os.path.relpath(self.getPathOfTraces(), self.path)
        xmlTraces = etree.SubElement(xmlWorkspaceConfig, "{" + WORKSPACE_NAMESPACE + "}traces")
        xmlTraces.text = str(self.getPathOfTraces())

        xmlLogging = etree.SubElement(xmlWorkspaceConfig, "{" + WORKSPACE_NAMESPACE + "}logging")
        xmlLogging.text = str(self.getPathOfLogging())

        xmlPrototypes = etree.SubElement(xmlWorkspaceConfig, "{" + WORKSPACE_NAMESPACE + "}prototypes")
        xmlPrototypes.text = str(self.getPathOfPrototypes())

        xmlWorkspaceProjects = etree.SubElement(root, "{" + WORKSPACE_NAMESPACE + "}projects")
        logging.info("Projects included in workspace.xml :")
        for project in self.getProjects():
            xmlProject = etree.SubElement(xmlWorkspaceProjects, "{" + WORKSPACE_NAMESPACE + "}project")
            xmlProject.set("path", project.getPath())

        xmlWorkspaceImported = etree.SubElement(root, "{" + WORKSPACE_NAMESPACE + "}traces")
        for importedTrace in self.getImportedTraces():
            importedTrace.save(xmlWorkspaceImported, WORKSPACE_NAMESPACE, COMMON_NAMESPACE, os.path.join(self.path, self.getPathOfTraces()))

        tree = ElementTree(root)
        tree.write(workspaceFile)
开发者ID:KurSh,项目名称:netzob,代码行数:40,代码来源:Workspace.py


注:本文中的netzob.Common.Type.TypeConvertor.TypeConvertor.pythonDatetime2XSDDatetime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。