Skip to content

Commit

Permalink
Add _dict back
Browse files Browse the repository at this point in the history
  • Loading branch information
uiri committed Mar 25, 2018
1 parent 6deb41b commit 1a50a5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ def test_valid_tests():
toml.dumps(toml.load(open(os.path.join(valid_dir, f))))


def test__dict():
class TestDict(dict):
pass

assert isinstance(toml.loads(
TEST_STR, _dict=TestDict), TestDict)


def test_dict_decoder():
class TestDict(dict):
pass
Expand Down
12 changes: 6 additions & 6 deletions toml/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _strictly_valid_num(n):
return True


def load(f, decoder=None):
def load(f, _dict=dict, decoder=None):
"""Parses named file or files as toml and returns a dictionary
Args:
Expand All @@ -82,7 +82,7 @@ def load(f, decoder=None):

if isinstance(f, basestring):
with io.open(f, encoding='utf-8') as ffile:
return loads(ffile.read(), decoder)
return loads(ffile.read(), _dict, decoder)
elif isinstance(f, list):
from os import path as op
from warnings import warn
Expand All @@ -97,14 +97,14 @@ def load(f, decoder=None):
d = decoder.get_empty_table()
for l in f:
if op.exists(l):
d.update(load(l, decoder))
d.update(load(l, _dict, decoder))
else:
warn("Non-existent filename in list with at least one valid "
"filename")
return d
else:
try:
return loads(f.read(), decoder)
return loads(f.read(), _dict, decoder)
except AttributeError:
raise TypeError("You can only load a file descriptor, filename or "
"list")
Expand All @@ -113,7 +113,7 @@ def load(f, decoder=None):
_groupname_re = re.compile(r'^[A-Za-z0-9_-]+$')


def loads(s, decoder=None):
def loads(s, _dict=dict, decoder=None):
"""Parses string as toml
Args:
Expand All @@ -130,7 +130,7 @@ def loads(s, decoder=None):

implicitgroups = []
if decoder is None:
decoder = TomlDecoder()
decoder = TomlDecoder(_dict)
retval = decoder.get_empty_table()
currentlevel = retval
if not isinstance(s, basestring):
Expand Down

0 comments on commit 1a50a5f

Please sign in to comment.