def _from_toml(toml_string=_A,filename=_A,encoding=_B,errors=_C):
	B=toml_string;A=filename
	if A:
		_exists(A)
		with open(A,_G,encoding=encoding,errors=errors)as D:C=toml.load(D)
	elif B:C=toml.loads(B)
	else:raise BoxError('from_toml requires a string or filename')
	return C
Beispiel #2
0
def _from_toml(toml_string=None,
               filename=None,
               encoding="utf-8",
               errors="strict"):
    if filename:
        _exists(filename)
        with open(filename, 'r', encoding=encoding, errors=errors) as f:
            data = toml.load(f)
    elif toml_string:
        data = toml.loads(toml_string)
    else:
        raise BoxError('from_toml requires a string or filename')
    return data
Beispiel #3
0
def parse_with_toml(data):
    """Uses TOML syntax to parse data"""
    try:
        return toml.loads(f"key={data}")["key"]
    except (toml.TomlDecodeError, KeyError):
        return data