diff --git a/benedict/__init__.py b/benedict/__init__.py index 2f6e259..30358d2 100644 --- a/benedict/__init__.py +++ b/benedict/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from benedict.dicts import benedict, benediction +from benedict.dicts import benedict from benedict.metadata import ( __author__, __copyright__, __description__, __license__, __title__, __version__, diff --git a/benedict/dicts/__init__.py b/benedict/dicts/__init__.py index 0804eab..d4e98d1 100644 --- a/benedict/dicts/__init__.py +++ b/benedict/dicts/__init__.py @@ -6,15 +6,6 @@ from benedict.dicts.parse import ParseDict from benedict.utils import dict_util -def benediction(method): - def wrapper(*args, **kwargs): - value = method(*args, **kwargs) - if isinstance(value, dict) and not isinstance(value, benedict): - return benedict(value) - return value - return wrapper - - class benedict(IODict, KeypathDict, ParseDict): def __init__(self, *args, **kwargs): @@ -26,9 +17,8 @@ class benedict(IODict, KeypathDict, ParseDict): def clone(self): return dict_util.clone(self) - @benediction def copy(self): - return super(benedict, self).copy() + return benedict(super(benedict, self).copy()) def deepcopy(self): return self.clone() @@ -45,46 +35,6 @@ class benedict(IODict, KeypathDict, ParseDict): def flatten(self, separator='_'): return dict_util.flatten(self, separator) - @classmethod - @benediction - def fromkeys(cls, sequence, value=None): - return KeypathDict.fromkeys(sequence, value) - - @staticmethod - @benediction - def from_base64(s, subformat='json', encoding='utf-8', **kwargs): - return IODict.from_base64(s, subformat=subformat, encoding=encoding, **kwargs) - - @staticmethod - @benediction - def from_csv(s, columns=None, columns_row=True, **kwargs): - return IODict.from_csv(s, columns=columns, columns_row=columns_row, **kwargs) - - @staticmethod - @benediction - def from_json(s, **kwargs): - return IODict.from_json(s, **kwargs) - - @staticmethod - @benediction - def from_query_string(s, **kwargs): - return IODict.from_query_string(s, **kwargs) - - @staticmethod - @benediction - def from_toml(s, **kwargs): - return IODict.from_toml(s, **kwargs) - - @staticmethod - @benediction - def from_xml(s, **kwargs): - return IODict.from_xml(s, **kwargs) - - @staticmethod - @benediction - def from_yaml(s, **kwargs): - return IODict.from_yaml(s, **kwargs) - def invert(self, flat=False): return dict_util.invert(self, flat) diff --git a/benedict/dicts/io.py b/benedict/dicts/io.py index 73877e8..82e6426 100644 --- a/benedict/dicts/io.py +++ b/benedict/dicts/io.py @@ -52,37 +52,37 @@ class IODict(dict): io_util.write_file(filepath, s) return s - @staticmethod - def from_base64(s, subformat='json', encoding='utf-8', **kwargs): + @classmethod + def from_base64(cls, s, subformat='json', encoding='utf-8', **kwargs): kwargs['subformat'] = subformat kwargs['encoding'] = encoding - return IODict._decode(s, 'base64', **kwargs) + return cls(IODict._decode(s, 'base64', **kwargs)) - @staticmethod - def from_csv(s, columns=None, columns_row=True, **kwargs): + @classmethod + def from_csv(cls, s, columns=None, columns_row=True, **kwargs): kwargs['columns'] = columns kwargs['columns_row'] = columns_row - return IODict._decode(s, 'csv', **kwargs) + return cls(IODict._decode(s, 'csv', **kwargs)) - @staticmethod - def from_json(s, **kwargs): - return IODict._decode(s, 'json', **kwargs) + @classmethod + def from_json(cls, s, **kwargs): + return cls(IODict._decode(s, 'json', **kwargs)) - @staticmethod - def from_query_string(s, **kwargs): - return IODict._decode(s, 'query_string', **kwargs) + @classmethod + def from_query_string(cls, s, **kwargs): + return cls(IODict._decode(s, 'query_string', **kwargs)) - @staticmethod - def from_toml(s, **kwargs): - return IODict._decode(s, 'toml', **kwargs) + @classmethod + def from_toml(cls, s, **kwargs): + return cls(IODict._decode(s, 'toml', **kwargs)) - @staticmethod - def from_xml(s, **kwargs): - return IODict._decode(s, 'xml', **kwargs) + @classmethod + def from_xml(cls, s, **kwargs): + return cls(IODict._decode(s, 'xml', **kwargs)) - @staticmethod - def from_yaml(s, **kwargs): - return IODict._decode(s, 'yaml', **kwargs) + @classmethod + def from_yaml(cls, s, **kwargs): + return cls(IODict._decode(s, 'yaml', **kwargs)) def to_base64(self, subformat='json', encoding='utf-8', **kwargs): kwargs['subformat'] = subformat diff --git a/benedict/dicts/keypath.py b/benedict/dicts/keypath.py index f48edcd..2557b92 100644 --- a/benedict/dicts/keypath.py +++ b/benedict/dicts/keypath.py @@ -124,8 +124,9 @@ class KeypathDict(dict): @classmethod def fromkeys(cls, sequence, value=None): - d = KeypathDict() - for key in sequence: + f = dict.fromkeys(sequence, value) + d = cls() + for key, value in f.items(): d[key] = value return d diff --git a/tests/test_benedict.py b/tests/test_benedict.py index 23270a5..cb0d12a 100644 --- a/tests/test_benedict.py +++ b/tests/test_benedict.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from benedict import benedict, benediction +from benedict import benedict from datetime import datetime from decimal import Decimal @@ -9,33 +9,6 @@ import unittest class benedict_test_case(unittest.TestCase): - def test_benediction_decorator(self): - @benediction - def f1(): - return None - self.assertEqual(f1(), None) - - @benediction - def f2(): - return 1 - self.assertEqual(f2(), 1) - - @benediction - def f3(): - return 'ok' - self.assertEqual(f3(), 'ok') - - @benediction - def f4(): - return [] - self.assertEqual(f4(), []) - - @benediction - def f5(): - return {} - self.assertEqual(f5(), {}) - self.assertTrue(isinstance(f5(), benedict)) - def test_clean(self): d = { 'a': {},