Fix file, long, raw_input, and xrange for Python 3

This commit is contained in:
cclauss
2019-01-05 21:19:37 +01:00
parent fdb855e366
commit 51ab27f54a
12 changed files with 46 additions and 20 deletions

View File

@@ -6,6 +6,11 @@ import unittest
from kdtree import KDTree_2Int, KDTree_4Int, KDTree_3Float, KDTree_4Float, KDTree_6Float
try:
long
except NameError:
long = int
class KDTree_2IntTestCase(unittest.TestCase):
def test_empty(self):

View File

@@ -98,7 +98,7 @@ def read(filename):
verts.append([d_point[0],d_point[1],d_point[2]])
meshdata = []
for d_face in d_nobj.obj.faces.array:
meshdata.append([verts[int(d_face[i])] for i in xrange(3)])
meshdata.append([verts[int(d_face[i])] for i in range(3)])
m = [tuple(r) for r in d_nobj.obj.matrix.array]
m = m[0] + m[1] + m[2] + m[3]
placement = FreeCAD.Placement(FreeCAD.Matrix(*m))

View File

@@ -21,6 +21,8 @@
#* *
#***************************************************************************
from six.moves import xrange
import FreeCAD, Mesh, os, numpy, MeshPart, Arch, Draft
if FreeCAD.GuiUp:
from DraftTools import translate

View File

@@ -40,6 +40,11 @@ import sys
import math,FreeCAD
from FreeCAD import Vector, Matrix
try:
long
except NameError:
long = int
params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
def precision():
return params.GetInt("precision",6)

View File

@@ -16,7 +16,14 @@ but random access is not allowed."""
import struct, sys, time, os
import zlib
import io
import __builtin__
from six.moves import xrange
from six.moves.builtins import open as builtin_open
try:
long
except NameError:
long = int
__all__ = ["GzipFile","open"]
@@ -99,7 +106,7 @@ class GzipFile(io.BufferedIOBase):
if mode and 'b' not in mode:
mode += 'b'
if fileobj is None:
fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb')
fileobj = self.myfileobj = builtin_open(filename, mode or 'rb')
if filename is None:
# Issue #13781: os.fdopen() creates a fileobj with a bogus name
# attribute. Avoid saving this in the gzip header's filename field.
@@ -504,13 +511,13 @@ def _test():
print("filename doesn't end in .gz:", repr(arg))
continue
f = open(arg, "rb")
g = __builtin__.open(arg[:-3], "wb")
g = builtin_open(arg[:-3], "wb")
else:
if arg == "-":
f = sys.stdin
g = GzipFile(filename="", mode="wb", fileobj=sys.stdout)
else:
f = __builtin__.open(arg, "rb")
f = builtin_open(arg, "rb")
g = open(arg + ".gz", "wb")
while True:
chunk = f.read(1024)

View File

@@ -24,6 +24,11 @@ __title__="FreeCAD OpenSCAD Workbench - Parametric Features"
__author__ = "Sebastian Hoogen"
__url__ = ["http://www.freecadweb.org"]
try:
long
except NameError:
long = int
'''
This Script includes python Features to represent OpenSCAD Operations
'''

View File

@@ -22,6 +22,8 @@
# * *
# ***************************************************************************
from six.moves import xrange
import FreeCAD
import FreeCADGui
import PathScripts.PathLog as PathLog

View File

@@ -24,6 +24,8 @@
from __future__ import print_function
from six.moves import xrange
import FreeCAD
import MeshPart
# import Part

View File

@@ -23,11 +23,6 @@
## TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
## SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# from __future__ import generators # only needed for Python 2.2
import sys
import os.path
import time
@@ -36,6 +31,7 @@ import urllib2
from xml.sax import handler, make_parser
import xml.sax.xmlreader
from six.moves import raw_input
##from IPython.Shell import IPShellEmbed
##args = ''
@@ -2549,7 +2545,7 @@ class SaxSelectorHandler(handler.ContentHandler):
def parseSelect(inFileName):
infile = file(inFileName, 'r')
infile = open(inFileName, 'r')
topElementName = None
parser = make_parser()
documentHandler = SaxSelectorHandler()
@@ -2758,7 +2754,7 @@ def get_impl_body(classBehavior, baseImplUrl, implUrl):
## trylocal = 1
## if trylocal:
## try:
## implFile = file(implUrl)
## implFile = open(implUrl)
## impl = implFile.read()
## implFile.close()
## except:
@@ -2888,7 +2884,7 @@ class SaxSelectorHandler(handler.ContentHandler):
def parseSelect(inFileName):
infile = file(inFileName, 'r')
infile = open(inFileName, 'r')
topElementName = None
parser = make_parser()
documentHandler = SaxSelectorHandler()
@@ -3146,9 +3142,9 @@ def makeFile(outFileName):
if (not Force) and os.path.exists(outFileName):
reply = raw_input('File %s exists. Overwrite? (y/n): ' % outFileName)
if reply == 'y':
outFile = file(outFileName, 'w')
outFile = open(outFileName, 'w')
else:
outFile = file(outFileName, 'w')
outFile = open(outFileName, 'w')
return outFile

View File

@@ -2286,7 +2286,7 @@ class SaxSelectorHandler(handler.ContentHandler):
def parseSelect(inFileName):
infile = file(inFileName, 'r')
infile = open(inFileName, 'r')
topElementName = None
parser = make_parser()
documentHandler = SaxSelectorHandler()

View File

@@ -33,6 +33,8 @@ This script builds qhrlp files from a local copy of the wiki
import sys, os, re, tempfile, getopt, shutil
from urllib2 import urlopen, HTTPError
from six.moves import raw_input
# CONFIGURATION #################################################
FOLDER = "./localwiki"

View File

@@ -242,8 +242,8 @@ def fetch_resources(uri, rel):
def createpdf_pisa(pagename,folder=TMPFOLDER):
"creates a pdf file from a saved page using pisa (python module)"
infile = file(folder + os.sep + pagename+'.html','ro')
outfile = file(folder + os.sep + pagename+'.pdf','wb')
infile = open(folder + os.sep + pagename+'.html','ro')
outfile = open(folder + os.sep + pagename+'.pdf','wb')
if VERBOSE: print ("Converting " + pagename + " to pdf...")
pdf = pisa.CreatePDF(infile,outfile,folder,link_callback=fetch_resources)
outfile.close()
@@ -272,12 +272,12 @@ def joinpdf(folder=TMPFOLDER,startpage=INDEX,outputname='freecad.pdf'):
for p in pages:
if exists(p[:-5]):
if VERBOSE: print ('Appending',p)
try: inputfile = PdfFileReader(file(folder+os.sep+p[:-5]+'.pdf','rb'))
try: inputfile = PdfFileReader(open(folder+os.sep+p[:-5]+'.pdf','rb'))
except: print ('Unable to append',p)
else:
for i in range(inputfile.getNumPages()):
result.addPage(inputfile.getPage(i))
outputfile = file(OUTPUTPATH + os.sep + outputname,'wb')
outputfile = open(OUTPUTPATH + os.sep + outputname,'wb')
result.write(outputfile)
outputfile.close()
if VERBOSE: print ('Successfully created',OUTPUTPATH,os.sep,outputname)