summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2023-05-05 14:41:19 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2023-05-08 21:58:56 +0200
commitbbe132092ed299275f9da7a86319fdf03b31861f (patch)
tree2ca8475b79dc325965926151165aa0eff4e1c565
parentitems: Add "initialize-links" option to ItemCache (diff)
downloadrtems-central-bbe132092ed299275f9da7a86319fdf03b31861f.tar.bz2
items: Use CSafeLoader if available
-rw-r--r--rtemsspec/items.py7
-rw-r--r--rtemsspec/tests/test_items_itemcache.py6
2 files changed, 7 insertions, 6 deletions
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index 1bc29dec..9beb180d 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -37,6 +37,11 @@ from typing import Any, Callable, Dict, Iterable, Iterator, List, Match, \
import json
import yaml
+try:
+ from yaml import CSafeLoader as SafeLoader
+except ImportError: # pragma: no cover
+ from yaml import SafeLoader # type: ignore
+
class ItemGetValueContext(NamedTuple):
""" Context used to get an item value. """
@@ -681,7 +686,7 @@ def _gather_spec_refinements(item: Item) -> Optional[_SpecType]:
def _load_yaml_data(path: str, uid: str) -> Any:
with open(path, "r", encoding="utf-8") as src:
try:
- data = yaml.safe_load(src.read())
+ data = yaml.load(src.read(), Loader=SafeLoader)
except yaml.YAMLError as err:
msg = ("YAML error while loading specification item file "
f"'{path}': {str(err)}")
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index 6cb35e3e..ba1ed859 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -108,11 +108,7 @@ def test_load_link_error(tmpdir):
def test_load_yaml_error(tmpdir):
config = create_item_cache_config_and_copy_spec(tmpdir,
"spec-item-cache-3")
- match = r"""YAML error while loading specification item file '.*invalid.yml': while parsing a block mapping
-expected <block end>, but found ':'
- in "<unicode string>", line 1, column 1:
- :
- \^"""
+ match = r"YAML error while loading specification item file '.*invalid.yml': while parsing a block mapping"
with pytest.raises(IOError, match=match):
ItemCache(config)