Fix invalid python3 syntax
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Wed, 13 Mar 2019 10:19:30 +0300
changeset 2536 2747d6e72eb8
parent 2535 0fab0af57950
child 2537 eb4a4cc41914
Fix invalid python3 syntax

Syntax checking using python3 ...
Python 3.7.2+
File "./connectors/PYRO/__init__.py", line 76
except Exception, e:
^
SyntaxError: invalid syntax

Syntax error in ./connectors/PYRO/__init__.py
File "./connectors/PYRO/PSK_Adapter.py", line 40
except ProtocolError, x:
^
SyntaxError: invalid syntax

Syntax error in ./s.py
File "./runtime/Worker.py", line 67
raise _job.exc_info[0], _job.exc_info[1], _job.exc_info[2]
^
SyntaxError: invalid syntax
connectors/PYRO/PSK_Adapter.py
connectors/PYRO/__init__.py
runtime/Worker.py
--- a/connectors/PYRO/PSK_Adapter.py	Wed Mar 13 10:02:11 2019 +0300
+++ b/connectors/PYRO/PSK_Adapter.py	Wed Mar 13 10:19:30 2019 +0300
@@ -37,7 +37,7 @@
                 # receive the authentication challenge string, and use that to build the actual identification string.
                 try:
                     authChallenge = self.recvAuthChallenge(conn)
-                except ProtocolError, x:
+                except ProtocolError as x:
                     # check if we were denied
                     if hasattr(x, "partialMsg") and x.partialMsg[:len(self.denyMSG)] == self.denyMSG:
                         raise ConnectionDeniedError(Pyro.constants.deniedReasons[int(x.partialMsg[-1])])
--- a/connectors/PYRO/__init__.py	Wed Mar 13 10:02:11 2019 +0300
+++ b/connectors/PYRO/__init__.py	Wed Mar 13 10:19:30 2019 +0300
@@ -73,7 +73,7 @@
     # Try to get the proxy object
     try:
         RemotePLCObjectProxy = Pyro.core.getAttrProxyForURI(schemename + "://" + location + "/PLCObject")
-    except Exception, e:
+    except Exception as e:
         confnodesroot.logger.write_error(
             _("Connection to {loc} failed with exception {ex}\n").format(
                 loc=location, exo=str(e)))
--- a/runtime/Worker.py	Wed Mar 13 10:02:11 2019 +0300
+++ b/runtime/Worker.py	Wed Mar 13 10:19:30 2019 +0300
@@ -51,6 +51,16 @@
         self.free = Condition(self.mutex)
         self.job = None
 
+    def reraise(self, job):
+        """
+        reraise exception happend in a job
+        @param job: job where original exception happend
+        """
+        exc_type = job.exc_info[0]
+        exc_value = job.exc_info[1]
+        exc_traceback = job.exc_info[2]
+        six.reraise(exc_type, exc_value, exc_traceback)
+
     def runloop(self, *args, **kwargs):
         """
         meant to be called by worker thread (blocking)
@@ -60,11 +70,8 @@
         if args or kwargs:
             _job = job(*args, **kwargs)
             _job.do()
-            if _job.success:
-                # result is ignored
-                pass
-            else:
-                raise _job.exc_info[0], _job.exc_info[1], _job.exc_info[2]
+            if not _job.success:
+                self.reraise(_job)
 
         while not self._finish:
             self.todo.wait()
@@ -106,10 +113,7 @@
         if _job.success:
             return _job.result
         else:
-            exc_type = _job.exc_info[0]
-            exc_value = _job.exc_info[1]
-            exc_traceback = _job.exc_info[2]
-            six.reraise(exc_type, exc_value, exc_traceback)
+            self.reraise(_job)
 
     def quit(self):
         """