Commit bd0ab8a2 authored by Matias Guijarro's avatar Matias Guijarro
Browse files

fix issue #781

parent 31e6b66e
Pipeline #11123 passed with stages
in 34 minutes and 56 seconds
......@@ -47,10 +47,12 @@ Accessing the configured elements from python is easy
import os
import gc
import re
import weakref
import collections
import yaml
from yaml.loader import Reader, Scanner, Parser, Composer, SafeConstructor, Resolver
from bliss.config.conductor import client
from bliss.config import channels
......@@ -58,13 +60,34 @@ from bliss.config import channels
CONFIG = None
def load_cfg_fromstring(cfg_string):
return yaml.safe_load(cfg_string)
class BlissYamlResolver(Resolver):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
new_resolvers = collections.defaultdict(list)
for k, resolver in self.__class__.yaml_implicit_resolvers.items():
for item in resolver:
tag, regexp = item
if tag.endswith("2002:bool"):
regexp = re.compile(r"^(?:true|True|TRUE|false|False|FALSE)$", re.X)
new_resolvers[k].append((tag, regexp))
self.__class__.yaml_implicit_resolvers = new_resolvers
class BlissSafeConstructor(SafeConstructor):
bool_values = {"true": True, "false": False}
def load_cfg(filename):
cfg_string = client.get_config_file(filename)
return load_cfg_fromstring(cfg_string)
class BlissSafeYamlLoader(
Reader, Scanner, Parser, Composer, BlissSafeConstructor, BlissYamlResolver
):
def __init__(self, stream):
Reader.__init__(self, stream)
Scanner.__init__(self)
Parser.__init__(self)
Composer.__init__(self)
BlissSafeConstructor.__init__(self)
BlissYamlResolver.__init__(self)
def get_config(base_path="", timeout=3.):
......@@ -407,7 +430,7 @@ class Config:
continue
try:
d = yaml.safe_load(file_content)
d = yaml.load(file_content, BlissSafeYamlLoader)
except yaml.scanner.ScannerError as exp:
exp.note = "Error in YAML parsing:\n"
exp.note += "----------------\n"
......
......@@ -101,3 +101,10 @@ def test_inherited_package(beacon):
assert isinstance(beacon.get("dummy2"), DummyObject)
finally:
sys.path.pop()
def test_yaml_boolean(beacon):
m = beacon.get("fake_multiplexer_config")
assert m["outputs"][0]["ON"] == 1
assert m["outputs"][0]["OFF"] == 0
-
plugin: default
name: fake_multiplexer_config
boards:
- class: Opiom
name: opiom_eh
serial:
url: ser2net://lid312:29000/dev/ttyRP19
timeout: 30
program: 20180910_120725_fastscan
outputs:
- label: PCOEDGE
comment: Pco Edge trigger
board: opiom_eh
register: IMA
shift: 0
mask: 0x3
OFF: 0
ON: 1
COUNTER_CARD: 2
MUSST: 3
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment