]> granicus.if.org Git - zziplib/commitdiff
docs: exception syntax compatibility with Python 3
authorPatrick Steinhardt <ps@pks.im>
Thu, 23 May 2019 20:20:23 +0000 (22:20 +0200)
committerPatrick Steinhardt <ps@pks.im>
Thu, 1 Aug 2019 08:14:04 +0000 (10:14 +0200)
Since Python 2.7, there exists a new syntax to catch errors: the old way
of saying `except IOError, error` has been replaced with `except IOError
as e`. The old syntax has finally been removed in Python 3, but as we're
still using it in zziplib newer interpreters will raise a parsing error.

Convert to use the new syntax to improve compatibility with Python 3.

docs/make-doc.py
docs/zzipdoc/commentmarkup.py
docs/zzipdoc/docbookdocument.py
docs/zzipdoc/functionlisthtmlpage.py
docs/zzipdoc/htm2dbk.py
docs/zzipdoc/htmldocument.py
docs/zzipdoc/textfile.py

index f12553fa32ece2b77773c1e69d6131c92ed2c249..1f8ff0ca34847154d054d9306dcbe2ddb506a3b9 100644 (file)
@@ -215,7 +215,7 @@ def scan_options (options, list):
         #else
         try:
             input = open(name, "r")
-        except IOError, error:
+        except IOError as error:
             warn(#...... (scan_options) ...............
                 "can not open input file: "+name, error)
             continue
@@ -524,7 +524,7 @@ html.add_page_list(html_pages)
 # and finally print the html-formatted output
 try:
     F = open(o.libhtmlfile, "w")
-except IOError, error:
+except IOError as error:
     warn(# ............. open(o.libhtmlfile, "w") ..............
         "can not open html output file: "+o.libhtmlfile, error)
 else:
@@ -987,7 +987,7 @@ doctype += '"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">'+"\n"
 
 try:
     F = open(o.docbookfile,"w")
-except IOError, error:
+except IOError as error:
     warn("can not open docbook output file: "+o.docbookfile, error)
 else:
     print >> F, doctype, '<reference><title>Manual Pages</title>'
@@ -1009,7 +1009,7 @@ else:
 # _____________________________________________________________________
 try:
     F = open( o.dumpdocfile, "w")
-except IOError, error:
+except IOError as error:
     warn ("can not open"+o.dumpdocfile,error)
 else:
     for func in function_list:
index 71803e04ee4a4de559ab87923c108eaecebe3d8e..c6824ee524f681a828baf772987b9290a9e204b4 100644 (file)
@@ -31,7 +31,7 @@ class CommentMarkup:
         comment = self.header.comment
         try:
             comment = self.header.get_otherlines()
-        except Exception, e:
+        except Exception:
             pass
         mode = ""
         text = ""
index ea0dfdc998cc5e0fd03f89be4e19932e316c4743..906e7a9225d0efd64eef14ece9b12729f6303db2 100644 (file)
@@ -23,14 +23,14 @@ class DocbookDocument:
     def get_title(self):
         if self.title: return title
         try:   return self.text[0].get_title()
-        except Exception, e: pass
+        except Exception: pass
         return self.title
     def _xml_doctype(self, rootnode):
         return "<!DOCTYPE "+rootnode+self.docbook_dtd+">"
     def _xml_text(self, xml):
         """ accepts adapter objects with .xml_text() """
         try:   return xml.xml_text()
-        except Exception, e: print "DocbookDocument/text", e; pass
+        except Exception as e: print "DocbookDocument/text", e; pass
         return str(xml)
     def _fetch_rootnode(self, text):
         fetch = Match(r"^[^<>]*<(\w+)\b")
@@ -62,7 +62,7 @@ class DocbookDocument:
             print >>fd, xml_text
             fd.close()
             return True
-        except IOError, e:
+        except IOError as e:
             print "could not open '"+filename+"'file", e
             return False
     def save_all(self, filename):
@@ -90,6 +90,6 @@ class DocbookDocument:
             print >>fd, "</"+self.rootnode+">"
             fd.close()
             return True
-        except IOError, e:
+        except IOError as e:
             print "could not open '"+filename+"'file", e
             return False
index b6310837cf6266695d7880437b12c0c3401093c4..ec3cdaf980ca8fd8042ac5637c5ef2edde510f97 100644 (file)
@@ -43,7 +43,7 @@ class FunctionListHtmlPage:
             callspec = entry.head_get_callspec()
             head_text = ("<code><b><function>"+namespec+"</function></b>"
                          +callspec+" : "+prespec+"</code>")
-        except Exception, e:
+        except Exception:
             pass
         try:
             extraline = ""
@@ -56,7 +56,7 @@ class FunctionListHtmlPage:
                              '<em><small>'+filename+'</small></em>'+
                              '</td></table>')
             body_text = extraline + body_text
-        except Exception, e:
+        except Exception:
             pass
         def link(text):
             return (text & Match("<function>(\w*)</function>")
index 18ffe5982268323e38eead95ba4f9d7e8bfb1b32..15f6f06143d894e8181aae88756ce327636daa3a 100644 (file)
@@ -146,7 +146,7 @@ def htm2dbk_files(args):
             doc.filename = filename
             doc.add(f.read())
             f.close()
-        except IOError, e:
+        except IOError:
             print >> sys.stderr, "can not open "+filename
     return doc.value()
 
index be355913268dc70b83f1ed82ea4bc6aed4a9fa4c..3f6b82484374cf3bcde3bac9a6fd3acea2662713 100644 (file)
@@ -29,31 +29,31 @@ class HtmlDocument:
     def get_title(self):
         if self.title: return self.title
         try:   return self.text[0].get_title()
-        except Exception, e: pass
+        except Exception: pass
         return self.title
     def _html_meta(self, meta):
         """ accepts adapter objects with .html_meta() """
         try:   return meta.html_meta()
-        except Exception, e: pass
+        except Exception: pass
         return str(meta)
     def _html_style(self, style):
         """ accepts adapter objects with .html_style() and .xml_style() """
         ee = None
         try:   return style.html_style()
-        except Exception, e: ee = e; pass
+        except Exception as e: ee = e; pass
         try:   return style.xml_style()
-        except Exception, e: print "HtmlDocument/style", ee, e; pass
+        except Exception as e: print "HtmlDocument/style", ee, e; pass
         try:   return str(style)
-        except Exception, e: print "HtmlDocument/style", e; return ""
+        except Exception as e: print "HtmlDocument/style", e; return ""
     def _html_text(self, html):
         """ accepts adapter objects with .html_text() and .xml_text() """
         ee = None
         try:   return html.html_text()
-        except Exception, e: ee = e; pass
+        except Exception as e: ee = e; pass
         try:   return html.xml_text()
-        except Exception, e: print "HtmlDocument/text", ee, e; pass
+        except Exception as e: print "HtmlDocument/text", ee, e; pass
         try:   return str(html)
-        except Exception, e: print "HtmlDocument/text", e; return "&nbsp;"
+        except Exception as e: print "HtmlDocument/text", e; return "&nbsp;"
     def navigation(self):
         if self.navi:
             return self.navi
@@ -63,7 +63,7 @@ class HtmlDocument:
                 self.navi = fd.read()
                 fd.close()
                 return self.navi
-            except Exception, e:
+            except Exception:
                 pass
         return None
     def html_header(self):
@@ -112,6 +112,6 @@ class HtmlDocument:
             print >>fd, self.html_footer()
             fd.close()
             return True
-        except IOError, e:
+        except IOError as e:
             print "could not open '"+filename+"'file", e
             return False
index bfaff8dbdfa3dcee3a8746124d9be15793372630..0b7bc9fa29a236ad6c7b3998bb8765b11d6c462b 100644 (file)
@@ -17,7 +17,7 @@ class TextFile:
             self.src_text = fd.read()
             fd.close()
             return True
-        except IOError, e:
+        except IOError:
             pass
         return False
     def assert_src_text(self):