Author: Andreas Tille <tille@debian.org>
Last-Update: Tue, 17 Sep 2019 12:57:58 +0200
Description: Use 2to3 to port Python2 code to Python3

--- a/inst/tools/mxParser.py
+++ b/inst/tools/mxParser.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 import sys
 import os
 import string
@@ -108,7 +108,7 @@ def parseStartOrValue( mxInput ):
     global valBuffer
     match = re.match("\s*(Start|Value)\s+(\S+)\s+(All|(\S+[ ]+)+)\s*", mxInput, re.IGNORECASE)
     if (match.group(3) == "All"):
-        for matrix in matrices.values():
+        for matrix in list(matrices.values()):
             mname = "matrix" + matrix.name
             if match.group(2) == "Value":
                 direction = "!"
@@ -132,18 +132,18 @@ def parseStartOrValue( mxInput ):
     return len(match.group(0))
         
 def printAlgebras():
-	for algebra in algebras.values():
+	for algebra in list(algebras.values()):
 		outstring = "algebra" + algebra.name + " <- "		
 		outstring += "mxAlgebra(" + mxAlgebraParser.parser.parse(algebra.expression) + ", "
 		outstring += "name = \"" + algebra.name + "\")"
-		print outstring
-	if len(algebras.values()) > 0:
-		print
+		print(outstring)
+	if len(list(algebras.values())) > 0:
+		print()
 
 def printMatrices():
     global matrices
     startCounter = 1
-    for matrix in matrices.values():
+    for matrix in list(matrices.values()):
         outstring = "matrix" + matrix.name + " <- "
         outstring += "mxMatrix(type = \"" + matrix.type + "\", "
         outstring += "nrow = " + str(matrix.nrow) + ", "
@@ -151,7 +151,7 @@ def printMatrices():
         if matrix.specification == None:
             outstring += "free = " + str(matrix.free).upper() + ", "
         else:
-            freelist = map(lambda x: x > 0, matrix.specification)
+            freelist = [x > 0 for x in matrix.specification]
             freestring = str(freelist).upper()
             freestring = string.replace(freestring, "[", "c(")
             freestring = string.replace(freestring, "]", ")")
@@ -169,36 +169,36 @@ def printMatrices():
             outstring += "labels = " + "makeLabels(" + specstring + "), "
         outstring += "byrow = TRUE, "
         outstring += "name = \"" + matrix.name + "\")"
-        print outstring
-	if len(matrices.values()) > 0:
-		print
+        print(outstring)
+	if len(list(matrices.values())) > 0:
+		print()
 
 
 def printValueBuffer():
 	global valBuffer
 	if valBuffer != "":
-		print valBuffer
+		print(valBuffer)
 
 def printModel():
 	global matrices, algebras
 	if title == None:
-		print "model <- mxModel()"
+		print("model <- mxModel()")
 	else:
-		print "model <- mxModel(name = \"" + title + "\")"
-	print
-	matrixNames = str(map(lambda x: "matrix" + x, matrices.keys()))
+		print("model <- mxModel(name = \"" + title + "\")")
+	print()
+	matrixNames = str(["matrix" + x for x in list(matrices.keys())])
 	matrixNames = string.replace(matrixNames, "[", "")
 	matrixNames = string.replace(matrixNames, "]", "")
 	matrixNames = string.replace(matrixNames, "'", "")
 	if len(matrixNames) > 0:
-		print "model <- mxModel(model, " + matrixNames + ")"
-	algNames = str(map(lambda x: "algebra" + x, algebras.keys()))
+		print("model <- mxModel(model, " + matrixNames + ")")
+	algNames = str(["algebra" + x for x in list(algebras.keys())])
 	algNames = string.replace(algNames, "[", "")
 	algNames = string.replace(algNames, "]", "")
 	algNames = string.replace(algNames, "'", "")
 	if len(algNames) > 0:
-		print "model <- mxModel(model, " + algNames + ")"
-	print
+		print("model <- mxModel(model, " + algNames + ")")
+	print()
 
 
 specLength = {   "Diag"  : lambda row, col: row,
@@ -216,7 +216,7 @@ mxDirectives = {    "\s*title" : parseTi
                     "\s*(start|value)" : parseStartOrValue }
 
 def tryDirectives ( mxInput ):
-    for directive in mxDirectives.keys():
+    for directive in list(mxDirectives.keys()):
         match = re.match(directive, mxInput, re.IGNORECASE)
         if (match != None):
             subtract = mxDirectives[directive](mxInput)
@@ -236,10 +236,10 @@ def parseModel( mxInput ):
 	while len(mxInput) > 0:
 		mxInput = tryDirectives(mxInput)
 
-	print
-	print "require(OpenMx)"
-	print "makeLabels <- function(x) { sapply(x, function(y) { paste('var', y, sep = '') })}"
-	print
+	print()
+	print("require(OpenMx)")
+	print("makeLabels <- function(x) { sapply(x, function(y) { paste('var', y, sep = '') })}")
+	print()
 
 
 	# Print matrix declarations
--- a/inst/tools/sphinxToR.py
+++ b/inst/tools/sphinxToR.py
@@ -1,12 +1,12 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 import re
 import sys
-print "require(OpenMx)"
-print "#################################################"
-print "# THIS IS AN AUTOGENERATED FILE"
-print "# ANY CHANGES MADE TO THIS FILE WILL NOT BE SAVED"
-print "#################################################"
+print("require(OpenMx)")
+print("#################################################")
+print("# THIS IS AN AUTOGENERATED FILE")
+print("# ANY CHANGES MADE TO THIS FILE WILL NOT BE SAVED")
+print("#################################################")
 p = re.compile("\.\. code-block:: r.*?\r?\n\r?\n(.+?)\r?\n[ \t]*\r?\n[\w`]", re.DOTALL)
 matches = p.finditer(sys.stdin.read())
 for match in matches:
-	print match.group(1)
+	print(match.group(1))
--- a/inst/tools/mxAlgebraParser.py
+++ b/inst/tools/mxAlgebraParser.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 
 # Mx 1.0 algebras are parsed using the
 # PLY implementation of lex and yacc parsing tools for Python.
