Read `toml` files using the standard `tomlib` (if available). #143

This commit is contained in:
Fabio Caccamo 2022-11-22 14:11:01 +01:00
parent c08b74356f
commit e9d2d85f78
1 changed files with 12 additions and 1 deletions

View File

@ -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):