diff --git a/pyangbind/lib/serialise.py b/pyangbind/lib/serialise.py index f1d4d78..d9c6659 100644 --- a/pyangbind/lib/serialise.py +++ b/pyangbind/lib/serialise.py @@ -36,7 +36,6 @@ from pyangbind.lib.yangtypes import YANGBool, safe_name - long = int diff --git a/pyangbind/lib/xpathhelper.py b/pyangbind/lib/xpathhelper.py index 02a5635..3479505 100644 --- a/pyangbind/lib/xpathhelper.py +++ b/pyangbind/lib/xpathhelper.py @@ -165,7 +165,7 @@ def _encode_path(self, path, mode="search", find_parent=False, normalise_namespa else: epath = "/" for i in range(startelem, lastelem): - (tagname, attributes) = self._tagname_attributes(parts[i], normalise_namespace=normalise_namespace) + tagname, attributes = self._tagname_attributes(parts[i], normalise_namespace=normalise_namespace) if ":" in tagname and normalise_namespace: tagname = tagname.split(":")[1] @@ -256,7 +256,7 @@ def register(self, object_path, object_ptr, caller=False): this_obj_id = str(uuid.uuid1()) self._library[this_obj_id] = object_ptr parent = object_path[:-1] - (tagname, attributes) = self._tagname_attributes(object_path[-1]) + tagname, attributes = self._tagname_attributes(object_path[-1]) if parent == []: parent_o = self._root diff --git a/pyangbind/lib/yangtypes.py b/pyangbind/lib/yangtypes.py index 7e67e27..aaff505 100644 --- a/pyangbind/lib/yangtypes.py +++ b/pyangbind/lib/yangtypes.py @@ -796,7 +796,7 @@ def add(self, *args, **kwargs): value = kwargs.pop("_v", None) - (k, keyargs) = self._generate_key(*args, **kwargs) + k, keyargs = self._generate_key(*args, **kwargs) if k in self._members: raise KeyError("%s is already defined as a list entry" % k) @@ -817,7 +817,7 @@ def add(self, *args, **kwargs): return k def delete(self, *args, **kwargs): - (k, _) = self._generate_key(*args, **kwargs) + k, _ = self._generate_key(*args, **kwargs) if self._path_helper: current_item = self._members[k] diff --git a/pyangbind/plugin/pybind.py b/pyangbind/plugin/pybind.py index 5d4f5b2..dc388bb 100644 --- a/pyangbind/plugin/pybind.py +++ b/pyangbind/plugin/pybind.py @@ -826,15 +826,12 @@ def get_children(ctx, fd, i_children, module, parent, path=str(), parent_cfg=Tru parent_descr = "" # Add more helper text. - nfd.write( - ''' """ + nfd.write(''' """ This class was auto-generated by the PythonClass plugin for PYANG from YANG module %s - based on the path %s. Each member element of the container is represented as a class variable - with a specific YANG type.%s - """\n''' - % (module.arg, (path if not path == "" else "/%s" % parent.arg), parent_descr) - ) + """\n''' % (module.arg, (path if not path == "" else "/%s" % parent.arg), parent_descr)) else: raise TypeError("unhandled keyword with children %s at %s" % (parent.keyword, parent.pos)) @@ -1009,15 +1006,12 @@ def get_children(ctx, fd, i_children, module, parent, path=str(), parent_cfg=Tru # set. # Generic class __init__, set up the path_helper if asked to. - nfd.write( - """ + nfd.write(""" _pybind_generated_by = 'container' - def __init__(self, *args, **kwargs):\n""" - ) + def __init__(self, *args, **kwargs):\n""") if ctx.opts.use_xpathhelper: - nfd.write( - """ + nfd.write(""" helper = kwargs.pop("path_helper", None) if helper is False: self._path_helper = False @@ -1027,17 +1021,13 @@ def __init__(self, *args, **kwargs):\n""" helper = getattr(self._parent, "_path_helper", False) self._path_helper = helper else: - self._path_helper = False\n""" - ) + self._path_helper = False\n""") else: - nfd.write( - """ - self._path_helper = False\n""" - ) + nfd.write(""" + self._path_helper = False\n""") if ctx.opts.use_extmethods: - nfd.write( - """ + nfd.write(""" extmethods = kwargs.pop("extmethods", None) if extmethods is False: self._extmethods = False @@ -1047,21 +1037,17 @@ def __init__(self, *args, **kwargs):\n""" extmethods = getattr(self._parent, "_extmethods", None) self._extmethods = extmethods else: - self._extmethods = False\n""" - ) + self._extmethods = False\n""") else: - nfd.write( - """ - self._extmethods = False\n""" - ) + nfd.write(""" + self._extmethods = False\n""") # Write out the classes that are stored locally as self.__foo where # foo is the safe YANG name. for c in classes: nfd.write(" self.%s = %s(%s)\n" % (classes[c]["name"], classes[c]["type"], classes[c]["arg"])) # Don't accept arguments to a container/list/submodule class - nfd.write( - """ + nfd.write(""" load = kwargs.pop("load", None) if args: if len(args) > 1: @@ -1081,20 +1067,16 @@ def __init__(self, *args, **kwargs):\n""" if load is None: setmethod(getattr(args[0], e)) else: - setmethod(getattr(args[0], e), load=load)\n""" - ) + setmethod(getattr(args[0], e), load=load)\n""") # A generic method to provide a path() method on each container, that gives # a path in the form of a list that describes the nodes in the hierarchy. - nfd.write( - """ + nfd.write(""" def _path(self): if hasattr(self, "_parent"): return self._parent._path()+[self._yang_name] else: - return %s\n""" - % path.split("/")[1:] - ) + return %s\n""" % path.split("/")[1:]) # For each element, write out a getter and setter method - with the doc # string of the element within the model. @@ -1103,19 +1085,15 @@ def _path(self): description_str = "" if i["description"]: description_str = "\n\n YANG Description: %s" % i["description"] - nfd.write( - ''' + nfd.write(''' def _get_%s(self): """ Getter method for %s, mapped from YANG variable %s (%s)%s """ return self.__%s - ''' - % (i["name"], i["name"], i["path"], i["origtype"], description_str, i["name"]) - ) + ''' % (i["name"], i["name"], i["path"], i["origtype"], description_str, i["name"])) - nfd.write( - ''' + nfd.write(''' def _set_%s(self, v, load=False): """ Setter method for %s, mapped from YANG variable %s (%s) @@ -1123,32 +1101,21 @@ def _set_%s(self, v, load=False): source YANG file, then _set_%s is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_%s() directly.%s - """''' - % (i["name"], i["name"], i["path"], i["origtype"], i["name"], i["name"], description_str) - ) + """''' % (i["name"], i["name"], i["path"], i["origtype"], i["name"], i["name"], description_str)) if keyval and i["yang_name"] in keyval: - nfd.write( - """ + nfd.write(""" parent = getattr(self, "_parent", None) if parent is not None and load is False: raise AttributeError("Cannot set keys directly when" + - " within an instantiated list")\n""" - ) - nfd.write( - """ + " within an instantiated list")\n""") + nfd.write(""" if hasattr(v, "_utype"): - v = v._utype(v)""" - ) - nfd.write( - """ + v = v._utype(v)""") + nfd.write(""" try: - t = %s(v,%s)""" - % (c_str["type"], c_str["arg"]) - ) - nfd.write( - """ - except (TypeError, ValueError):\n""" - ) + t = %s(v,%s)""" % (c_str["type"], c_str["arg"])) + nfd.write(""" + except (TypeError, ValueError):\n""") nfd.write( """ raise ValueError({ 'error-string': \"\"\"%s must be of a type compatible with %s\"\"\", @@ -1175,12 +1142,9 @@ def _set_%s(self, v, load=False): # be used. Generally, this is done in a choice where one branch needs to # be set to the default, but may be used wherever re-initialiation of # the object is required. - nfd.write( - """ + nfd.write(""" def _unset_%s(self): - self.__%s = %s(%s)\n\n""" - % (i["name"], i["name"], c_str["type"], c_str["arg"]) - ) + self.__%s = %s(%s)\n\n""" % (i["name"], i["name"], c_str["type"], c_str["arg"])) # When an element is read-only, write out the _set and _get methods, but # we don't actually make the property object accessible. This ensures that