Closed igrush closed 9 months ago
I have discovered the issue. This seems to be an artifact of the 2 to 3 python conversion. In the RestrictedClassType in yangtypes.py, in the method mp_check there is a type check that looks for six types.
def mp_check(value):
if not isinstance(value, six.string_types + (six.text_type,)):
return False
if regex.match(convert_regexp(regexp), value):
return True
return False
return mp_check
However if the type passed in is a Restricted type it is passed in as an lxml.objectify.StringElement. This fails the check. If instead of the lxml.objectify.StringElement you use the lxml.objectify.StringElement.pyval, it will work.
My solution was to add a type check before the call to mp_check. in class RestrictedClass(base_type):
if val is not False:
for test in self._restriction_tests:
passed = False
if isinstance(val, objectify.StringElement):
val = val.pyval
if test(val) is not False:
passed = True
break
if not passed:
raise ValueError("%s does not match a restricted type" % val)
Hi,
Could you please try again with recent versions of pyangbind?
Python2 was deprecated, and pyangbind is working fine with python3.
Thanks.
Closing issue without recent updates.
How I got here I am attempting to decode from XML into a pyangbind object. Here is a small code sample.
pybind_eg is the directory containing the bindings. They were generated with --split-class-dir and --use-xpathhelper, so the binding code is mainly in the init.py files. I have attached pybind_eg.zip with the bindings.
This is the yang that describes router-id:
The setter method _set_router_id(self, v, load=False) in the binding is failing. The router-id is of type inet:ip-address for which there is no match of type to a restricted type in YANGDynClass.
So this fails with the error message:
I get a couple of follow up errors with this message.
pybind_eg.zip