def _parse_property(self, prop): """ >>> parse_property(b'key=value') ('key', 'value') >>> parse_property(b'foo') ('foo', '') >>> parse_property(b'client_unique_identifier=gZ7K[...]GIik=') ('client_unique_identifier', 'gZ7K[...]GIik=') """ prop = prop.split(b"=") if len(prop) == 1: key = prop[0] val = bytes() elif len(prop) == 2: key, val = prop else: key = prop[0] val = b"=".join(prop[1:]) try: key = key.decode() val = val.decode() except UnicodeDecodeError as err: # Todo: - Should we simply ignore decode errors? # - Is decoding reasonable? raise TS3ParserError(self, err) key = TS3Escape.unescape(key) val = TS3Escape.unescape(val) return (key, val)
def _parse_property(self, prop): """ >>> parse_property(b'key=value') ('key', 'value') >>> parse_property(b'foo') ('foo', '') >>> parse_property(b'client_unique_identifier=gZ7K[...]GIik=') ('client_unique_identifier', 'gZ7K[...]GIik=') """ prop = prop.split(b"=") if len(prop) == 1: key = prop[0] val = bytes() elif len(prop) == 2: key, val = prop else: key = prop[0] val = b"=".join(prop[1:]) # Take a look at https://github.com/benediktschmitt/py-ts3/issues/34 # to find out, why we simply ignore the decode errors. try: key = key.decode() except UnicodeDecodeError as err: LOG.warning("Failed to decode the key part properly: '%s'.", err) key = key.decode(errors="ignore") try: val = val.decode() except UnicodeDecodeError as err: LOG.warning("Failed to decode the value part properly: '%s'.", err) val = val.decode(errors="ignore") key = TS3Escape.unescape(key) val = TS3Escape.unescape(val) return (key, val)