diff --git a/octodns/context.py b/octodns/context.py new file mode 100644 index 0000000..eec8ca1 --- /dev/null +++ b/octodns/context.py @@ -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 diff --git a/octodns/yaml.py b/octodns/yaml.py index 6cdeaf1..09433d9 100644 --- a/octodns/yaml.py +++ b/octodns/yaml.py @@ -7,17 +7,9 @@ from yaml import SafeDumper, SafeLoader, dump, load from yaml.constructor import ConstructorError from yaml.representer import SafeRepresenter -_natsort_key = natsort_keygen() - +from .context import ContextDict -# 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 +_natsort_key = natsort_keygen() class ContextLoader(SafeLoader):