]> granicus.if.org Git - zziplib/commitdiff
docs: use print function for compatibility with Python 3
authorPatrick Steinhardt <ps@pks.im>
Thu, 23 May 2019 20:37:01 +0000 (22:37 +0200)
committerPatrick Steinhardt <ps@pks.im>
Thu, 1 Aug 2019 08:14:04 +0000 (10:14 +0200)
Another quite visible change with Python 3 is that the old `print`
statement has been replaced with a function. To ease migration to the
newer way, Python 2.7 provides a compatibility module "print_function".

Convert all code in docs to use the new function syntax.

docs/cpp2markdown-1.py
docs/cpp2markdown.py
docs/make-doc.py
docs/zzipdoc/docbookdocument.py
docs/zzipdoc/functionlisthtmlpage.py
docs/zzipdoc/functionlistreference.py
docs/zzipdoc/htm2dbk.py
docs/zzipdoc/htmldocument.py
docs/zzipdoc/match.py
docs/zzipdoc/textfileheader.py

index 60d28c4a0f416355480766a645d5f61afb4c4c25..317e9f8107fb066f10010a78eb28c145f67ea9e2 100755 (executable)
@@ -1,4 +1,7 @@
 #! /usr/bin/env python
+
+from __future__ import print_function
+
 import pygments.lexers.compiled as lexer
 import optparse
 import re
@@ -108,7 +111,7 @@ class CppToMarkdown:
     def run(self, filename):
         filetext = open(filename).read()
         for line in self.process(filetext, filename):
-            print line
+            print(line)
     def process(self, filetext, filename=""):
         section_ruler = "-----------------------------------------"
         copyright = ""
@@ -136,7 +139,7 @@ class CppToMarkdown:
             else:
                 if text:
                     yield "#### NOTES"
-                    print token, text.replace("\n", "\n  ")
+                    print(token + " " + text.replace("\n", "\n  "))
         if copyright:
             yield section_ruler
             yield "### COPYRIGHT"
index 710bbdc24375566b09738abb65f6164b78984626..749de359cc7c50cc0795226f1ecdb0cd99b9be9c 100644 (file)
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
 import pygments.lexers.compiled as lexer
 import optparse
 import re
@@ -62,7 +64,7 @@ class CppToMarkdown:
     def run(self, filename):
         filetext = open(filename).read()
         for line in self.process(filetext, filename):
-            print line
+            print(line)
     def process(self, filetext, filename=""):
         for token, text in self.parse(filetext):
             if token == FileInclude:
@@ -86,7 +88,7 @@ class CppToMarkdown:
             else:
                 if text:
                     yield "#### NOTES"
-                    print token, text.replace("\n", "\n  ")
+                    print(token + " " + text.replace("\n", "\n  "))
     def isexported_function(self):
         function = self.function_text.strip().replace("\n"," ")
         logg.debug("@ --------------------------------------") 
index 1f8ff0ca34847154d054d9306dcbe2ddb506a3b9..50e579ffbf699642cbf8c81ee831c2309adf1a86 100644 (file)
@@ -1,5 +1,8 @@
 #! /usr/bin/python
 # -*- coding: UTF-8 -*-
+
+from __future__ import print_function
+
 import sys
 import re
 import string
@@ -376,7 +379,7 @@ def examine_head_anchors(func_list):
         function.head = s(function.head, r"(.*)also:(.*)", lambda x
                           : set_seealso(function, x.group(2)) and x.group(1))
         if function.seealso and None:
-            print "function[",function.name,"].seealso=",function.seealso
+            print("function[" + function.name + "].seealso=" + function.seealso)
 examine_head_anchors(function_list)
 
 # =============================================================== HTML =====
@@ -528,7 +531,7 @@ except IOError as error:
     warn(# ............. open(o.libhtmlfile, "w") ..............
         "can not open html output file: "+o.libhtmlfile, error)
 else:
-    print >> F, html.page_text()
+    print(html.page_text(), file=F)
     F.close()
 #fi
 
@@ -990,19 +993,18 @@ try:
 except IOError as error:
     warn("can not open docbook output file: "+o.docbookfile, error)
 else:
-    print >> F, doctype, '<reference><title>Manual Pages</title>'
+    print(doctype + '<reference><title>Manual Pages</title>', file=F)
 
     for page in combined_pages:
-        print >> F, page.refentry_text()
+        print(page.refentry_text(), file=F)
     #od
 
     for page in header_refpages.values():
         if not page.refentry: continue
-        print >> F, "\n<!-- _______ "+page.id+" _______ -->",
-        print >> F, page.refentry_text()
+        print("\n<!-- _______ "+page.id+" _______ -->" + page.refentry_text(), file=F)
     #od
 
-    print >> F, "\n",'</reference>',"\n"
+    print("\n</reference>\n", file=F)
     F.close()
 #fi
 
@@ -1014,13 +1016,11 @@ except IOError as error:
 else:
     for func in function_list:
         name = func.name
-        print >> F, "<fn id=\""+name+"\">"+"<!-- FOR \""+name+"\" -->\n"
+        print("<fn id=\""+name+"\">"+"<!-- FOR \""+name+"\" -->\n", file=F)
         for H in sorted_keys(func.dict()):
-            print >> F, "<"+H+" name=\""+name+"\">",
-            print >> F, str(func.dict()[H]),
-            print >> F, "</"+H+">"
+            print("<"+H+" name=\""+name+"\">" + str(func.dict()[H]) + "</"+H+">", file=F)
         #od
-        print >> F, "</fn><!-- END \""+name+"\" -->\n\n";
+        print("</fn><!-- END \""+name+"\" -->\n\n", file=F)
     #od
     F.close();
 #fi
index 906e7a9225d0efd64eef14ece9b12729f6303db2..d9a50fadcda76e847023e5097ccdbd79601e0099 100644 (file)
@@ -1,5 +1,8 @@
 #! /usr/bin/env python
 # -*- coding: UTF-8 -*-
+
+from __future__ import print_function
+
 from zzipdoc.match import Match
 
 class DocbookDocument:
@@ -30,7 +33,7 @@ class DocbookDocument:
     def _xml_text(self, xml):
         """ accepts adapter objects with .xml_text() """
         try:   return xml.xml_text()
-        except Exception as e: print "DocbookDocument/text", e; pass
+        except Exception as e: print("DocbookDocument/text" + str(e)); pass
         return str(xml)
     def _fetch_rootnode(self, text):
         fetch = Match(r"^[^<>]*<(\w+)\b")
@@ -47,7 +50,7 @@ class DocbookDocument:
         return filename
     def save(self, filename = None):
         filename = self._filename(filename)
-        print "writing '"+filename+"'"
+        print("writing '"+filename+"'")
         if len(self.text) > 1:
             self.save_all(filename)
         else:
@@ -58,12 +61,12 @@ class DocbookDocument:
             xml_text = self._xml_text(text)
             rootnode = self._fetch_rootnode(xml_text)
             doctype = self._xml_doctype(rootnode)
-            print >>fd, doctype
-            print >>fd, xml_text
+            print(doctype, file=fd)
+            print(xml_text, file=fd)
             fd.close()
             return True
         except IOError as e:
-            print "could not open '"+filename+"'file", e
+            print("could not open '"+filename+"'file" + str(e))
             return False
     def save_all(self, filename):
         assert len(self.text) > 1
@@ -76,20 +79,20 @@ class DocbookDocument:
             else:
                 rootnode = self.rootnode
             doctype = self._xml_doctype(rootnode)
-            print >>fd, doctype
+            print(doctype, file=fd)
             title = self.get_title()
             if title and self.rootnode in self.has_title_child:
-                print >>fd, "<"+self.rootnode+'><title>'+title+'</title>'
+                print("<"+self.rootnode+'><title>'+title+'</title>', file=fd)
             elif title:
-                print >>fd, "<"+self.rootnode+' id="'+title+'">'
+                print("<"+self.rootnode+' id="'+title+'">', file=fd)
             else:
-                print >>fd, "<"+self.rootnode+'>'
+                print("<"+self.rootnode+'>', file=fd)
             for text in self.text:
                 text = self._xml_text(text)
-                print >>fd, text
-            print >>fd, "</"+self.rootnode+">"
+                print(text)
+            print("</"+self.rootnode+">", file=fd)
             fd.close()
             return True
         except IOError as e:
-            print "could not open '"+filename+"'file", e
+            print("could not open '"+filename+"'file" + str(e))
             return False
index ec3cdaf980ca8fd8042ac5637c5ef2edde510f97..acabdd4c70243650b6a5ffa038eb01932e2faef2 100644 (file)
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
 from zzipdoc.options import *
 from zzipdoc.match import Match
 
@@ -35,7 +37,7 @@ class FunctionListHtmlPage:
         head_text = entry.head_xml_text()
         body_text = entry.body_xml_text(name)
         if not head_text:
-            print "no head_text for", name
+            print("no head_text for " + name)
             return
         try:
             prespec = entry.head_get_prespec()
@@ -102,7 +104,7 @@ class FunctionListHtmlPage:
         text &= (Match("(?s)<link>(\w+)</link>")
                  >> (lambda x: self.resolve_internal(x.group(1))))
         if len(self.not_found_in_anchors):
-            print "not found in anchors: ", self.not_found_in_anchors
+            print("not found in anchors: {}".format(self.not_found_in_anchors))
         return (text & Match("(?s)<link>([^<>]*)</link>")
                 >> "<code>\\1</code>")
     def resolve_external(self, func, sect):
index 50531104918735390bb5f0ebe7ebd8a37d18e64a..7b7560395c4f62362478e265a44077c4ec5004c3 100644 (file)
@@ -1,5 +1,7 @@
 #! /usr/bin/env python
 # -*- coding: UTF-8 -*-
+from __future__ import print_function
+
 from zzipdoc.match import Match
 from zzipdoc.htm2dbk import *
 
@@ -19,7 +21,7 @@ class FunctionListReference:
         description = entry.body_xml_text(name)
         funcsynopsis = entry.head_xml_text()
         if not funcsynopsis:
-            print "no funcsynopsis for", name
+            print("no funcsynopsis for " + name)
             return
         if self.entry is None:
             self.entry = FunctionListRefEntry(entry, self.o)
index 15f6f06143d894e8181aae88756ce327636daa3a..0a6d743edf1254ce5fec0a130b0dfe9275d82d1b 100644 (file)
@@ -6,6 +6,8 @@ The mapping of markups and links is far from perfect. But all we
 want is the docbook-to-pdf converter and similar technology being
 present in the world of docbook-to-anything converters. """
 
+from __future__ import print_function
+
 from datetime import date
 from zzipdoc.match import Match
 import sys
@@ -147,7 +149,7 @@ def htm2dbk_files(args):
             doc.add(f.read())
             f.close()
         except IOError:
-            print >> sys.stderr, "can not open "+filename
+            print("can not open "+filename, file=sys.stderr)
     return doc.value()
 
 def html2docbook(text):
@@ -161,7 +163,7 @@ if __name__ == "__main__":
     opt, args = cmdline.parse_args()
     result = htm2dbk_files(args)
     if not opt.into:
-        print result
+        print(result)
     else:
         f = open(opt.into, "w")
         f.write(result)
index 3f6b82484374cf3bcde3bac9a6fd3acea2662713..ca6141d574e586dccd9b2f2c7262854185b1d0e7 100644 (file)
@@ -1,5 +1,7 @@
 #! /usr/bin/env python
 # -*- coding: UTF-8 -*-
+from __future__ import print_function
+
 from zzipdoc.match import Match
 
 class HtmlDocument:
@@ -42,18 +44,18 @@ class HtmlDocument:
         try:   return style.html_style()
         except Exception as e: ee = e; pass
         try:   return style.xml_style()
-        except Exception as e: print "HtmlDocument/style", ee, e; pass
+        except Exception as e: print("HtmlDocument/style {} {}".format(ee, e)); pass
         try:   return str(style)
-        except Exception as e: print "HtmlDocument/style", e; return ""
+        except Exception as e: print("HtmlDocument/style {}".format(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 as e: ee = e; pass
         try:   return html.xml_text()
-        except Exception as e: print "HtmlDocument/text", ee, e; pass
+        except Exception as e: print("HtmlDocument/text {} {}".format(ee, e)); pass
         try:   return str(html)
-        except Exception as e: print "HtmlDocument/text", e; return "&nbsp;"
+        except Exception as e: print("HtmlDocument/text {}".format(e)); return "&nbsp;"
     def navigation(self):
         if self.navi:
             return self.navi
@@ -103,15 +105,15 @@ class HtmlDocument:
         return filename
     def save(self, filename = None):
         filename = self._filename(filename)
-        print "writing '"+filename+"'"
+        print("writing '"+filename+"'")
         try:
             fd = open(filename, "w")
-            print >>fd, self.html_header()
+            print(self.html_header(), file=fd)
             for text in self.text:
-                print >>fd, self._html_text(text)
-            print >>fd, self.html_footer()
+                print(self._html_text(text), file=fd)
+            print(self.html_footer(), file=fd)
             fd.close()
             return True
         except IOError as e:
-            print "could not open '"+filename+"'file", e
+            print("could not open '"+filename+"'file {}".format(e))
             return False
index 47582a1410b67ec26af7a680a98c21b6c2cf5502..d1b2b0d710973ee9faf3dc6fd150a0cc9417ad0e 100644 (file)
@@ -3,6 +3,8 @@
 # @creator (C) 2003 Guido U. Draheim
 # @license http://creativecommons.org/licenses/by-nc-sa/2.0/de/
 
+from __future__ import print_function
+
 import re
 
 try:
@@ -95,14 +97,14 @@ class Match(str):
 if __name__ == "__main__":
     # matching:
     if "foo" & Match("oo"):
-        print "oo"
+        print("oo")
     x = Match()
     if "foo" & x("(o+)"):
-        print x[1]
+        print(x[1])
     # replacing:
     y = "fooboo" & Match("oo") >> "ee"
-    print y
+    print(y)
     r = Match("oo") >> "ee"
-    print "fooboo" & r
+    print("fooboo" & r)
     s = MatchReplace("oo", "ee")
-    print "fooboo" & s
+    print("fooboo" & s)
index c73724320446f616fd26580d04a2036611f80a31..c38c4be06ec591d7097f0dfdc2b9d60bff68f01e 100644 (file)
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
 from zzipdoc.match import Match
 
 class TextFileHeader:
@@ -17,7 +19,7 @@ class TextFileHeader:
         x = Match()
         text = self.textfile.get_src_text()
         if not text:
-            print "nonexistent file:", self.textfile.get_filename()
+            print("nonexistent file: " + self.textfile.get_filename())
             return False
         if text & x(r"(?s)[/][*]+(\s(?:.(?!\*\/))*.)\*\/"
                     r"(?:\s*\#(?:define|ifdef|endif)[ ]*\S*[ ]*\S*)*"