def parse_key_value()

in pbspro/src/pbspro/parser.py [0:0]


    def parse_key_value(self, raw_output: str) -> List[Dict[str, str]]:
        if raw_output.lower().startswith("no active"):
            # e.g. No Active Nodes, nothing done.
            return []

        ret = []
        current_record: Dict[str, str] = {}

        line_continued: str = ""
        for n, line in enumerate(raw_output.splitlines()):
            line = line.strip()
            if line.startswith("#"):
                continue

            if line.endswith(","):
                line_continued = line_continued + line
                continue
            else:
                line = line_continued + line
                line_continued = ""

            if not line:
                if current_record:
                    ret.append(current_record)
                    current_record = {}
                continue

            if not current_record:
                try:
                    obj_type, obj_name = line.split()
                except ValueError:
                    obj_name = line
                    obj_type = "unknown"

                current_record["obj_type"] = obj_type
                current_record["name"] = obj_name
            else:
                assert (
                    "=" in line
                ), "{} has no = in it. Line {} of the following:\n{}".format(
                    line, n + 1, raw_output
                )

                key, value = line.split("=", 1)
                key, value = key.strip(), value.strip()
                current_record[key] = value

        if current_record:
            ret.append(current_record)

        return ret