Browse Source

Move ContextDict into octodns.context

pull/1029/head
Ross McFarland 2 years ago
parent
commit
6be9bb9c6d
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 22 additions and 10 deletions
  1. +20
    -0
      octodns/context.py
  2. +2
    -10
      octodns/yaml.py

+ 20
- 0
octodns/context.py 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

+ 2
- 10
octodns/yaml.py View File

@ -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):


Loading…
Cancel
Save