def _parse_path(self, path): if not path: path = Path_.from_string(path) elif isinstance(path, Path_): path = path elif isinstance(path, str): path = Path_.from_string(path) elif isinstance(path, (list, tuple)): path = Path_.from_string("/".join(path)) else: raise ValueError("Failed to parse path: %s" % str(path)) return path.raw
def _build_update(self, update): if isinstance(update, (Update_, Path_)): update = update if isinstance(update, str): update = Path_.from_string(update) elif isinstance(update, (list, tuple)): update = Update_.from_keyval(update) return update.raw
def test_gnmi_path(): paths = [ "/system/nsftuff", "origin:/some/other/path", "/path/with/some[key=val-ue]/more[key=ssss]" ] for path in paths: pobj = Path_.from_string(path) pstr = pobj.to_string() [(e.name, e.key) for e in pobj.elem] assert path == pstr
def test_gnmi_path(): paths = [ "/system/nsftuff", "origin:/some/other/path", "/path/with/some[key=val-ue][df=sdf]/more[key=ssss]" ] for path in paths: pobj = Path_.from_string(path) pstr = pobj.to_string() print([(e.name, e.key) for e in pobj.elements]) print(pstr) print(str(path)) print(pobj.raw)
def _parse_path( self, path: Optional[Union[Path_, pb.Path, str, list, tuple]]) -> pb.Path: if path is None: path = "" elif isinstance(path, (list, tuple)): path = "/".join(list(path)) if isinstance(path, str): return Path_.from_string(path).raw elif isinstance(path, Path_): return path.raw elif isinstance(path, pb.Path): return path else: raise ValueError("Failed to parse path: %s" % str(path))
def paths(): return [Path_.from_string(p) for p in GNMI_PATHS.split(";")]