1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Move ContextDict into octodns.context

This commit is contained in:
Ross McFarland
2023-07-29 12:10:00 -07:00
parent 31d8d57e79
commit 6be9bb9c6d
2 changed files with 22 additions and 10 deletions

20
octodns/context.py Normal file
View File

@@ -0,0 +1,20 @@
#
#
#
class ContextDict(dict):
'''
This is used by things that call `Record.new` to pass in a `data`
dictionary that includes some context as to where the data came from to be
printed along with exceptions or validations of the record.
It breaks lots of stuff if we stored the context in an extra key and the
python `dict` object doesn't allow you to set attributes on the object so
this is a very thin wrapper around `dict` that allows us to have a context
attribute.
'''
def __init__(self, *args, context=None, **kwargs):
super().__init__(*args, **kwargs)
self.context = context

View File

@@ -7,19 +7,11 @@ from yaml import SafeDumper, SafeLoader, dump, load
from yaml.constructor import ConstructorError
from yaml.representer import SafeRepresenter
from .context import ContextDict
_natsort_key = natsort_keygen()
# TODO: where should this live
class ContextDict(dict):
# can't assign attributes to plain dict objects and it breaks lots of stuff
# if we put the context into the dict data itself
def __init__(self, *args, context=None, **kwargs):
super().__init__(*args, **kwargs)
self.context = context
class ContextLoader(SafeLoader):
def _pairs(self, node):
self.flatten_mapping(node)