From: Neil Muller <drnlmuller+debian@gmail.com>
Date: Fri, 27 Dec 2019 11:52:26 +0200
Subject: Update documentation build to work with python3

We update the builddocs command and pydoc2 modules to work with python3
---
 docs/pydoc/builddocs.py |  2 +-
 docs/pydoc/pydoc2.py    | 58 +++++++++++++++++++++++--------------------------
 2 files changed, 28 insertions(+), 32 deletions(-)

diff --git a/docs/pydoc/builddocs.py b/docs/pydoc/builddocs.py
index 004118d..1880b17 100755
--- a/docs/pydoc/builddocs.py
+++ b/docs/pydoc/builddocs.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 """Script to automatically generate OpenGLContext documentation"""
 import pydoc2
 
diff --git a/docs/pydoc/pydoc2.py b/docs/pydoc/pydoc2.py
index 7b28bac..f5bfcaa 100644
--- a/docs/pydoc/pydoc2.py
+++ b/docs/pydoc/pydoc2.py
@@ -1,21 +1,19 @@
 """Pydoc sub-class for generating documentation for entire packages"""
 import pydoc, inspect, os, string
-import sys, imp, os, stat, re, types, inspect
-from repr import Repr
-from string import expandtabs, find, join, lower, split, strip, rfind, rstrip
+import sys
 
 
 class DefaultFormatter(pydoc.HTMLDoc):
     def docmodule(self, object, name=None, mod=None, packageContext = None, *ignored):
         """Produce HTML documentation for a module object."""
         name = object.__name__ # ignore the passed-in name
-        parts = split(name, '.')
+        parts = name.split('.')
         links = []
         for i in range(len(parts)-1):
             links.append(
                 '<a href="%s.html"><font color="#ffffff">%s</font></a>' %
-                (join(parts[:i+1], '.'), parts[i]))
-        linkedname = join(links + parts[-1:], '.')
+                ('.'.join(parts[:i+1]), parts[i]))
+        linkedname = '.'.join(links + parts[-1:])
         head = '<big><big><strong>%s</strong></big></big>' % linkedname
         try:
             path = inspect.getabsfile(object)
@@ -35,7 +33,7 @@ class DefaultFormatter(pydoc.HTMLDoc):
         if hasattr(object, '__date__'):
             info.append(self.escape(str(object.__date__)))
         if info:
-            head = head + ' (%s)' % join(info, ', ')
+            head = head + ' (%s)' % ', '.join(info)
         result = self.heading(
             head, '#ffffff', '#7799ee', '<a href=".">index</a><br>' + filelink)
 
@@ -52,7 +50,7 @@ class DefaultFormatter(pydoc.HTMLDoc):
                 module = sys.modules.get(modname)
                 if modname != name and module and hasattr(module, key):
                     if getattr(module, key) is base:
-                        if not cdict.has_key(key):
+                        if key not in cdict:
                             cdict[key] = cdict[base] = modname + '.html#' + key
         funcs, fdict = [], {}
         for key, value in inspect.getmembers(object, inspect.isroutine):
@@ -62,8 +60,7 @@ class DefaultFormatter(pydoc.HTMLDoc):
                 if inspect.isfunction(value): fdict[value] = fdict[key]
         data = []
         for key, value in inspect.getmembers(object, pydoc.isdata):
-            if key not in ['__builtins__', '__doc__']:
-                data.append((key, value))
+            data.append((key, value))
 
         doc = self.markup(pydoc.getdoc(object), self.preformat, fdict, cdict)
         doc = doc and '<tt>%s</tt>' % doc
@@ -91,31 +88,31 @@ class DefaultFormatter(pydoc.HTMLDoc):
             result = result + self.moduleSection( object, packageContext)
         elif modules:
             contents = self.multicolumn(
-                modules, lambda (key, value), s=self: s.modulelink(value))
+                modules, lambda key_value, s=self: s.modulelink(key_value[1]))
             result = result + self.bigsection(
                 'Modules', '#fffff', '#aa55cc', contents)
 
         
         if classes:
-            classlist = map(lambda (key, value): value, classes)
+            classlist = map(lambda key_value: key_value[1], classes)
             contents = [
                 self.formattree(inspect.getclasstree(classlist, 1), name)]
             for key, value in classes:
                 contents.append(self.document(value, key, name, fdict, cdict))
             result = result + self.bigsection(
-                'Classes', '#ffffff', '#ee77aa', join(contents))
+                'Classes', '#ffffff', '#ee77aa', ''.join(contents))
         if funcs:
             contents = []
             for key, value in funcs:
                 contents.append(self.document(value, key, name, fdict, cdict))
             result = result + self.bigsection(
-                'Functions', '#ffffff', '#eeaa77', join(contents))
+                'Functions', '#ffffff', '#eeaa77', ''.join(contents))
         if data:
             contents = []
             for key, value in data:
                 contents.append(self.document(value, key))
             result = result + self.bigsection(
-                'Data', '#ffffff', '#55aa55', join(contents, '<br>\n'))
+                'Data', '#ffffff', '#55aa55', '<br>\n'.join(contents))
         if hasattr(object, '__author__'):
             contents = self.markup(str(object.__author__), self.preformat)
             result = result + self.bigsection(
@@ -156,7 +153,7 @@ class DefaultFormatter(pydoc.HTMLDoc):
             modpkgs.sort()
             # do more recursion here...
             for (modname, name, ya,yo) in modpkgs:
-                packageContext.addInteresting( join( (object.__name__, modname), '.'))
+                packageContext.addInteresting('.'.join( (object.__name__, modname) ))
             items = []
             for (modname, name, ispackage,isshadowed) in modpkgs:
                 try:
@@ -181,12 +178,12 @@ class DefaultFormatter(pydoc.HTMLDoc):
                     items.append(
                         self.modpkglink( (modname, name, ispackage, isshadowed) )
                     )
-            contents = string.join( items, '<br>')
+            contents = '<br>'.join( items )
             result = self.bigsection(
                 'Package Contents', '#ffffff', '#aa55cc', contents)
         elif modules:
             contents = self.multicolumn(
-                modules, lambda (key, value), s=self: s.modulelink(value))
+                modules, lambda key_value, s=self: s.modulelink(key_value[1]))
             result = self.bigsection(
                 'Modules', '#fffff', '#aa55cc', contents)
         else:
@@ -239,7 +236,7 @@ class PackageDocumentationGenerator:
         for exclusion in exclusions:
             try:
                 self.exclusions[ exclusion ]= pydoc.locate ( exclusion)
-            except pydoc.ErrorDuringImport, value:
+            except pydoc.ErrorDuringImport as value:
                 self.warn( """Unable to import the module %s which was specified as an exclusion module"""% (repr(exclusion)))
         self.formatter = formatter or DefaultFormatter()
         for base in baseModules:
@@ -249,18 +246,18 @@ class PackageDocumentationGenerator:
         self.warnings.append (message)
     def info (self, message):
         """Information/status report"""
-        print message
+        print(message)
     def addBase(self, specifier):
         """Set the base of the documentation set, only children of these modules will be documented"""
         try:
             self.baseSpecifiers [specifier] = pydoc.locate ( specifier)
             self.pending.append (specifier)
-        except pydoc.ErrorDuringImport, value:
+        except pydoc.ErrorDuringImport as value:
             self.warn( """Unable to import the module %s which was specified as a base module"""% (repr(specifier)))
     def addInteresting( self, specifier):
         """Add a module to the list of interesting modules"""
         if self.checkScope( specifier):
-##			print "addInteresting", specifier
+##			print("addInteresting", specifier)
             self.pending.append (specifier)
         else:
             self.completed[ specifier] = 1
@@ -268,17 +265,17 @@ class PackageDocumentationGenerator:
         """Check that the specifier is "in scope" for the recursion"""
         if not self.recursion:
             return 0
-        items = string.split (specifier, ".")
+        items = specifier.split(".")
         stopCheck = items [:]
         while stopCheck:
-            name = string.join(items, ".")
+            name = ".".join(items)
             if self.recursionStops.get( name):
                 return 0
             elif self.completed.get (name):
                 return 0
             del stopCheck[-1]
         while items:
-            if self.baseSpecifiers.get( string.join(items, ".")):
+            if self.baseSpecifiers.get( ".".join(items)):
                 return 1
             del items[-1]
         # was not within any given scope
@@ -292,20 +289,20 @@ class PackageDocumentationGenerator:
         try:
             while self.pending:
                 try:
-                    if self.completed.has_key( self.pending[0] ):
+                    if self.pending[0] in self.completed:
                         raise AlreadyDone( self.pending[0] )
                     self.info( """Start %s"""% (repr(self.pending[0])))
                     object = pydoc.locate ( self.pending[0] )
                     self.info( """   ... found %s"""% (repr(object.__name__)))
                 except AlreadyDone:
                     pass
-                except pydoc.ErrorDuringImport, value:
+                except pydoc.ErrorDuringImport as value:
                     self.info( """   ... FAILED %s"""% (repr( value)))
                     self.warn( """Unable to import the module %s"""% (repr(self.pending[0])))
-                except (SystemError, SystemExit), value:
+                except (SystemError, SystemExit) as value:
                     self.info( """   ... FAILED %s"""% (repr( value)))
                     self.warn( """Unable to import the module %s"""% (repr(self.pending[0])))
-                except Exception, value:
+                except Exception as value:
                     self.info( """   ... FAILED %s"""% (repr( value)))
                     self.warn( """Unable to import the module %s"""% (repr(self.pending[0])))
                 else:
@@ -330,7 +327,7 @@ class PackageDocumentationGenerator:
                 del self.pending[0]
         finally:
             for item in self.warnings:
-                print item
+                print(item)
             
     def clean (self, objectList, object):
         """callback from the formatter object asking us to remove
@@ -378,4 +375,3 @@ if __name__ == "__main__":
         destinationDirectory = "z:\\temp",
         exclusions = excludes,
     ).process ()
-        
\ No newline at end of file
