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:
20
octodns/context.py
Normal file
20
octodns/context.py
Normal 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
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user