本文整理汇总了Python中netzob.Common.MMSTD.Dictionary.Variables.AbstractVariable.AbstractVariable类的典型用法代码示例。如果您正苦于以下问题:Python AbstractVariable类的具体用法?Python AbstractVariable怎么用?Python AbstractVariable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractVariable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, _id, name, mutable, learnable, pointedID, symbol):
"""Constructor of AbstractRelationVariable:
@type pointedID: string
@param pointedID: the pointed variable's ID.
"""
AbstractVariable.__init__(self, _id, name, mutable, learnable, False)
self.log = logging.getLogger('netzob.Common.MMSTD.Dictionary.Variable.AbstractRelationVariable.py')
self.pointedID = pointedID
self.symbol = symbol
self.pointedVariable = None
示例2: __init__
def __init__(self, _id, name, mutable, random, children=None):
"""Constructor of AbstractNodeVariable:
@type children: netzob.Common.MMSTD.Dictionary.Variable.AbstractVariable.AbstractVariable List
@param children: the list of this variable's children.
"""
AbstractVariable.__init__(self, _id, name, mutable, random, True)
# create logger with the given configuration
self.log = logging.getLogger('netzob.Common.MMSTD.Dictionary.Variable.AbstractNodeVariable.py')
self.children = []
if children is not None:
self.children.extend(children)
self.learning = False # (read access with mutable flag) Tells if the variable reads normally or through an attempt of learning.
示例3: __init__
def __init__(self, _id, name, mutable, learnable, relationType, pointedID, symbol):
"""Constructor of ComputedRelationVariable:
Mutable and learnable are useless.
@type relationType: string
@param relationType: the type of computation we will use.
"""
AbstractVariable.__init__(self, _id, name, mutable, learnable, False)
self.log = logging.getLogger('netzob.Common.MMSTD.Dictionary.Variable.ComputedRelationVariable.py')
self.relationType = relationType
self.currentValue = None
self.pointedID = pointedID
self.symbol = symbol
self.pointedVariable = None
示例4: loadFromXML
def loadFromXML(xmlRoot, namespace, version, symbol):
"""loadFromXML:
Loads a repeat variable from an XML definition.
We do not trust the user and check every field (even mandatory).
"""
logging.debug("[ RepeatVariable: loadFromXML:")
if version == "0.1":
xmlID = xmlRoot.get("id")
xmlName = xmlRoot.get("name")
xmlMutable = xmlRoot.get("mutable") == "True"
xmlLearnable = xmlRoot.get("learnable") == "True"
xmlChild = xmlRoot.find("{" + namespace + "}variable")
child = AbstractVariable.loadFromXML(xmlChild, namespace, version, symbol)
# minIterations
xmlMinIterations = xmlRoot.find("{" + namespace + "}minIterations")
if xmlMinIterations is not None:
minIterations = int(xmlMinIterations.text)
else:
minIterations = 0
# maxIterations
xmlMaxIterations = xmlRoot.find("{" + namespace + "}maxIterations")
if xmlMaxIterations is not None:
maxIterations = int(xmlMaxIterations.text)
else:
maxIterations = RepeatVariable.MAX_ITERATIONS
result = RepeatVariable(xmlID, xmlName, xmlMutable, xmlLearnable, child, minIterations, maxIterations)
logging.debug("RepeatVariable: loadFromXML successes: {0} ]".format(result.toString()))
return result
logging.debug("RepeatVariable: loadFromXML fails")
return None
示例5: writeChildren
def writeChildren(self, writingToken):
"""write:
Each child tries to write its value..
If it fails, it restore it value and the next child try.
It stops if one child successes.
"""
self.log.debug("[ {0} (Alternate): writeChildren:".format(AbstractVariable.toString(self)))
savedValue = writingToken.getValue()
savedIndex = writingToken.getIndex()
for child in self.getChildren():
# Memorized values for the child and its successor.
dictOfValues = dict()
dictOfValue = child.getDictOfValues(writingToken)
for key, val in dictOfValue.iteritems():
dictOfValues[key] = val
child.write(writingToken)
if writingToken.isOk() and writingToken.getValue() is not None:
break
else:
writingToken.setValue(savedValue)
# We restore values for the child and its successor.
child.restore(writingToken)
vocabulary = writingToken.getVocabulary()
for key, val in dictOfValues.iteritems():
vocabulary.getVariableByID(key).setCurrentValue(val)
if writingToken.isOk():
# The value of the variable is simply the value we made.
self.currentValue = writingToken.getValue()[savedIndex:writingToken.getIndex()]
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), writingToken.toString()))
示例6: toString
def toString(self):
"""toString:
"""
lgth = 0
if self.children is not None:
lgth = len(self.children)
return _("[Alternate] {0} ({1})").format(AbstractVariable.toString(self), str(lgth))
示例7: write
def write(self, writingToken):
"""write:
Each child tries sequentially to write its value.
If one of them fails, the whole operation is cancelled.
"""
self.log.debug("[ {0} (Aggregate): write access:".format(AbstractVariable.toString(self)))
self.resetTokenChoppedIndexes() # New write access => new final value and new reference to it.
if self.getChildren() is not None:
if self.isMutable():
# mutable.
self.shuffleChildren()
self.writeChildren(writingToken)
else:
# not mutable.
self.writeChildren(writingToken)
else:
# no child.
self.log.debug("Write abort: the variable has no child.")
writingToken.setOk(False)
# Variable notification
if writingToken.isOk():
self.notifyBoundedVariables("write", writingToken)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), writingToken.toString()))
示例8: toString
def toString(self):
"""toString:
"""
lgth = 0
if self.getChildren() is not None:
lgth = len(self.getChildren())
return _("[Aggregate] {0} ({1})").format(AbstractVariable.toString(self), str(lgth))
示例9: read
def read(self, readingToken):
"""read:
Each child tries sequentially to read a part of the read value.
If one of them fails, the whole operation is cancelled.
"""
self.log.debug("[ {0} (Aggregate): read access:".format(AbstractVariable.toString(self)))
if self.getChildren() is not None:
if self.isMutable():
# mutable.
self.sortChildrenToRead(readingToken)
self.readChildren(readingToken)
else:
# not mutable.
self.readChildren(readingToken)
else:
# no child.
self.log.debug("Write abort: the variable has no child.")
readingToken.setOk(False)
# Variable notification
if readingToken.isOk():
self.notifyBoundedVariables("read", readingToken, self.currentValue)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), readingToken.toString()))
示例10: notifiedWrite
def notifiedWrite(self, writingToken):
"""notify:
A write access called by a notification of the pointed variable (when it has finished its own treatment).
It updates the values this variable has written in the writingToken value.
@type writingToken: netzob.Common.MMSTD.Dictionary.VariableProcessingToken.VariableWritingToken.VariableWritingToken
@param writingToken: a token which contains all critical information on this access.
"""
self.log.debug("[ {0} (relation): notifiedWrite access:".format(AbstractVariable.toString(self)))
if self.isDefined(writingToken):
# Compute the value
self.retrieveValue(writingToken)
# replace the new value in the writing token
writingToken.setValueForVariable(self, self.currentValue)
else:
self.log.debug("Write abort: the variable is neither defined, nor random.")
writingToken.setOk(False)
# Variable notification
if writingToken.isOk():
self.notifyBoundedVariables("write", writingToken)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), writingToken.toString()))
示例11: write
def write(self, writingToken):
"""write:
The relation variable returns a computed or a generated value.
"""
self.log.debug("[ {0} (relation): write access:".format(AbstractVariable.toString(self)))
self.directPointer = self.findDirectPointer()
if self.isDefined(writingToken):
if not self.directPointer:
# We will write the real value at notification time. (An awaiting value is written though.)
self.bindValue(writingToken)
self.guessValue()
else:
# We directly retrieve and write the actual value (which would be deprecated and replaced if the variable is directPointer).
self.retrieveValue(writingToken)
self.writeValue(writingToken)
else:
self.log.debug("Write abort: the variable is not defined.")
writingToken.setOk(False)
# Variable notification
if writingToken.isOk():
self.notifyBoundedVariables("write", writingToken)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), writingToken.toString()))
示例12: notifiedRead
def notifiedRead(self, readingToken, pointedValue):
"""notifiedRead:
A read access called by a notification of the pointed variable (when it has finished its own treatment).
It checks that the new value complies with the reading token value at this very position.
@type readingToken: netzob.Common.MMSTD.Dictionary.VariableProcessingToken.VariableReadingToken.VariableReadingToken
@param readingToken: a token which contains all critical information on this access.
"""
self.log.debug("[ {0} (relation): read access:".format(AbstractVariable.toString(self)))
if self.isDefined(readingToken):
for linkedValue in readingToken.getLinkedValue():
if linkedValue[0] == self.getID():
# We compare the pointed value to the value the current variable wrote in memory.
if linkedValue[1] != self.computeValue(pointedValue):
readingToken.setOk(False)
break
else:
self.log.debug("Read abort: the variable is neither defined, nor mutable.")
readingToken.setOk(False)
# Variable notification
if readingToken.isOk():
self.notifyBoundedVariables("read", readingToken, pointedValue)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), readingToken.toString()))
示例13: read
def read(self, readingToken):
"""read:
The relation variable tries to compare/learn the read value.
"""
self.log.debug("[ {0} (relation): read access:".format(AbstractVariable.toString(self)))
self.directPointer = self.findDirectPointer()
if self.isDefined(readingToken):
if self.directPointer:
# We directly retrieve and compare the value.
self.retrieveValue(readingToken)
self.compare(readingToken)
else:
# We make a small format comparison.
self.compareFormat(readingToken)
# We will verify the value at notification time.
self.bindValue(readingToken)
else:
self.log.debug("Read abort: the variable is not defined.")
readingToken.setOk(False)
# Variable notification
if readingToken.isOk():
self.notifyBoundedVariables("read", readingToken, self.currentValue)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), readingToken.toString()))
示例14: write
def write(self, writingToken):
"""write:
The leaf element returns its value or a generated one.
"""
self.log.debug("[ {0} (leaf): write access:".format(AbstractVariable.toString(self)))
self.resetTokenChoppedIndexes() # New write access => new final value and new reference to it.
if self.isMutable():
if self.isLearnable():
if self.isDefined(writingToken):
# mutable, learnable and defined.
self.mutate(writingToken)
self.writeValue(writingToken)
else:
# mutable, learnable and not defined.
self.generate(writingToken)
self.memorize(writingToken)
self.writeValue(writingToken)
else:
if self.isDefined(writingToken):
# mutable, not learnable, defined.
self.generate(writingToken)
self.writeValue(writingToken)
else:
# mutable, not learnable, not defined.
self.generate(writingToken)
self.writeValue(writingToken)
else:
if self.isLearnable():
if self.isDefined(writingToken):
# not mutable, learnable and defined.
self.writeValue(writingToken)
else:
# not mutable, learnable and not defined.
self.generate(writingToken)
self.memorize(writingToken)
self.writeValue(writingToken)
else:
if self.isDefined(writingToken):
# not mutable, not learnable and defined.
self.writeValue(writingToken)
else:
# not mutable, not learnable and not defined.
self.log.debug("Write abort: the variable is neither defined, nor mutable.")
writingToken.setOk(False)
# Variable notification
if writingToken.isOk():
self.notifyBoundedVariables("write", writingToken)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), writingToken.toString()))
示例15: read
def read(self, readingToken):
"""read:
The leaf element tries to compare/learn the read value.
"""
self.log.debug("[ {0} (leaf): read access:".format(AbstractVariable.toString(self)))
if self.isMutable():
if self.isLearnable():
if self.isDefined(readingToken):
# mutable, learnable and defined.
self.forget(readingToken)
self.compareFormat(readingToken)
self.learn(readingToken)
self.memorize(readingToken)
else:
# mutable, learnable and not defined.
self.compareFormat(readingToken)
self.learn(readingToken)
self.memorize(readingToken)
else:
if self.isDefined(readingToken):
# mutable, not learnable and defined.
self.compareFormat(readingToken)
else:
# mutable, learnable and not defined.
self.compareFormat(readingToken)
else:
if self.isLearnable():
if self.isDefined(readingToken):
# not mutable, learnable and defined.
self.compare(readingToken)
else:
# not mutable, learnable and not defined.
self.compareFormat(readingToken)
self.learn(readingToken)
self.memorize(readingToken)
else:
if self.isDefined(readingToken):
# not mutable, not learnable and defined.
self.compare(readingToken)
else:
# not mutable, not learnable and not defined.
self.log.debug("Read abort: the variable is neither defined, nor mutable.")
readingToken.setOk(False)
# Variable notification
if readingToken.isOk():
self.notifyBoundedVariables("read", readingToken, self.getValue(readingToken))
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), readingToken.toString()))