Пример #1
0
 def __init__(self,
              id,
              binding=None,
              verdict=None,
              time_obtained=None,
              function_call=None,
              collapsing_atom=None,
              collapsing_atom_sub_index=None):
     connection = get_connection()
     self.id = id
     if binding is None:
         result = connection.request('client/verdict/id/%d/' % self.id)
         if result == "None": raise ValueError('no verdicts with given ID')
         d = json.loads(result)
         self.binding = d["binding"]
         self.verdict = d["verdict"]
         self.time_obtained = d["time_obtained"]
         self.function_call = d["function_call"]
         self.collapsing_atom = d["collapsing_atom"]
         self.collapsing_atom_sub_index = d["collapsing_atom_sub_index"]
     else:
         self.binding = binding
         self.verdict = verdict
         self.time_obtained = time_obtained
         self.function_call = function_call
         self.collapsing_atom = collapsing_atom
         self.collapsing_atom_sub_index = collapsing_atom_sub_index
Пример #2
0
 def __init__(self,
              id=None,
              property_hash=None,
              serialised_structure=None,
              index_in_atoms=None):
     connection = get_connection()
     if id is not None and property_hash is not None and serialised_structure is not None and index_in_atoms is not None:
         self.id = id
         self.property_hash = property_hash
         self.serialised_structure = serialised_structure
         self.index_in_atoms = index_in_atoms
     else:
         if id is not None:
             self.id = id
             result = connection.request('client/atom/id/%d/' % self.id)
             if result == "None": raise ValueError('no atoms with given ID')
             d = json.loads(result)
             self.property_hash = d["property_hash"]
             self.serialised_structure = d["serialised_structure"]
             self.index_in_atoms = d["index_in_atoms"]
         elif index_in_atoms is not None and property_hash is not None:
             self.index_in_atoms = index_in_atoms
             self.property_hash = property_hash
             result = connection.request(
                 'client/atom/index/%d/property/%s/' %
                 (self.index_in_atoms, self.property_hash))
             if result == "None": raise ValueError('no such atoms')
             d = json.loads(result)
             self.serialised_structure = d["serialised_structure"]
             self.id = d["id"]
         else:
             raise ValueError(
                 'either id or index_in_atoms and property arguments needed to initialize object'
             )
Пример #3
0
 def __init__(self,
              id,
              binding=None,
              verdict=None,
              time_obtained=None,
              function_call=None,
              collapsing_atom=None):
     connection = get_connection()
     self.id = id
     if binding == None:
         str = connection.request('client/get_verdict_by_id/%d/' % self.id)
         if str == "None": raise ValueError('no verdicts with given ID')
         str = str[1:-1]
         d = json.loads(str)
         self.binding = d["binding"]
         self.verdict = d["verdict"]
         self.time_obtained = d["time_obtained"]
         self.function_call = d["function_call"]
         self.collapsing_atom = d["collapsing_atom"]
     else:
         self.binding = binding
         self.verdict = verdict
         self.time_obtained = time_obtained
         self.function_call = function_call
         if collapsing_atom != None: self.collapsing_atom = collapsing_atom
Пример #4
0
 def __init__(self, id=None, time_of_request=None):
     connection = get_connection()
     if id != None:
         self.id = id
         if time_of_request == None:
             str = connection.request('client/get_http_by_id/%d/' % self.id)
             if str == "None":
                 raise ValueError(
                     'no HTTP requests in the database with given ID')
             str = str[1:-1]
             d = json.loads(str)
             self.time_of_request = d["time_of_request"]
         else:
             self.time_of_request = time_of_request
     elif time_of_request != None:
         self.time_of_request = time_of_request
         str = connection.request('client/get_http_by_time/%s/' %
                                  self.time_of_request)
         if str == "None":
             raise ValueError(
                 'no HTTP requests in the database with given time')
         str = str[1:-1]
         d = json.loads(str)
         self.id = d["id"]
     else:
         raise ValueError('either id or time_of_request argument required')
Пример #5
0
def test_data(id=None,
              test_name=None,
              test_result=None,
              start_time=None,
              end_time=None):
    """
    Factory function for test data rows.
    """

    connection = get_connection()

    if (id is not None and test_name is not None and test_result is not None
            and start_time is not None and end_time is not None):

        return TestData(id=id,
                        test_name=test_name,
                        test_result=test_result,
                        start_time=start_time,
                        end_time=end_time)

    elif id is not None:

        result = connection.request('client/test_data/id/%d/' % id)
        if result == "None": raise ValueError('no test data with given ID')
        dict = json.loads(result)

        return TestData(id=id,
                        test_name=dict["test_name"],
                        test_result=dict["test_result"],
                        start_time=dict["start_time"],
                        end_time=dict["end_time"])
Пример #6
0
 def __init__(self,
              id=None,
              time_of_transaction=None,
              time_lower_bound=None,
              time_upper_bound=None):
     connection = get_connection()
     if id is not None:
         self.id = id
         if time_of_transaction is None:
             result = connection.request('client/transaction/id/%d/' %
                                         self.id)
             if result == "None":
                 raise ValueError(
                     'no transaction in the database with given ID')
             d = json.loads(result)
             self.time_of_transaction = d["time_of_transaction"]
         else:
             self.time_of_transaction = time_of_transaction
     elif time_of_transaction is not None:
         self.time_of_transaction = time_of_transaction
         result = connection.request('client/transaction/time/%s/' %
                                     self.time_of_transaction)
         if result == "None":
             raise ValueError(
                 'no transaction in the database with given time')
         d = json.loads(result)
         self.id = d["id"]
     else:
         raise ValueError(
             'either id or time_of_transaction argument required')
Пример #7
0
 def __init__(self, hash):
     connection = get_connection()
     self.hash = hash
     result = connection.request('client/property/hash/%s/' % hash)
     if result == "None":
         raise ValueError('no such property')
     else:
         f_dict = json.loads(str)
         self.serialised_structure = f_dict["serialised_structure"]
Пример #8
0
 def __init__(self, id, binding_space_index, function,
              binding_statement_lines):
     connection = get_connection()
     self.id = id
     if binding_space_index == None or function == None or binding_statement_lines == None:
         pass
     else:
         self.binding_space_index = binding_space_index
         self.function = function
         self.binding_statement_lines = binding_statement_lines
Пример #9
0
 def get_assignments_as_dictionary(self):
     connection = get_connection()
     str = connection.request(
         '/client/get_assignment_dict_from_observation/%d/' % self.id)
     if str == "None":
         raise ValueError('no assignments paired with given observation')
     assignment_dict = json.loads(str)
     for a in assignment_dict:
         # TODO: use assignment_dict[a][1] to decide if we need to import another type
         assignment_dict[a] = pickle.loads(assignment_dict[a][0])
     return assignment_dict
Пример #10
0
 def reconstruct_path(self, scfg):
     """Locally reconstruct the entire path taken by this function call (if there was path instrumentation)."""
     connection = get_connection()
     json_result = connection.request(
         'client/get_path_conditions_by_function_call_id/%i/' % self.id)
     path_condition_list = json.loads(json_result)
     trimmed_path_condition_list = list(reversed(path_condition_list[0:-1]))
     # TODO: at the moment, I don't think we need to deserialise...
     edges = edges_from_condition_sequence(scfg,
                                           trimmed_path_condition_list, -1)
     return edges
Пример #11
0
 def __init__(self, id):
     connection = get_connection()
     self.id = id
     result = connection.request('client/assignment/id/%d/' % self.id)
     if result == "None":
         raise ValueError('There is no assignment with given ID')
     d = json.loads(result)
     self.variable = d["variable"]
     self.value = d[
         "value"]  # is it better to keep this serialised or to deserialise it?
     self.type = d["type"]
Пример #12
0
 def get_assignments(self):
     connection = get_connection()
     result = connection.request('client/observation/id/%d/assignments/' %
                                 self.id)
     if result == "None":
         raise ValueError('no assignments paired with given observation')
     assignment_dict = json.loads(result)
     assignment_list = []
     for a in assignment_dict:
         assignment_class = Assignment(a["id"])
         assignment_list.append(assignment_class)
     return assignment_list
Пример #13
0
 def get_assignments(self):
     connection = get_connection()
     result = connection.request('client/observation/id/%d/assignments/' %
                                 self.id)
     if result == "[]":
         if warnings_on: ('No assignments paired with given observation')
         return []
     assignment_dict = json.loads(result)
     assignment_list = []
     for a in assignment_dict:
         assignment_class = Assignment(a["id"])
         assignment_list.append(assignment_class)
     return assignment_list
Пример #14
0
 def get_observations(self):
     connection = get_connection()
     str = connection.request('client/list_observations_during_call/%d/' %
                              self.id)
     if str == "None": print('no observations for given function call')
     obs_dict = json.loads(str)
     obs_list = []
     for o in obs_dict:
         obs_class = observation(o["id"], o["instrumentation_point"],
                                 o["verdict"], o["observed_value"],
                                 o["atom_index"], o["previous_condition"])
         obs_list.append(obs_class)
     return obs_list
Пример #15
0
 def reconstruct_reaching_path(self, scfg):
     """Reconstruct the sequence of edges to reach this observation through the SCFG given."""
     connection = get_connection()
     json_result = connection.request(
         'client/get_path_condition_sequence/%i/' % self.id)
     result_dict = json.loads(json_result)
     path_condition_list = result_dict["path_subchain"]
     path_length = result_dict["path_length"]
     #trimmed_path_condition_list = list(reversed(path_condition_list[0:-1]))
     # TODO: at the moment, I don't think we need to deserialise...
     edges = edges_from_condition_sequence(scfg, path_condition_list,
                                           path_length)
     return edges
Пример #16
0
 def __init__(self, hash, serialised_structure=None):
     connection = get_connection()
     self.hash = hash
     if serialised_structure == None:
         str = connection.request('client/get_property_by_hash/%s/' % hash)
         if str == "None":
             raise ValueError('no such property')
         else:
             str = str[1:-1]
             f_dict = json.loads(str)
             self.serialised_structure = f_dict["serialised_structure"]
     else:
         self.serialised_structure = serialised_structure
Пример #17
0
 def get_assignments(self):
     connection = get_connection()
     str = connection.request(
         'client/list_assignments_given_observation/%d/' % self.id)
     if str == "None":
         raise ValueError('no assignments paired with given observation')
     assignment_dict = json.loads(str)
     assignment_list = []
     for a in assignment_dict:
         assignment_class = assignment(a["id"], a["variable"], a["value"],
                                       a["type"])
         assignment_list.append(assignment_class)
     return assignment_list
Пример #18
0
 def get_calls_with_verdict(self, verdict_value):
     connection = get_connection()
     str = connection.request(
         'client/list_function_calls_with_verdict/%d/%d/' %
         (self.id, verdict_value))
     if str == "None": raise ValueError('no such calls')
     calls_dict = json.loads(str)
     calls_list = []
     for call in calls_dict:
         call_class = function_call(call["id"], call["function"],
                                    call["time_of_call"],
                                    call["http_request"])
         calls_list.append(call_class)
     return calls_list
Пример #19
0
    def get_bindings(self):
        connection = get_connection()
        result = connection.request("client/function/id/%d/bindings/" %
                                    self.id)
        if result == "None":
            raise ValueError("No such bindings")
        bindings_dict = json.loads(result)
        binding_list = []
        for b in bindings_dict:
            binding_obj = binding(b["id"], b["binding_space_index"],
                                  b["function"], b["binding_statement_lines"])
            binding_list.append(binding_obj)

        return binding_list
Пример #20
0
def list_functions():
    """
    Get a list of all existing functions from the server.
    """
    connection = get_connection()
    result = connection.request('client/function/')
    if result == "None":
        raise ValueError('No functions currently exist.')
    f_dict = json.loads(result)
    f_list = []
    for f in f_dict:
        f_obj = function(f["id"], f["fully_qualified_name"])
        f_list.append(f_obj)
    return f_list
Пример #21
0
def list_verdicts_dict_with_value(value):
    """finds all verdicts in the database with given value
    returns a dictionary with keys:
    from verdict - id, binding, verdict, time_obtained,
    from function_call - function, time_of_call
    from function - fully_qualified_name, property"""

    connection = get_connection()

    str = connection.request(
        'client/list_verdicts_function_property_by_value/%d/' % value)
    if str == "None": raise ValueError('there are no such verdicts')
    d = json.loads(str)
    return d
Пример #22
0
 def get_verdicts(self):
     connection = get_connection()
     result = connection.request('client/binding/id/%s/verdicts/' % self.id)
     if result == "None":
         raise ValueError('no such property')
     else:
         result = json.loads(result)
         verdict_list = []
         for v in result:
             new_verdict = verdict(v["id"], v["binding"], v["verdict"],
                                   v["time_obtained"], v["function_call"],
                                   v["collapsing_atom"],
                                   v["collapsing_atom_sub_index"])
             verdict_list.append(new_verdict)
         return verdict_list
Пример #23
0
 def get_calls(self):
     connection = get_connection()
     result = connection.request(
         'client/transaction/id/%d/function_calls/' % self.id)
     if result == "None":
         print('no calls during the given request')
         return
     calls_dict = json.loads(result)
     calls_list = []
     for call in calls_dict:
         call_class = FunctionCall(call["id"], call["function"],
                                   call["time_of_call"],
                                   call["end_time_of_call"], call["trans"])
         calls_list.append(call_class)
     return calls_list
Пример #24
0
def list_verdicts_with_value(value):
    """called as list_verdicts(True) or list_verdicts(False)
    returns a list of objects 'class verdict' with the given value"""

    connection = get_connection()

    str = connection.request('client/list_verdicts_with_value/%d/' % value)
    if str == "None": raise ValueError('there are no such verdicts')
    verdicts_dict = json.loads(str)
    verdicts_list = []
    for v in verdicts_dict:
        verdict_class = verdict(v["id"], v["binding"], v["time_obtained"],
                                v["function_call"], v["collapsing_atom"])
        verdicts_list.append(verdict_class)
    return verdicts_list
Пример #25
0
 def get_calls(self):
     connection = get_connection()
     str = connection.request('client/list_function_calls_http/%d/' %
                              self.id)
     if str == "None":
         print('no calls during the given request')
         return
     calls_dict = json.loads(str)
     calls_list = []
     for call in calls_dict:
         call_class = function_call(call["id"], call["function"],
                                    call["time_of_call"],
                                    call["http_request"])
         calls_list.append(call_class)
     return calls_list
Пример #26
0
 def get_observations(self):
     connection = get_connection()
     result = connection.request(
         'client/instrumentation_point/id/%d/observations/' % self.id)
     if result == "None":
         print('no observations for given instrumentation point')
         return
     obs_dict = json.loads(result)
     obs_list = []
     for o in obs_dict:
         obs_class = observation(o["id"], o["instrumentation_point"],
                                 o["verdict"], o["observed_value"],
                                 o["atom_index"], o["previous_condition"])
         obs_list.append(obs_class)
     return obs_list
Пример #27
0
 def get_observations(self):
     """
     Get a list of the observations that were needed to obtain this verdict.
     """
     connection = get_connection()
     result = connection.request('client/verdict/id/%d/observations/' %
                                 self.id)
     if result == "None": print('no observations for given verdict')
     obs_dict = json.loads(result)
     obs_list = []
     for o in obs_dict:
         obs_class = observation(o["id"], o["instrumentation_point"],
                                 o["verdict"], o["observed_value"],
                                 o["atom_index"], o["previous_condition"])
         obs_list.append(obs_class)
     return obs_list
Пример #28
0
 def get_calls(self):
     """function.get_calls() returns a list of calls for the given function
     if given the optional parameter value, it returns the list of the
     function calls which happened during the given trans"""
     connection = get_connection()
     result = connection.request('client/function/name/%s/function_calls/' %
                                 self.fully_qualified_name)
     if (result == "None"): raise ValueError('no such calls')
     calls_dict = json.loads(result)
     calls_list = []
     for call in calls_dict:
         call_class = FunctionCall(call["id"], call["function"],
                                   call["time_of_call"],
                                   call["end_time_of_call"], call["trans"])
         calls_list.append(call_class)
     return calls_list
Пример #29
0
 def get_verdicts(self, verdict_value=None):
     connection = get_connection()
     if verdict_value == None:
         str = connection.request('client/list_verdicts_of_function/%d/' %
                                  self.id)
     else:
         str = connection.request(
             'client/list_verdicts_of_function_with_value/%d/%d/' %
             (self.id, verdict_value))
     if str == "None": raise ValueError('no such verdicts')
     verdicts_dict = json.loads(str)
     verdicts_list = []
     for v in verdicts_dict:
         verdict_class = verdict(v["id"], v["binding"], v["verdict"],
                                 v["time_obtained"], v["function_call"])
         verdicts_list.append(verdict_class)
     return verdicts_list
Пример #30
0
def verdict(id=None,
            binding=None,
            verdict=None,
            time_obtained=None,
            function_call=None,
            collapsing_atom=None,
            collapsing_atom_sub_index=None):
    """
    Factory function for verdicts.  Gives a single Verdict object or a list, depending on input.
    """

    connection = get_connection()

    if (id is not None and binding is not None and verdict is not None
            and time_obtained is not None and function_call is not None
            and collapsing_atom is not None
            and collapsing_atom_sub_index is not None):

        return Verdict(id=id,
                       binding=binding,
                       verdict=verdict,
                       time_obtained=time_obtained,
                       function_call=function_call,
                       collapsing_atom=collapsing_atom,
                       collapsing_atom_sub_index=collapsing_atom_sub_index)

    elif id is not None:

        result = connection.request('client/verdict/id/%d/' % id)
        if result == "None": raise ValueError('no verdicts with given ID')
        d = json.loads(result)

        return Verdict(
            id=id,
            binding=d["binding"],
            verdict=d["verdict"],
            time_obtained=d["time_obtained"],
            function_call=d["function_call"],
            collapsing_atom=d["collapsing_atom"],
            collapsing_atom_sub_index=d["collapsing_atom_sub_index"])

    else:

        raise Exception(
            "Cannot instantiate single or multiple verdicts with parameters given."
        )