Commits

Wolfgang Scherer  committed 29deaef

ws_docutils/span/directive.py: Python3 compatible exception handling.

  • Participants
  • Parent commits 1a6875c

Comments (0)

Files changed (2)

 
 setup(name='ws_docutils',
       description='WS Docutils Extensions',
-      version='0.3',
+      version='0.4',
       author='Wolfgang Scherer',
       author_email='sw@wiedenmann-seile.de',
       url='http://wolfmanx.bitbucket.org/ws-docutils/',

File ws_docutils/span/directive.py

                     error_handler=(self.state.document.settings.\
                                    input_encoding_error_handler),
                     handle_io_errors=None)
-            except IOError, error:
+            except IOError:
+                (t, error, tb) = sys.exc_info()
+                del(tb)
                 raise self.severe('Problems with "%s" directive path:\n%s.'
                                   % (self.name, error))
             try:
                 text = raw_file.read()
-            except UnicodeError, error:
+            except UnicodeError:
+                (t, error, tb) = sys.exc_info()
+                del(tb)
                 raise self.severe(
                     'Problem with "%s" directive:\n%s: %s'
                     % (self.name, error.__class__.__name__, error))
             import urllib2
             try:
                 raw_text = urllib2.urlopen(source).read()
-            except (urllib2.URLError, IOError, OSError), error:
+            except (urllib2.URLError, IOError, OSError):
+                (t, error, tb) = sys.exc_info()
+                del(tb)
                 raise self.severe(
                     'Problems with "%s" directive URL "%s":\n%s.'
                     % (self.name, self.options['url'], error))
                                input_encoding_error_handler))
             try:
                 text = raw_file.read()
-            except UnicodeError, error:
+            except UnicodeError:
+                (t, error, tb) = sys.exc_info()
+                del(tb)
                 raise self.severe(
                     'Problem with "%s" directive:\n%s: %s'
                     % (self.name, error.__class__.__name__, error))
                 lines = statemachine.string2lines(
                     text, tab_width, convert_whitespace=1)
                 text = '\n'.join(lines[startline:endline])
-        except UnicodeError, error:
+        except UnicodeError:
+            (t, error, tb) = sys.exc_info()
+            del(tb)
             raise self.severe(
                 'Problem with "%s" directive:\n%s: %s'
                 % (self.name, error.__class__.__name__, error))
                     error_handler=(self.state.document.settings.\
                                    input_encoding_error_handler),
                     handle_io_errors=None)
-            except IOError, error:
+            except IOError:
+                (t, error, tb) = sys.exc_info()
+                del(tb)
                 sys.stderr.write( "# {1:<{0}s}: [{2!s}]\n".format(
                     dbg_fwid if 'dbg_fwid' in globals() else 15,
                     '||:div:||', 'error' ))
                                   % (self.name, error))
             try:
                 text = raw_file.read()
-            except UnicodeError, error:
+            except UnicodeError:
+                (t, error, tb) = sys.exc_info()
+                del(tb)
                 sys.stderr.write( "# {1:<{0}s}: [{2!s}]\n".format(
                     dbg_fwid if 'dbg_fwid' in globals() else 15,
                     '||:div:||', 'error' ))
             import urllib2
             try:
                 raw_text = urllib2.urlopen(source).read()
-            except (urllib2.URLError, IOError, OSError), error:
+            except (urllib2.URLError, IOError, OSError):
+                (t, error, tb) = sys.exc_info()
+                del(tb)
                 sys.stderr.write( "# {1:<{0}s}: [{2!s}]\n".format(
                     dbg_fwid if 'dbg_fwid' in globals() else 15,
                     '||:div:||', 'error' ))
                                input_encoding_error_handler))
             try:
                 text = raw_file.read()
-            except UnicodeError, error:
+            except UnicodeError:
+                (t, error, tb) = sys.exc_info()
+                del(tb)
                 sys.stderr.write( "# {1:<{0}s}: [{2!s}]\n".format(
                     dbg_fwid if 'dbg_fwid' in globals() else 15,
                     '||:div:||', 'error' ))
                 lines = statemachine.string2lines(
                     text, tab_width, convert_whitespace=1)
                 text = '\n'.join(lines[startline:endline])
-        except UnicodeError, error:
+        except UnicodeError:
+            (t, error, tb) = sys.exc_info()
+            del(tb)
             sys.stderr.write( "# {1:<{0}s}: [{2!s}]\n".format(
                     dbg_fwid if 'dbg_fwid' in globals() else 15,
                     '||:div:||', 'error' ))
             div_node = nodes.div('', *[], **attributes)
             try:
                 self.state.nested_parse(content, offset, div_node, 1)
-            except Exception as e:
+            except Exception:
+                (t, error, tb) = sys.exc_info()
+                del(tb)
                 sys.stderr.write( "# {1:<{0}s}: [{2!r}]\n".format(
                         dbg_fwid if 'dbg_fwid' in globals() else 15,
-                        e.__class__.__name__, dir(e)))
+                        error.__class__.__name__, dir(e)))
                 sys.stderr.write( "# {1:<{0}s}: [{2!s}]\n".format(
                         dbg_fwid if 'dbg_fwid' in globals() else 15,
                         '||:div:||', 'error below' ))
-                raise e
+                raise error
             sys.stderr.write( "# {1:<{0}s}: [{2!s}]\n".format(
                     dbg_fwid if 'dbg_fwid' in globals() else 15,
                     'children', div_node.children ))
 
 # :ide: COMPILE: Run w/o args
 # . (progn (save-buffer) (compile (concat "python ./" (file-name-nondirectory (buffer-file-name)) " ")))
+
 #
 # Local Variables:
 # mode: python