Beispiel #1
0
 def add_finding(self, finding, detail="", location={}):
     if type(location) == tuple and "jsoncfg.config_classes" in str(
             type(location[1])):
         location_data = {}
         location_data["string"] = location[0]
         location_data["lineno"] = jsoncfg.node_location(location[1])[0]
         location_data["column"] = jsoncfg.node_location(location[1])[1]
         location = location_data
     elif "ConfigJSONScalar" in str(type(location)):
         location_data = {}
         location_data["string"] = location.value
         location_data["lineno"] = jsoncfg.node_location(location).line
         location_data["column"] = jsoncfg.node_location(location).column
         location = location_data
     if "filepath" not in location:
         location["filepath"] = self.filepath
     self._findings.append(Finding(finding, detail, location))
Beispiel #2
0
    def add_finding(self, finding, detail=None, location={}):
        """
        Add finding to the class.

        finding: String specifiying the problem
        location: Dictionary with information about where this problem is. Often set to:
            {"location": "string"}
        """
        if "jsoncfg.config_classes.ConfigJSONObject" in str(type(location)):
            node_location = jsoncfg.node_location(location)
            location = {
                "line": node_location.line,
                "column": node_location.column
            }
        elif "jsoncfg.config_classes.ConfigJSONScalar" in str(type(location)):
            node_location = jsoncfg.node_location(location)
            location = {"string": location.value}
            location["line"] = node_location.line
            location["column"] = node_location.column
        elif "tuple" in str(type(location)):
            node_location = jsoncfg.node_location(location[1])
            location = {"string": location[0]}
            location["line"] = node_location.line
            location["column"] = node_location.column
        elif "jsoncfg.config_classes.ConfigJSONScalar" in str(
                type(location.get("string", ""))):
            node_location = jsoncfg.node_location(location["string"])
            location["line"] = node_location.line
            location["column"] = node_location.column
            location["string"] = location["string"].value
        elif "tuple" in str(type(location.get("string", ""))):
            node_location = jsoncfg.node_location(location["string"][1])
            location["line"] = node_location.line
            location["column"] = node_location.column
            location["string"] = location["string"][0]

        elif "jsoncfg.config_classes" in str(type(location.get("string", ""))):
            location["string"] = location["string"][0]

        self.findings.append(Finding(finding, detail, location))
Beispiel #3
0
def make_list(v):
    """
    If the object is not a list already, it converts it to one
    Examples:
    [1, 2, 3] -> [1, 2, 3]
    [1] -> [1]
    1 -> [1]
    """
    if not jsoncfg.node_is_array(v):
        if jsoncfg.node_is_scalar(v):
            location = jsoncfg.node_location(v)
            line = location.line
            column = location.column
        else:
            line = v.line
            column = v.column

        a = jsoncfg.config_classes.ConfigJSONArray(line, column)
        a._append(v)
        return a
    return v
 def test_node_location(self):
     config = loads_config('\n{k0:0}')
     location = node_location(config)
     self.assertEquals(location, (2, 1))
     self.assertEquals(location.line, 2)
     self.assertEquals(location.column, 1)
 def test_node_location(self):
     config = loads_config('\n{k0:0}')
     location = node_location(config)
     self.assertEquals(location, (2, 1))
     self.assertEquals(location.line, 2)
     self.assertEquals(location.column, 1)