Beispiel #1
0
    def loadFromXML(xmlRoot, vocabulary, namespace, version):
        if version == "0.1":
            initialStateID = xmlRoot.get("initialState")
            states = []
            transitions = []

            # Retrieve all the states
            for xmlState in xmlRoot.findall("{" + namespace + "}states/{" +
                                            namespace + "}state"):
                state = AbstractState.loadFromXML(xmlState, namespace, version)
                if state is not None:
                    states.append(state)

            # Retrieve all the transitions
            if xmlRoot.find("{" + namespace + "}transitions") is not None:
                xmlTransitions = xmlRoot.find("{" + namespace + "}transitions")
                for xmlTransition in xmlTransitions.findall("{" + namespace +
                                                            "}transition"):
                    transition = AbstractTransition.loadFromXML(
                        states, vocabulary, xmlTransition, namespace, version)
                    if transition is not None:
                        transitions.append(transition)

            # First we retrieve the initial state to create the grammar
            initialState = None
            for state in states:
                if state.getID() == initialStateID:
                    initialState = state

            if initialState is None:
                logging.warn(
                    "Impossible to retrieve the initial state of the saved grammar"
                )
                return None

            # Creation of the automata
            automata = MMSTD(initialState, vocabulary)

            # Register all the states
            for state in states:
                automata.addState(state)

            for transition in transitions:
                automata.addTransition(transition)

            return automata
Beispiel #2
0
    def loadFromXML(xmlRoot, vocabulary, namespace, version):
        if version == "0.1":
            initialStateID = xmlRoot.get("initialState")
            states = []
            transitions = []

            # Retrieve all the states
            for xmlState in xmlRoot.findall("{" + namespace + "}states/{" + namespace + "}state"):
                state = AbstractState.loadFromXML(xmlState, namespace, version)
                if state is not None:
                    states.append(state)

            # Retrieve all the transitions
            if xmlRoot.find("{" + namespace + "}transitions") is not None:
                xmlTransitions = xmlRoot.find("{" + namespace + "}transitions")
                for xmlTransition in xmlTransitions.findall("{" + namespace + "}transition"):
                    transition = AbstractTransition.loadFromXML(states, vocabulary, xmlTransition, namespace, version)
                    if transition is not None:
                        transitions.append(transition)

            # First we retrieve the initial state to create the grammar
            initialState = None
            for state in states:
                if state.getID() == initialStateID:
                    initialState = state

            if initialState is None:
                logging.warn("Impossible to retrieve the initial state of the saved grammar")
                return None

            # Creation of the automata
            automata = MMSTD(initialState, vocabulary)

            # Register all the states
            for state in states:
                automata.addState(state)

            for transition in transitions:
                automata.addTransition(transition)

            return automata
Beispiel #3
0
 def __init__(self, id, name):
     AbstractState.__init__(self, "StartState", id, name)
     # create logger with the given configuration
     self.log = logging.getLogger(
         'netzob.Common.MMSTD.States.impl.StartState.py')
     self.transitions = []
Beispiel #4
0
 def __init__(self, id, name):
     AbstractState.__init__(self, "StartState", id, name)
     # create logger with the given configuration
     self.log = logging.getLogger('netzob.Common.MMSTD.States.impl.StartState.py')
     self.transitions = []