mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-03-22 10:38:37 +00:00
utils/serializer: Fix using incorrect loader and imports
- Ensure that the new loader is used when opening files to ensure that our custom constructors are used. - Fix missing imports
This commit is contained in:
parent
5652057adb
commit
ce59318e66
@ -59,10 +59,11 @@ to specify it explicitly.
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import json as _json
|
import json as _json
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict, Hashable
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
import yaml as _yaml # pylint: disable=wrong-import-order
|
import yaml as _yaml # pylint: disable=wrong-import-order
|
||||||
|
from yaml import MappingNode
|
||||||
try:
|
try:
|
||||||
from yaml import FullLoader as _yaml_loader
|
from yaml import FullLoader as _yaml_loader
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -236,7 +237,7 @@ class _WaYamlLoader(_yaml_loader):
|
|||||||
mapping = OrderedDict()
|
mapping = OrderedDict()
|
||||||
for key_node, value_node in node.value:
|
for key_node, value_node in node.value:
|
||||||
key = self.construct_object(key_node, deep=deep)
|
key = self.construct_object(key_node, deep=deep)
|
||||||
if not isinstance(key, collections.Hashable):
|
if not isinstance(key, Hashable):
|
||||||
raise ConstructorError("while constructing a mapping", node.start_mark,
|
raise ConstructorError("while constructing a mapping", node.start_mark,
|
||||||
"found unhashable key", key_node.start_mark)
|
"found unhashable key", key_node.start_mark)
|
||||||
value = self.construct_object(value_node, deep=deep)
|
value = self.construct_object(value_node, deep=deep)
|
||||||
@ -263,7 +264,7 @@ class yaml(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def load(fh, *args, **kwargs):
|
def load(fh, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return _yaml.load(fh, *args, Loader=_yaml_loader, **kwargs)
|
return _yaml.load(fh, *args, Loader=_WaYamlLoader, **kwargs)
|
||||||
except _yaml.YAMLError as e:
|
except _yaml.YAMLError as e:
|
||||||
lineno = None
|
lineno = None
|
||||||
if hasattr(e, 'problem_mark'):
|
if hasattr(e, 'problem_mark'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user