Read `toml` files using the standard `tomlib` (if available). #143
This commit is contained in:
parent
c08b74356f
commit
e9d2d85f78
|
@ -2,6 +2,14 @@
|
|||
|
||||
import toml
|
||||
|
||||
try:
|
||||
# python >= 3.11
|
||||
import tomllib
|
||||
|
||||
tomllib_available = True
|
||||
except ImportError:
|
||||
tomllib_available = False
|
||||
|
||||
from benedict.serializers.abstract import AbstractSerializer
|
||||
|
||||
|
||||
|
@ -18,7 +26,10 @@ class TOMLSerializer(AbstractSerializer):
|
|||
)
|
||||
|
||||
def decode(self, s, **kwargs):
|
||||
data = toml.loads(s, **kwargs)
|
||||
if tomllib_available:
|
||||
data = tomllib.loads(s, **kwargs)
|
||||
else:
|
||||
data = toml.loads(s, **kwargs)
|
||||
return data
|
||||
|
||||
def encode(self, d, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue