hassio/utils/gdbus.py
def parse_gvariant(raw: str) -> Any:
        """Parse GVariant input to python."""
        # Process first string
        json_raw = RE_GVARIANT_STRING_ESC.sub(
            lambda x: x.group(0).replace('"', '\\"'), raw
        )
        json_raw = RE_GVARIANT_STRING.sub(r'"\1"', json_raw)

        # Remove complex type handling
        json_raw: str = RE_GVARIANT_TYPE.sub(
            lambda x: x.group(0) if not x.group(1) else "", json_raw
        )
        json_raw = RE_GVARIANT_VARIANT.sub(
            lambda x: x.group(0) if not x.group(1) else "", json_raw
        )
        json_raw = RE_GVARIANT_TUPLE_O.sub(
            lambda x: x.group(0) if not x.group(1) else "[", json_raw
        )
        json_raw = RE_GVARIANT_TUPLE_C.sub(
            lambda x: x.group(0) if not x.group(1) else "]", json_raw
        )

        # No data
        if json_raw.startswith("[]"):
            return []

        try:
            return json.loads(json_raw)
        except json.JSONDecodeError as err:
            _LOGGER.error("Can't parse '%s': %s", json_raw, err)
            _LOGGER.debug("GVariant data: '%s'", raw)
            raise DBusParseError() from None
Parse GVariant input to python.
Parse GVariant input to python.
Parse GVariant input to python .
def parse_gvariant(raw: str) -> Any:
        json_raw = RE_GVARIANT_STRING_ESC.sub(
            lambda x: x.group(0).replace('"', '\\"'), raw
        )
        json_raw = RE_GVARIANT_STRING.sub(r'"\1"', json_raw)
        json_raw: str = RE_GVARIANT_TYPE.sub(
            lambda x: x.group(0) if not x.group(1) else "", json_raw
        )
        json_raw = RE_GVARIANT_VARIANT.sub(
            lambda x: x.group(0) if not x.group(1) else "", json_raw
        )
        json_raw = RE_GVARIANT_TUPLE_O.sub(
            lambda x: x.group(0) if not x.group(1) else "[", json_raw
        )
        json_raw = RE_GVARIANT_TUPLE_C.sub(
            lambda x: x.group(0) if not x.group(1) else "]", json_raw
        )
        if json_raw.startswith("[]"):
            return []
        try:
            return json.loads(json_raw)
        except json.JSONDecodeError as err:
            _LOGGER.error("Can't parse '%s': %s", json_raw, err)
            _LOGGER.debug("GVariant data: '%s'", raw)
            raise DBusParseError() from None
def parse_gvariant ( raw : str ) -> Any : json_raw = RE_GVARIANT_STRING_ESC . sub ( lambda x : x . group ( 0 ) . replace ( '"' , '\\"' ) , raw ) json_raw = RE_GVARIANT_STRING . sub ( r'"\1"' , json_raw ) json_raw : str = RE_GVARIANT_TYPE . sub ( lambda x : x . group ( 0 ) if not x . group ( 1 ) else "" , json_raw ) json_raw = RE_GVARIANT_VARIANT . sub ( lambda x : x . group ( 0 ) if not x . group ( 1 ) else "" , json_raw ) json_raw = RE_GVARIANT_TUPLE_O . sub ( lambda x : x . group ( 0 ) if not x . group ( 1 ) else "[" , json_raw ) json_raw = RE_GVARIANT_TUPLE_C . sub ( lambda x : x . group ( 0 ) if not x . group ( 1 ) else "]" , json_raw ) if json_raw . startswith ( "[]" ) : return [ ] try : return json . loads ( json_raw ) except json . JSONDecodeError as err : _LOGGER . error ( "Can't parse '%s': %s" , json_raw , err ) _LOGGER . debug ( "GVariant data: '%s'" , raw ) raise DBusParseError ( ) from None
Parse GVariant input to python.
Parse GVariant input to python .
"""Parse GVariant input to python.""" # Process first string # Remove complex type handling # No data
raw
str