2019-06-10 09:59:16 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from benedict.dicts.keypath import KeypathDict
|
|
|
|
from benedict.dicts.parse import ParseDict
|
|
|
|
|
|
|
|
from copy import deepcopy
|
|
|
|
|
|
|
|
|
|
|
|
class benedict(KeypathDict, ParseDict):
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(benedict, self).__init__(*args, **kwargs)
|
|
|
|
|
2019-06-10 12:40:05 +00:00
|
|
|
@staticmethod
|
|
|
|
def cast(val):
|
|
|
|
if isinstance(val, dict) and not isinstance(val, benedict):
|
|
|
|
return benedict(val)
|
|
|
|
else:
|
|
|
|
return val
|
|
|
|
|
2019-06-10 09:59:16 +00:00
|
|
|
def copy(self):
|
2019-06-10 12:40:05 +00:00
|
|
|
return benedict.cast(
|
2019-06-10 09:59:16 +00:00
|
|
|
super(benedict, self).copy())
|
|
|
|
|
|
|
|
def deepcopy(self):
|
2019-06-10 12:40:05 +00:00
|
|
|
return benedict.cast(
|
2019-06-10 09:59:16 +00:00
|
|
|
deepcopy(self))
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def fromkeys(cls, sequence, value=None):
|
2019-06-10 12:40:05 +00:00
|
|
|
return benedict.cast(
|
2019-06-10 09:59:16 +00:00
|
|
|
KeypathDict.fromkeys(sequence, value))
|
|
|
|
|
2019-06-10 12:40:05 +00:00
|
|
|
def __getitem__(self, key):
|
|
|
|
return benedict.cast(
|
|
|
|
super(benedict, self).__getitem__(key))
|
|
|
|
|
|
|
|
def get(self, key, default=None):
|
|
|
|
return benedict.cast(
|
|
|
|
super(benedict, self).get(key, default))
|
|
|
|
|
|
|
|
def pop(self, key, default=None):
|
|
|
|
return benedict.cast(
|
|
|
|
super(benedict, self).pop(key, default))
|
|
|
|
|
|
|
|
def setdefault(self, key, default=None):
|
|
|
|
return benedict.cast(
|
|
|
|
super(benedict, self).setdefault(key, default))
|
|
|
|
|