[telemetry] python3 conversion: raise_six

Convert telemetry to Python 3 style applying fixers on telemetry/:
  python -m modernize -w -f raise_six .

This is one of the CLs converting Telemetry to be compatible for Python3. The conversion utilizes the modernize module: https://pypi.org/project/modernize/

Bug: chromium:1198408
Change-Id: Ief3c0bbbd912c59dcbe42dda5fc3c75f8e4cd03f
Reviewed-on: https://chromium-review.googlesource.com/c/catapult/+/2844930
Commit-Queue: Wenbin Zhang <wenbinzhang@google.com>
Reviewed-by: John Chen <johnchen@chromium.org>
diff --git a/telemetry/telemetry/core/platform.py b/telemetry/telemetry/core/platform.py
index 5a26c7b..e279669 100644
--- a/telemetry/telemetry/core/platform.py
+++ b/telemetry/telemetry/core/platform.py
@@ -5,7 +5,6 @@
 import logging as real_logging
 import os
 import subprocess
-import sys
 import time
 import six
 
@@ -67,10 +66,9 @@
                                                            finder_options))
         return _REMOTE_PLATFORMS[device.guid]
     return None
-  except Exception:
-    current_exception = sys.exc_info()
+  except Exception: # pylint: disable=broad-except
     logging.error('Fail to create platform instance for %s.', device.name)
-    raise current_exception[0], current_exception[1], current_exception[2]
+    raise
 
 
 class Platform(object):
diff --git a/telemetry/telemetry/internal/actions/wait.py b/telemetry/telemetry/internal/actions/wait.py
index 17e6dbc..9dc14a1 100644
--- a/telemetry/telemetry/internal/actions/wait.py
+++ b/telemetry/telemetry/internal/actions/wait.py
@@ -3,6 +3,7 @@
 # found in the LICENSE file.
 
 import sys
+import six
 
 from telemetry.internal.actions import page_action
 
@@ -17,7 +18,9 @@
                             timeout_in_seconds=self.timeout)
     except py_utils.TimeoutException as e:
       # Rethrow with the original stack trace for better debugging.
-      raise py_utils.TimeoutException, \
+      six.reraise(
+          py_utils.TimeoutException,
           py_utils.TimeoutException(
-              'Timeout while waiting for element.\n' + e.message), \
+              'Timeout while waiting for element.\n' + e.message),
           sys.exc_info()[2]
+      )
diff --git a/telemetry/telemetry/internal/backends/chrome_inspector/devtools_client_backend.py b/telemetry/telemetry/internal/backends/chrome_inspector/devtools_client_backend.py
index 0afe9b5..2ed65c6 100644
--- a/telemetry/telemetry/internal/backends/chrome_inspector/devtools_client_backend.py
+++ b/telemetry/telemetry/internal/backends/chrome_inspector/devtools_client_backend.py
@@ -6,6 +6,7 @@
 import re
 import socket
 import sys
+import six
 
 from py_utils import exc_util
 from py_utils import retry_util
@@ -307,7 +308,7 @@
     except devtools_http.DevToolsClientUrlError:
       error = TabNotFoundError(
           'Unable to close tab, tab id not found: %s' % tab_id)
-      raise error, None, sys.exc_info()[2]
+      six.reraise(error, None, sys.exc_info()[2])
 
   def ActivateTab(self, tab_id, timeout):
     """Activates the tab with the given id.
@@ -322,7 +323,7 @@
     except devtools_http.DevToolsClientUrlError:
       error = TabNotFoundError(
           'Unable to activate tab, tab id not found: %s' % tab_id)
-      raise error, None, sys.exc_info()[2]
+      six.reraise(error, None, sys.exc_info()[2])
 
   def GetUrl(self, tab_id):
     """Returns the URL of the tab with |tab_id|, as reported by devtools.
diff --git a/telemetry/telemetry/internal/backends/chrome_inspector/devtools_http.py b/telemetry/telemetry/internal/backends/chrome_inspector/devtools_http.py
index af7b588..116703b 100644
--- a/telemetry/telemetry/internal/backends/chrome_inspector/devtools_http.py
+++ b/telemetry/telemetry/internal/backends/chrome_inspector/devtools_http.py
@@ -6,6 +6,7 @@
 import json
 import socket
 import sys
+import six
 
 import six.moves.http_client  # pylint: disable=import-error
 
@@ -44,7 +45,7 @@
       self._conn = six.moves.http_client.HTTPConnection(
           host_port, timeout=timeout)
     except (socket.error, six.moves.http_client.HTTPException) as e:
-      raise DevToolsClientConnectionError, (e,), sys.exc_info()[2]
+      six.reraise(DevToolsClientConnectionError, (e,), sys.exc_info()[2])
 
   def Disconnect(self):
     """Closes the HTTP connection."""
@@ -54,7 +55,7 @@
     try:
       self._conn.close()
     except (socket.error, six.moves.http_client.HTTPException) as e:
-      raise DevToolsClientConnectionError, (e,), sys.exc_info()[2]
+      six.reraise(DevToolsClientConnectionError, (e,), sys.exc_info()[2])
     finally:
       self._conn = None
 
@@ -92,8 +93,8 @@
     except (socket.error, six.moves.http_client.HTTPException) as e:
       self.Disconnect()
       if isinstance(e, socket.error) and e.errno == errno.ECONNREFUSED:
-        raise DevToolsClientUrlError, (e,), sys.exc_info()[2]
-      raise DevToolsClientConnectionError, (e,), sys.exc_info()[2]
+        six.reraise(DevToolsClientUrlError, (e,), sys.exc_info()[2])
+      six.reraise(DevToolsClientConnectionError, (e,), sys.exc_info()[2])
 
   def RequestJson(self, path, timeout=30):
     """Sends a request and parse the response as JSON.
diff --git a/telemetry/telemetry/internal/backends/chrome_inspector/inspector_backend.py b/telemetry/telemetry/internal/backends/chrome_inspector/inspector_backend.py
index acdf6f2..e13d306 100644
--- a/telemetry/telemetry/internal/backends/chrome_inspector/inspector_backend.py
+++ b/telemetry/telemetry/internal/backends/chrome_inspector/inspector_backend.py
@@ -325,11 +325,14 @@
             'Exception thrown when trying to capture console output: %s' %
             repr(e))
       # Rethrow with the original stack trace for better debugging.
-      raise py_utils.TimeoutException, \
+      six.reraise(
+          py_utils.TimeoutException,
           py_utils.TimeoutException(
-              'Timeout after %ss while waiting for JavaScript:' % timeout +
-              condition + '\n' +  e.message + '\n' + debug_message), \
+              'Timeout after %ss while waiting for JavaScript:'
+              % timeout + condition + '\n' +  e.message + '\n' + debug_message
+          ),
           sys.exc_info()[2]
+      )
 
 
   def AddTimelineMarker(self, marker):
@@ -698,7 +701,7 @@
     new_error.AddDebuggingMessage(original_error_msg)
     self._AddDebuggingInformation(new_error)
 
-    raise new_error, None, sys.exc_info()[2]
+    six.reraise(new_error, None, sys.exc_info()[2])
 
   def _AddDebuggingInformation(self, error):
     """Adds debugging information to error.
diff --git a/telemetry/telemetry/testing/browser_test_case.py b/telemetry/telemetry/testing/browser_test_case.py
index 9d5443f..8658382 100644
--- a/telemetry/telemetry/testing/browser_test_case.py
+++ b/telemetry/telemetry/testing/browser_test_case.py
@@ -5,7 +5,6 @@
 from functools import wraps
 import logging
 import os
-import sys
 import types
 import unittest
 import six
@@ -37,18 +36,12 @@
     def WrappedMethod(self):
       try:  # pylint: disable=broad-except
         method(self)
-      except Exception:
-        exc_info = sys.exc_info()
-
+      except Exception: # pylint: disable=broad-except
         if self._browser:
           self._browser.DumpStateUponFailure()
         else:
           logging.warning('Cannot dump browser state: No browser.')
-
-        # Re-raise the original exception. Note that we can't just use 'raise'
-        # without any arguments because an exception might have been thrown when
-        # dumping the state of the browser.
-        raise exc_info[0], exc_info[1], exc_info[2]
+        raise
     return WrappedMethod