Ticket #61526: Python2-3_patches.diff

File Python2-3_patches.diff, 16.8 KB (added by ballapete (Peter "Pete" Dyballa), 3 years ago)

Translates the used Python 2 files to Python 3

  • docs/makedocs.py

     
    3737        return None
    3838    def print_list_mainheader(self):
    3939        for t_fileheader in self.headers:
    40             print t_fileheader.get_filename(), t_fileheader.src_mainheader()
     40            print(t_fileheader.get_filename(), t_fileheader.src_mainheader())
    4141       
    4242class PerFunctionEntry:
    4343    def __init__(self, header, comment, prototype):
     
    6666                                           functionprototype) ]
    6767    def print_list_titleline(self):
    6868        for funcheader in self.headers:
    69             print funcheader.get_filename(), "[=>]", funcheader.get_titleline()
     69            print(funcheader.get_filename(), "[=>]", funcheader.get_titleline())
    7070    def print_list_name(self):
    7171        for funcheader in self.prototypes:
    72             print funcheader.get_filename(), "[>>]", funcheader.get_name()
     72            print(funcheader.get_filename(), "[>>]", funcheader.get_name())
    7373
    7474class PerFunctionFamilyEntry:
    7575    def __init__(self, leader):
     
    122122        for name in self.retarget:
    123123            into = self.retarget[name]
    124124            if into not in name_list:
    125                 print ("function '"+name+"' retarget into '"+into+
    126                        "' does not exist - keep alone")
     125                print(("function '"+name+"' retarget into '"+into+
     126                       "' does not exist - keep alone"))
    127127            if into in self.retarget:
    128128                other = self.retarget[into]
    129                 print ("function '"+name+"' retarget into '"+into+
    130                        "' which is itself a retarget into '"+other+"'")
     129                print(("function '"+name+"' retarget into '"+into+
     130                       "' which is itself a retarget into '"+other+"'"))
    131131            if into not in lead_list:
    132132                lead_list += [ into ]
    133133        for func in self.functions:
     
    141141                entry.add(func) # the first
    142142                self.entries += [ entry ]
    143143            else:
    144                 print "head function '"+name+" has no entry"
     144                print("head function '"+name+" has no entry")
    145145        for func in self.functions:
    146146            name = func.get_name()
    147147            if name in self.retarget:
     
    150150                if entry is not None:
    151151                    entry.add(func) # will not add duplicates
    152152                else:
    153                     print "into function '"+name+" has no entry"
     153                    print("into function '"+name+" has no entry")
    154154    def print_list_name(self):
    155155        for family in self.entries:
    156156            name = family.get_name()
    157             print name, ":",
     157            print(name, ":", end=' ')
    158158            for item in family.functions:
    159                 print item.get_name(), ",",
    160             print ""
     159                print(item.get_name(), ",", end=' ')
     160            print("")
    161161class HtmlManualPageAdapter:
    162162    def __init__(self, entry):
    163163        """ usually takes a PerFunctionEntry """
  • docs/zzipdoc/match.py

     
    1818        MatchReplace.__call__(self, matching, template, count, flags)
    1919    def __call__(self, matching, template = None, count = 0, flags = None):
    2020        """ other than __init__ the template may be left off to be unchanged"""
    21         if isinstance(count, basestring): # count/flags swapped over?
     21        if isinstance(count, str): # count/flags swapped over?
    2222            flags = count; count = 0
    2323        if isinstance(matching, Match):
    2424            self.matching = matching
     
    5757    def __call__(self, pattern, flags = None):
    5858        assert isinstance(pattern, str) or pattern is None
    5959        assert isinstance(flags, str) or flags is None
    60         str.__init__(self, pattern)
     60        str.__init__(pattern)
    6161        self.replaced = 0 # set by subn() inside MatchReplace
    6262        self.found = None # set by search() to a MatchObject
    6363        self.pattern = pattern
     
    9090if __name__ == "__main__":
    9191    # matching:
    9292    if "foo" & Match("oo"):
    93         print "oo"
     93        print("oo")
    9494    x = Match()
    9595    if "foo" & x("(o+)"):
    96         print x[1]
     96        print(x[1])
    9797    # replacing:
    9898    y = "fooboo" & Match("oo") >> "ee"
    99     print y
     99    print(y)
    100100    r = Match("oo") >> "ee"
    101     print "fooboo" & r
     101    print("fooboo" & r)
    102102    s = MatchReplace("oo", "ee")
    103     print "fooboo" & s
     103    print("fooboo" & s)
  • docs/zzipdoc/options.py

     
    33# @creator (C) 2003 Guido U. Draheim
    44# @license http://creativecommons.org/licenses/by-nc-sa/2.0/de/
    55
    6 from match import Match
     6from .match import Match
    77
    88# use as o.optionname to check for commandline options.
    99class Options:
    1010    var = {}
    1111    def __getattr__(self, name):
    12         if not self.var.has_key(name): return None
     12        if name not in self.var: return None
    1313        return self.var[name]
    1414    def __setattr__(self, name, value):
    1515        self.var[name] = value
  • docs/zzipdoc/textfile.py

     
    1717            self.src_text = fd.read()
    1818            fd.close()
    1919            return True
    20         except IOError, e:
     20        except IOError as e:
    2121            pass
    2222        return False
    2323    def assert_src_text(self):
     
    4141        self._line(self.src_text, offset)
    4242    def _line(self, text, offset):
    4343        line = 1
    44         for x in xrange(0,offset):
     44        for x in range(0,offset):
    4545            if x == "\n":
    4646                line += 1
    4747        return line
  • docs/zzipdoc/textfileheader.py

     
    1 from match import Match
     1from .match import Match
    22
    33class TextFileHeader:
    44    """ scan for a comment block at the source file start and fill the
     
    1717        x = Match()
    1818        text = self.textfile.get_src_text()
    1919        if not text:
    20             print "nonexistent file:", self.textfile.get_filename()
     20            print("nonexistent file:", self.textfile.get_filename())
    2121            return False
    2222        if text & x(r"(?s)[/][*]+(\s(?:.(?!\*\/))*.)\*\/"
    2323                    r"(?:\s*\#(?:define|ifdef|endif)[ ]*\S*[ ]*\S*)*"
  • docs/zzipdoc/functionheader.py

     
    1 from match import Match
     1from .match import Match
    22
    33class FunctionHeader:
    44    """ parsing the comment block that is usually presented before
  • docs/zzipdoc/functionprototype.py

     
    1 from match import Match
     1from .match import Match
    22
    33class FunctionPrototype:
    44    """ takes a single function prototype line (cut from some source file)
  • docs/zzipdoc/commentmarkup.py

     
    1 from match import Match
     1from .match import Match
    22
    33def markup_link_syntax(text):
    44    """ markup the link-syntax ` => somewhere ` in the text block """
     
    3131        comment = self.header.comment
    3232        try:
    3333            comment = self.header.get_otherlines()
    34         except Exception, e:
     34        except Exception as e:
    3535            pass
    3636        mode = ""
    3737        text = ""
  • docs/zzipdoc/functionlisthtmlpage.py

     
    1 from options import *
    2 from match import Match
     1from .options import *
     2from .match import Match
    33
    44class FunctionListHtmlPage:
    55    """ The main part here is to create a TOC (table of contents) at the
     
    3535        head_text = entry.head_xml_text()
    3636        body_text = entry.body_xml_text(name)
    3737        if not head_text:
    38             print "no head_text for", name
     38            print("no head_text for", name)
    3939            return
    4040        try:
    4141            prespec = entry.head_get_prespec()
     
    4343            callspec = entry.head_get_callspec()
    4444            head_text = ("<code><b><function>"+namespec+"</function></b>"
    4545                         +callspec+" : "+prespec+"</code>")
    46         except Exception, e:
     46        except Exception as e:
    4747            pass
    4848        try:
    4949            extraline = ""
     
    5656                             '<em><small>'+filename+'</small></em>'+
    5757                             '</td></table>')
    5858            body_text = extraline + body_text
    59         except Exception, e:
     59        except Exception as e:
    6060            pass
    6161        def link(text):
    6262            return (text & Match("<function>(\w*)</function>")
     
    102102        text &= (Match("(?s)<link>(\w+)</link>")
    103103                 >> (lambda x: self.resolve_internal(x.group(1))))
    104104        if len(self.not_found_in_anchors):
    105             print "not found in anchors: ", self.not_found_in_anchors
     105            print("not found in anchors: ", self.not_found_in_anchors)
    106106        return (text & Match("(?s)<link>([^<>]*)</link>")
    107107                >> "<code>\\1</code>")
    108108    def resolve_external(self, func, sect):
  • docs/zzipdoc/functionlistreference.py

     
    11#! /usr/bin/env python
    22# -*- coding: UTF-8 -*-
    3 from match import Match
    4 from htm2dbk import *
     3from .match import Match
     4from .htm2dbk import *
    55
    66class FunctionListReference:
    77    """ Creating a docbook-style <reference> list of <refentry> parts
     
    1919        description = entry.body_xml_text(name)
    2020        funcsynopsis = entry.head_xml_text()
    2121        if not funcsynopsis:
    22             print "no funcsynopsis for", name
     22            print("no funcsynopsis for", name)
    2323            return
    2424        if self.entry is None:
    2525            self.entry = FunctionListRefEntry(entry, self.o)
  • docs/zzipdoc/dbk2htm.py

     
    1 from match import Match
     1from .match import Match
    22import string
    33
    44class dbk2htm_conversion:
  • docs/zzipdoc/htmldocument.py

     
    11#! /usr/bin/env python
    22# -*- coding: UTF-8 -*-
    3 from match import Match
     3from .match import Match
    44
    55class HtmlDocument:
    66    """ binds some html content page with additional markup - in this
     
    2929    def get_title(self):
    3030        if self.title: return self.title
    3131        try:   return self.text[0].get_title()
    32         except Exception, e: pass
     32        except Exception as e: pass
    3333        return self.title
    3434    def _html_meta(self, meta):
    3535        """ accepts adapter objects with .html_meta() """
    3636        try:   return meta.html_meta()
    37         except Exception, e: pass
     37        except Exception as e: pass
    3838        return str(meta)
    3939    def _html_style(self, style):
    4040        """ accepts adapter objects with .html_style() and .xml_style() """
    4141        ee = None
    4242        try:   return style.html_style()
    43         except Exception, e: ee = e; pass
     43        except Exception as e: ee = e; pass
    4444        try:   return style.xml_style()
    45         except Exception, e: print "HtmlDocument/style", ee, e; pass
     45        except Exception as e: print("HtmlDocument/style", ee, e); pass
    4646        try:   return str(style)
    47         except Exception, e: print "HtmlDocument/style", e; return ""
     47        except Exception as e: print("HtmlDocument/style", e); return ""
    4848    def _html_text(self, html):
    4949        """ accepts adapter objects with .html_text() and .xml_text() """
    5050        ee = None
    5151        try:   return html.html_text()
    52         except Exception, e: ee = e; pass
     52        except Exception as e: ee = e; pass
    5353        try:   return html.xml_text()
    54         except Exception, e: print "HtmlDocument/text", ee, e; pass
     54        except Exception as e: print("HtmlDocument/text", ee, e); pass
    5555        try:   return str(html)
    56         except Exception, e: print "HtmlDocument/text", e; return "&nbsp;"
     56        except Exception as e: print("HtmlDocument/text", e); return "&nbsp;"
    5757    def navigation(self):
    5858        if self.navi:
    5959            return self.navi
     
    6363                self.navi = fd.read()
    6464                fd.close()
    6565                return self.navi
    66             except Exception, e:
     66            except Exception as e:
    6767                pass
    6868        return None
    6969    def html_header(self):
     
    103103        return filename
    104104    def save(self, filename = None):
    105105        filename = self._filename(filename)
    106         print "writing '"+filename+"'"
     106        print("writing '"+filename+"'")
    107107        try:
    108108            fd = open(filename, "w")
    109             print >>fd, self.html_header()
     109            print(self.html_header(), file=fd)
    110110            for text in self.text:
    111                 print >>fd, self._html_text(text)
    112             print >>fd, self.html_footer()
     111                print(self._html_text(text), file=fd)
     112            print(self.html_footer(), file=fd)
    113113            fd.close()
    114114            return True
    115         except IOError, e:
    116             print "could not open '"+filename+"'file", e
     115        except IOError as e:
     116            print("could not open '"+filename+"'file", e)
    117117            return False
  • docs/zzipdoc/docbookdocument.py

     
    11#! /usr/bin/env python
    22# -*- coding: UTF-8 -*-
    3 from match import Match
     3from .match import Match
    44
    55class DocbookDocument:
    66    """ binds some xml content page with additional markup - in this
     
    2323    def get_title(self):
    2424        if self.title: return title
    2525        try:   return self.text[0].get_title()
    26         except Exception, e: pass
     26        except Exception as e: pass
    2727        return self.title
    2828    def _xml_doctype(self, rootnode):
    2929        return "<!DOCTYPE "+rootnode+self.docbook_dtd+">"
    3030    def _xml_text(self, xml):
    3131        """ accepts adapter objects with .xml_text() """
    3232        try:   return xml.xml_text()
    33         except Exception, e: print "DocbookDocument/text", e; pass
     33        except Exception as e: print("DocbookDocument/text", e); pass
    3434        return str(xml)
    3535    def _fetch_rootnode(self, text):
    3636        fetch = Match(r"^[^<>]*<(\w+)\b")
     
    4747        return filename
    4848    def save(self, filename = None):
    4949        filename = self._filename(filename)
    50         print "writing '"+filename+"'"
     50        print("writing '"+filename+"'")
    5151        if len(self.text) > 1:
    5252            self.save_all(filename)
    5353        else:
     
    5858            xml_text = self._xml_text(text)
    5959            rootnode = self._fetch_rootnode(xml_text)
    6060            doctype = self._xml_doctype(rootnode)
    61             print >>fd, doctype
    62             print >>fd, xml_text
     61            print(doctype, file=fd)
     62            print(xml_text, file=fd)
    6363            fd.close()
    6464            return True
    65         except IOError, e:
    66             print "could not open '"+filename+"'file", e
     65        except IOError as e:
     66            print("could not open '"+filename+"'file", e)
    6767            return False
    6868    def save_all(self, filename):
    6969        assert len(self.text) > 1
     
    7676            else:
    7777                rootnode = self.rootnode
    7878            doctype = self._xml_doctype(rootnode)
    79             print >>fd, doctype
     79            print(doctype, file=fd)
    8080            title = self.get_title()
    8181            if title and self.rootnode in self.has_title_child:
    82                 print >>fd, "<"+self.rootnode+'><title>'+title+'</title>'
     82                print("<"+self.rootnode+'><title>'+title+'</title>', file=fd)
    8383            elif title:
    84                 print >>fd, "<"+self.rootnode+' id="'+title+'">'
     84                print("<"+self.rootnode+' id="'+title+'">', file=fd)
    8585            else:
    86                 print >>fd, "<"+self.rootnode+'>'
     86                print("<"+self.rootnode+'>', file=fd)
    8787            for text in self.text:
    8888                text = self._xml_text(text)
    89                 print >>fd, text
    90             print >>fd, "</"+self.rootnode+">"
     89                print(text, file=fd)
     90            print("</"+self.rootnode+">", file=fd)
    9191            fd.close()
    9292            return True
    93         except IOError, e:
    94             print "could not open '"+filename+"'file", e
     93        except IOError as e:
     94            print("could not open '"+filename+"'file", e)
    9595            return False
  • docs/zzipdoc/htm2dbk.py

     
    77present in the world of docbook-to-anything converters. """
    88
    99from datetime import date
    10 import match
     10from . import match
    1111import sys
    1212
    1313m = match.Match
     
    146146            doc.filename = filename
    147147            doc.add(f.read())
    148148            f.close()
    149         except IOError, e:
    150             print >> sys.stderr, "can not open "+filename
     149        except IOError as e:
     150            print("can not open "+filename, file=sys.stderr)
    151151    return doc.value()
    152152
    153153def html2docbook(text):
     
    155155    return htm2dbk_conversion().convert2(text)
    156156
    157157if __name__ == "__main__":
    158     print htm2dbk_files(sys.argv[1:])
     158    print(htm2dbk_files(sys.argv[1:]))