mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Implement black formatting
This commit is contained in:
@@ -2,8 +2,12 @@
|
||||
#
|
||||
#
|
||||
|
||||
from __future__ import absolute_import, division, print_function, \
|
||||
unicode_literals
|
||||
from __future__ import (
|
||||
absolute_import,
|
||||
division,
|
||||
print_function,
|
||||
unicode_literals,
|
||||
)
|
||||
|
||||
from natsort import natsort_keygen
|
||||
from yaml import SafeDumper, SafeLoader, load, dump
|
||||
@@ -16,7 +20,6 @@ _natsort_key = natsort_keygen()
|
||||
# Found http://stackoverflow.com/a/21912744 which guided me on how to hook in
|
||||
# here
|
||||
class SortEnforcingLoader(SafeLoader):
|
||||
|
||||
def _construct(self, node):
|
||||
self.flatten_mapping(node)
|
||||
ret = self.construct_pairs(node)
|
||||
@@ -25,14 +28,18 @@ class SortEnforcingLoader(SafeLoader):
|
||||
for key in keys:
|
||||
expected = keys_sorted.pop(0)
|
||||
if key != expected:
|
||||
raise ConstructorError(None, None, 'keys out of order: '
|
||||
f'expected {expected} got {key} at ' +
|
||||
str(node.start_mark))
|
||||
raise ConstructorError(
|
||||
None,
|
||||
None,
|
||||
'keys out of order: '
|
||||
f'expected {expected} got {key} at ' + str(node.start_mark),
|
||||
)
|
||||
return dict(ret)
|
||||
|
||||
|
||||
SortEnforcingLoader.add_constructor(SortEnforcingLoader.DEFAULT_MAPPING_TAG,
|
||||
SortEnforcingLoader._construct)
|
||||
SortEnforcingLoader.add_constructor(
|
||||
SortEnforcingLoader.DEFAULT_MAPPING_TAG, SortEnforcingLoader._construct
|
||||
)
|
||||
|
||||
|
||||
def safe_load(stream, enforce_order=True):
|
||||
@@ -62,7 +69,7 @@ def safe_dump(data, fh, **options):
|
||||
'indent': 2,
|
||||
'default_style': '',
|
||||
'default_flow_style': False,
|
||||
'explicit_start': True
|
||||
'explicit_start': True,
|
||||
}
|
||||
kwargs.update(options)
|
||||
dump(data, fh, SortingDumper, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user