vdb/lib/utils.py
def load(d):
    """Parses a python object from a JSON string. Every Object which should be loaded needs a constuctor that doesn't need any Arguments.
    Arguments: Dict object; the module which contains the class, the parsed object is instance of."""

    def _load(d):
        if isinstance(d, list):
            li = []
            for item in d:
                li.append(_load(item))
            return li
        elif isinstance(d, dict) and "type" in d:  # object
            t = d["type"]
            if t == "datetime":
                if hasattr(datetime, "fromisoformat"):
                    return datetime.fromisoformat(d["value"])
                else:
                    return datetime.strptime(d["value"], date_format_str)
            if t == "Severity":
                return Severity.from_str(d["value"])
            try:
                del d["type"]
                clazz = getattr(importlib.import_module("vdb.lib"), t)
                if hasattr(clazz, "from_dict"):
                    o = clazz.from_dict(d)
                else:
                    o = clazz(**d)
            except KeyError:
                raise ClassNotFoundError(
                    "Class '%s' not found in the given module!" % t
                )
            except TypeError:
                raise TypeError(
                    "Make sure there is an constuctor that doesn't take any arguments (class: %s)"
                    % t
                )
            return o
        elif isinstance(d, dict):  # dict
            rd = {}
            for key in d:
                rd[key] = _load(d[key])
            return rd
        else:
            return d

    return _load(d)
Parses a python object from a JSON string. Every Object which should be loaded needs a constuctor that doesn't need any Arguments.
    Arguments: Dict object; the module which contains the class, the parsed object is instance of.
Parses a python object from a JSON string. Every Object which should be loaded needs a constuctor that doesn't need any Arguments.
Arguments: Dict object; the module which contains the class, the parsed object is instance of.
Parses a python object from a JSON string . Every Object which should be loaded needs a constuctor that doesn ' t need any Arguments . Arguments : Dict object ; the module which contains the class the parsed object is instance of .
def load(d):
    def _load(d):
        if isinstance(d, list):
            li = []
            for item in d:
                li.append(_load(item))
            return li
        elif isinstance(d, dict) and "type" in d:  
            t = d["type"]
            if t == "datetime":
                if hasattr(datetime, "fromisoformat"):
                    return datetime.fromisoformat(d["value"])
                else:
                    return datetime.strptime(d["value"], date_format_str)
            if t == "Severity":
                return Severity.from_str(d["value"])
            try:
                del d["type"]
                clazz = getattr(importlib.import_module("vdb.lib"), t)
                if hasattr(clazz, "from_dict"):
                    o = clazz.from_dict(d)
                else:
                    o = clazz(**d)
            except KeyError:
                raise ClassNotFoundError(
                    "Class '%s' not found in the given module!" % t
                )
            except TypeError:
                raise TypeError(
                    "Make sure there is an constuctor that doesn't take any arguments (class: %s)"
                    % t
                )
            return o
        elif isinstance(d, dict):  
            rd = {}
            for key in d:
                rd[key] = _load(d[key])
            return rd
        else:
            return d
    return _load(d)
def load ( d ) : def _load ( d ) : if isinstance ( d , list ) : li = [ ] for item in d : li . append ( _load ( item ) ) return li elif isinstance ( d , dict ) and "type" in d : t = d [ "type" ] if t == "datetime" : if hasattr ( datetime , "fromisoformat" ) : return datetime . fromisoformat ( d [ "value" ] ) else : return datetime . strptime ( d [ "value" ] , date_format_str ) if t == "Severity" : return Severity . from_str ( d [ "value" ] ) try : del d [ "type" ] clazz = getattr ( importlib . import_module ( "vdb.lib" ) , t ) if hasattr ( clazz , "from_dict" ) : o = clazz . from_dict ( d ) else : o = clazz ( ** d ) except KeyError : raise ClassNotFoundError ( "Class '%s' not found in the given module!" % t ) except TypeError : raise TypeError ( "Make sure there is an constuctor that doesn't take any arguments (class: %s)" % t ) return o elif isinstance ( d , dict ) : rd = { } for key in d : rd [ key ] = _load ( d [ key ] ) return rd else : return d return _load ( d )
Parses a python object from a JSON string.
Parses a python object from a JSON string .
"""Parses a python object from a JSON string. Every Object which should be loaded needs a constuctor that doesn't need any Arguments.
    Arguments: Dict object; the module which contains the class, the parsed object is instance of.""" # object # dict
d