Exemplo n.º 1
0
    def __init__(self, obj):
        self.isPCRE = False
        self.compiledValue = None

        if isinstance(obj, str) or isinstance(obj, unicode):
            self.value = str(obj)

            # Support the short form using forward slashes to indicate a PCRE
            if self.value.startswith("/") and self.value.endswith("/"):
                self.isPCRE = True
                self.value = self.value[1:-1]
                try:
                    self.compiledValue = re.compile(self.value)
                except re.error as e:
                    raise RuntimeError("Error in regular expression: %s" % e)
        else:
            self.value = JSONHelper.getStringChecked(obj, "value", True)

            matchType = JSONHelper.getStringChecked(obj, "matchType", False)
            if matchType != None:
                if matchType.lower() == "contains":
                    pass
                elif matchType.lower() == "pcre":
                    self.isPCRE = True
                    try:
                        self.compiledValue = re.compile(self.value)
                    except re.error as e:
                        raise RuntimeError("Error in regular expression: %s" % e)
                else:
                    raise RuntimeError("Unknown match operator specified: %s" % matchType)
Exemplo n.º 2
0
    def __init__(self, obj):
        self.isPCRE = False
        self.compiledValue = None

        if isinstance(obj, str) or isinstance(obj, unicode):
            self.value = str(obj)

            # Support the short form using forward slashes to indicate a PCRE
            if self.value.startswith("/") and self.value.endswith("/"):
                self.isPCRE = True
                self.value = self.value[1:-1]
                self.compiledValue = re.compile(self.value)
        else:
            self.value = JSONHelper.getStringChecked(obj, "value", True)

            matchType = JSONHelper.getStringChecked(obj, "matchType", False)
            if matchType != None:
                if matchType.lower() == "contains":
                    pass
                elif matchType.lower() == "pcre":
                    self.isPCRE = True
                    self.compiledValue = re.compile(self.value)
                else:
                    raise RuntimeError("Unknown match operator specified: %s" %
                                       matchType)
Exemplo n.º 3
0
    def __init__(self, obj):
        self.isPCRE = False
        self.compiledValue = None

        if isinstance(obj, bytes):
            obj = obj.decode("utf-8")

        if isinstance(obj, six.text_type):
            self.value = obj

            # Support the short form using forward slashes to indicate a PCRE
            if self.value.startswith("/") and self.value.endswith("/"):
                self.isPCRE = True
                self.value = self.value[1:-1]
                try:
                    self.compiledValue = re.compile(self.value)
                except re.error as e:
                    raise RuntimeError("Error in regular expression: %s" % e)
        else:
            self.value = JSONHelper.getStringChecked(obj, "value", True)

            matchType = JSONHelper.getStringChecked(obj, "matchType", False)
            if matchType is not None:
                if matchType.lower() == "contains":
                    pass
                elif matchType.lower() == "pcre":
                    self.isPCRE = True
                    try:
                        self.compiledValue = re.compile(self.value)
                    except re.error as e:
                        raise RuntimeError("Error in regular expression: %s" %
                                           e)
                else:
                    raise RuntimeError("Unknown match operator specified: %s" %
                                       matchType)
Exemplo n.º 4
0
 def __init__(self, obj):
     '''
     Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
     '''
     Symptom.__init__(self, obj)
     self.output = StringMatch(JSONHelper.getObjectOrStringChecked(obj, "value", True))
     self.src = JSONHelper.getStringChecked(obj, "src")
     
     if self.src != None:
         self.src = self.src.lower()
         if self.src != "stderr" and self.src != "stdout" and self.src != "crashdata":
             raise RuntimeError("Invalid source specified: %s" % self.src)
Exemplo n.º 5
0
    def __init__(self, obj):
        '''
        Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
        '''
        Symptom.__init__(self, obj)
        self.output = StringMatch(JSONHelper.getObjectOrStringChecked(obj, "value", True))
        self.src = JSONHelper.getStringChecked(obj, "src")

        if self.src != None:
            self.src = self.src.lower()
            if self.src != "stderr" and self.src != "stdout" and self.src != "crashdata":
                raise RuntimeError("Invalid source specified: %s" % self.src)
Exemplo n.º 6
0
 def __init__(self, obj):
     '''
     Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
     '''
     Symptom.__init__(self, obj)
     self.registerNames = JSONHelper.getArrayChecked(obj, "registerNames")
     self.instructionName = JSONHelper.getObjectOrStringChecked(obj, "instructionName")
     
     if self.instructionName != None:
         self.instructionName = StringMatch(self.instructionName)
     elif self.registerNames == None or len(self.registerNames) == 0:
         raise RuntimeError("Must provide at least instruction name or register names")
Exemplo n.º 7
0
    def __init__(self, obj):
        '''
        Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
        '''
        Symptom.__init__(self, obj)
        self.registerNames = JSONHelper.getArrayChecked(obj, "registerNames")
        self.instructionName = JSONHelper.getObjectOrStringChecked(obj, "instructionName")

        if self.instructionName != None:
            self.instructionName = StringMatch(self.instructionName)
        elif self.registerNames == None or len(self.registerNames) == 0:
            raise RuntimeError("Must provide at least instruction name or register names")
Exemplo n.º 8
0
    def __init__(self, obj):
        '''
        Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
        '''
        Symptom.__init__(self, obj)
        self.functionName = StringMatch(JSONHelper.getNumberOrStringChecked(obj, "functionName", True))        
        self.frameNumber = JSONHelper.getNumberOrStringChecked(obj, "frameNumber")

        if self.frameNumber != None:
            self.frameNumber = NumberMatch(self.frameNumber)
        else:
            # Default to 0
            self.frameNumber = NumberMatch(0)
Exemplo n.º 9
0
    def __init__(self, obj):
        '''
        Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
        '''
        Symptom.__init__(self, obj)
        self.functionName = StringMatch(JSONHelper.getNumberOrStringChecked(obj, "functionName", True))
        self.frameNumber = JSONHelper.getNumberOrStringChecked(obj, "frameNumber")

        if self.frameNumber != None:
            self.frameNumber = NumberMatch(self.frameNumber)
        else:
            # Default to 0
            self.frameNumber = NumberMatch(0)
Exemplo n.º 10
0
 def __init__(self, obj):
     '''
     Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
     '''
     Symptom.__init__(self, obj)
     self.output = StringMatch(
         JSONHelper.getObjectOrStringChecked(obj, "value", True))
Exemplo n.º 11
0
 def __init__(self, obj):
     '''
     Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
     '''
     Symptom.__init__(self, obj)
     self.address = NumberMatch(
         JSONHelper.getNumberOrStringChecked(obj, "address", True))
Exemplo n.º 12
0
 def __init__(self, obj):
     '''
     Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
     '''
     Symptom.__init__(self, obj)
     self.functionNames = []
     
     rawFunctionNames = JSONHelper.getArrayChecked(obj, "functionNames", True)
     
     for fn in rawFunctionNames:
         self.functionNames.append(StringMatch(fn))
Exemplo n.º 13
0
    def __init__(self, obj):
        '''
        Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
        '''
        Symptom.__init__(self, obj)
        self.functionNames = []

        rawFunctionNames = JSONHelper.getArrayChecked(obj, "functionNames", True)

        for fn in rawFunctionNames:
            self.functionNames.append(StringMatch(fn))
Exemplo n.º 14
0
class CrashSignature():
    def __init__(self, rawSignature):
        '''
        Constructor
        
        @type rawSignature: string
        @param rawSignature: A JSON-formatted string representing the crash signature
        '''

        # For now, we store the original raw signature and hand it out for
        # conversion to String. This is fine as long as our Signature object
        # is immutable. Later, we should implement a method that actually
        # serializes this object back to JSON as it is.
        #
        self.rawSignature = rawSignature
        self.symptoms = []

        try:
            obj = json.loads(rawSignature, object_pairs_hook=OrderedDict)
        except ValueError, e:
            raise RuntimeError("Invalid JSON: %s" % e)

        # Get the symptoms objects (mandatory)
        if "symptoms" in obj:
            symptoms = JSONHelper.getArrayChecked(obj, "symptoms", True)
            if len(symptoms) == 0:
                raise RuntimeError("Signature must have at least one symptom.")

            for rawSymptomsObj in symptoms:
                self.symptoms.append(Symptom.fromJSONObject(rawSymptomsObj))
        else:
            raise RuntimeError('Missing mandatory top-level key "symptoms".')

        # Get some optional lists
        self.platforms = JSONHelper.getArrayChecked(obj, "platforms")
        self.operatingSystems = JSONHelper.getArrayChecked(
            obj, "operatingSystems")
        self.products = JSONHelper.getArrayChecked(obj, "products")
Exemplo n.º 15
0
    def __init__(self, rawSignature):
        '''
        Constructor

        @type rawSignature: string
        @param rawSignature: A JSON-formatted string representing the crash signature
        '''

        # For now, we store the original raw signature and hand it out for
        # conversion to String. This is fine as long as our Signature object
        # is immutable. Later, we should implement a method that actually
        # serializes this object back to JSON as it is.
        #
        self.rawSignature = rawSignature
        self.symptoms = []

        try:
            obj = json.loads(rawSignature, object_pairs_hook=OrderedDict)
        except ValueError as e:
            raise RuntimeError("Invalid JSON: %s" % e)

        # Get the symptoms objects (mandatory)
        if "symptoms" in obj:
            symptoms = JSONHelper.getArrayChecked(obj, "symptoms", True)
            if len(symptoms) == 0:
                raise RuntimeError("Signature must have at least one symptom.")

            for rawSymptomsObj in symptoms:
                self.symptoms.append(Symptom.fromJSONObject(rawSymptomsObj))
        else:
            raise RuntimeError('Missing mandatory top-level key "symptoms".')

        # Get some optional lists
        self.platforms = JSONHelper.getArrayChecked(obj, "platforms")
        self.operatingSystems = JSONHelper.getArrayChecked(obj, "operatingSystems")
        self.products = JSONHelper.getArrayChecked(obj, "products")
Exemplo n.º 16
0
 def __init__(self, obj):
     '''
     Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
     '''
     Symptom.__init__(self, obj)
     self.address = NumberMatch(JSONHelper.getNumberOrStringChecked(obj, "address", True))
Exemplo n.º 17
0
 def __init__(self, obj):
     '''
     Private constructor, called by L{Symptom.fromJSONObject}. Do not use directly.
     '''
     Symptom.__init__(self, obj)
     self.output = StringMatch(JSONHelper.getObjectOrStringChecked(obj, "value", True))