clean etherlab: pep8, W602 deprecated form of raising exception
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Sat, 29 Sep 2018 13:44:02 +0300
changeset 2378 7aa47c09f8f5
parent 2377 88a9d64560d3
child 2379 015b724c30a5
clean etherlab: pep8, W602 deprecated form of raising exception
etherlab/CommonEtherCATFunction.py
etherlab/EthercatCFileGenerator.py
etherlab/EthercatSlave.py
etherlab/etherlab.py
--- a/etherlab/CommonEtherCATFunction.py	Sat Sep 29 13:34:06 2018 +0300
+++ b/etherlab/CommonEtherCATFunction.py	Sat Sep 29 13:44:02 2018 +0300
@@ -28,7 +28,7 @@
         return int(value.replace("#", "0"), 16)
 
     except Exception:
-        raise ValueError, "Invalid value for HexDecValue \"%s\"" % value
+        raise ValueError("Invalid value for HexDecValue \"%s\"" % value)
 
 
 def ExtractName(names, default=None):
--- a/etherlab/EthercatCFileGenerator.py	Sat Sep 29 13:34:06 2018 +0300
+++ b/etherlab/EthercatCFileGenerator.py	Sat Sep 29 13:44:02 2018 +0300
@@ -72,7 +72,8 @@
 def ConfigureVariable(entry_infos, str_completion):
     entry_infos["data_type"] = DATATYPECONVERSION.get(entry_infos["var_type"], None)
     if entry_infos["data_type"] is None:
-        raise ValueError, _("Type of location \"%s\" not yet supported!") % entry_infos["var_name"]
+        msg = _("Type of location \"%s\" not yet supported!") % entry_infos["var_name"]
+        raise ValueError(msg)
 
     if not entry_infos.get("no_decl", False):
         if "real_var" in entry_infos:
@@ -165,9 +166,11 @@
                     entry_infos["infos"][4].append(name)
                     return entry_infos["infos"][2]
                 else:
-                    raise ValueError, _("Output variables can't be defined with different locations (%s and %s)") % (entry_infos["infos"][2], name)
+                    msg = _("Output variables can't be defined with different locations (%s and %s)") \
+                          % (entry_infos["infos"][2], name)
+                    raise ValueError(msg)
         else:
-            raise ValueError, _("Definition conflict for location \"%s\"") % name
+            raise ValueError(_("Definition conflict for location \"%s\"") % name)
 
     def GenerateCFile(self, filepath, location_str, master_number):
 
@@ -217,7 +220,9 @@
             # Extract slave device informations
             device, module_extra_params = self.Controler.GetModuleInfos(type_infos)
             if device is None:
-                raise ValueError, _("No informations found for device %s!") % (type_infos["device_type"])
+                msg = _("No informations found for device %s!") \
+                      % (type_infos["device_type"])
+                raise ValueError(msg)
 
             # Extract slaves variables to be mapped
             slave_variables = self.UsedVariables.get(slave_idx, {})
@@ -393,13 +398,13 @@
                                 message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"]
                                 if (self.Controler.GetSizeOfType(entry_infos["var_type"]) !=
                                     self.Controler.GetSizeOfType(entry_type)):
-                                    raise ValueError, message
+                                    raise ValueError(message)
                                 else:
                                     self.Controler.GetCTRoot().logger.write_warning(_("Warning: ") + message + "\n")
 
                             if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or
                                 entry_infos["dir"] == "Q" and pdo_type != "Outputs"):
-                                raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"]
+                                raise ValueError(_("Wrong direction for location \"%s\"!") % entry_infos["var_name"])
 
                             ConfigureVariable(entry_infos, str_completion)
 
@@ -428,7 +433,7 @@
                                 if sync_manager["name"] == pdo_type:
                                     sm = sm_idx
                         if sm is None:
-                            raise ValueError, _("No sync manager available for %s pdo!") % pdo_type
+                            raise ValueError(_("No sync manager available for %s pdo!") % pdo_type)
 
                         sync_managers[sm]["pdos_number"] += 1
                         sync_managers[sm]["pdos"].append(
@@ -460,8 +465,9 @@
                         if not entry_declaration["mapped"]:
                             entry = device_entries.get((index, subindex), None)
                             if entry is None:
-                                raise ValueError, _("Unknown entry index 0x%4.4x, subindex 0x%2.2x for device %s") % \
-                                                 (index, subindex, type_infos["device_type"])
+                                msg = _("Unknown entry index 0x%4.4x, subindex 0x%2.2x for device %s") \
+                                      % (index, subindex, type_infos["device_type"])
+                                raise ValueError(msg)
 
                             entry_infos = {
                                 "index": index,
@@ -479,7 +485,7 @@
                                 message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"]
                                 if (self.Controler.GetSizeOfType(entry_infos["var_type"]) !=
                                     self.Controler.GetSizeOfType(entry["Type"])):
-                                    raise ValueError, message
+                                    raise ValueError(message)
                                 else:
                                     self.Controler.GetCTRoot().logger.write_warning(message + "\n")
 
@@ -488,10 +494,13 @@
                             elif entry_infos["dir"] == "Q" and entry["PDOMapping"] in ["R", "RT"]:
                                 pdo_type = "Outputs"
                             else:
-                                raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"]
+                                msg = _("Wrong direction for location \"%s\"!") \
+                                      % entry_infos["var_name"]
+                                raise ValueError(msg)
 
                             if pdo_type not in dynamic_pdos:
-                                raise ValueError, _("No Sync manager defined for %s!") % pdo_type
+                                msg = _("No Sync manager defined for %s!") % pdo_type
+                                raise ValueError(msg)
 
                             ConfigureVariable(entry_infos, str_completion)
 
@@ -501,7 +510,7 @@
                                 while dynamic_pdos[pdo_type]["current_index"] in pdos_index:
                                     dynamic_pdos[pdo_type]["current_index"] += 1
                                 if dynamic_pdos[pdo_type]["current_index"] >= dynamic_pdos[pdo_type]["max_index"]:
-                                    raise ValueError, _("No more free PDO index available for %s!") % pdo_type
+                                    raise ValueError(_("No more free PDO index available for %s!") % pdo_type)
                                 pdos_index.append(dynamic_pdos[pdo_type]["current_index"])
 
                                 dynamic_pdos_number += 1
--- a/etherlab/EthercatSlave.py	Sat Sep 29 13:34:06 2018 +0300
+++ b/etherlab/EthercatSlave.py	Sat Sep 29 13:44:02 2018 +0300
@@ -40,7 +40,7 @@
     try:
         return int(value.replace("#", "0"), 16)
     except Exception:
-        raise ValueError, "Invalid value for HexDecValue \"%s\"" % value
+        raise ValueError("Invalid value for HexDecValue \"%s\"" % value)
 
 
 def GenerateHexDecValue(value, base=10):
@@ -49,7 +49,7 @@
     elif base == 16:
         return "#x%.8x" % value
     else:
-        raise ValueError, "Not supported base"
+        raise ValueError("Not supported base")
 
 
 def ExtractName(names, default=None):
--- a/etherlab/etherlab.py	Sat Sep 29 13:34:06 2018 +0300
+++ b/etherlab/etherlab.py	Sat Sep 29 13:44:02 2018 +0300
@@ -241,7 +241,7 @@
                     for device in self.devices_xpath(self.modules_infos):
                         device_group = device.getGroupType()
                         if device_group not in vendor_category["groups"]:
-                            raise ValueError, "Not such group \"%\"" % device_group
+                            raise ValueError("Not such group \"%\"" % device_group)
                         vendor_category["groups"][device_group]["devices"].append(
                             (device.getType().getcontent(), device))