py3: OpenSCAD: use io.open more explicit

This commit is contained in:
Clemens Weissbacher
2018-10-29 17:17:53 +01:00
parent 1538a14eca
commit 1be9f18b52
3 changed files with 8 additions and 11 deletions

View File

@@ -41,10 +41,7 @@ except AttributeError:
from PySide import QtGui
return QtGui.QApplication.translate(context, text, None)
try:
from io import open
except ImportError:
from codecs import open
import io
try:
import FreeCAD
@@ -180,7 +177,7 @@ def callopenscadstring(scadstr,outputext='csg'):
import os,tempfile,time
dir1=tempfile.gettempdir()
inputfilename=os.path.join(dir1,'%s.scad' % next(tempfilenamegen))
inputfile = open(inputfilename,'w', encoding="utf8")
inputfile = io.open(inputfilename,'w', encoding="utf8")
inputfile.write(scadstr)
inputfile.close()
outputfilename = callopenscad(inputfilename,outputext=outputext,\

View File

@@ -50,7 +50,9 @@ convexity = 'convexity = %d' % conv
#***************************************************************************
# Radius values not fixed for value apart from cylinder & Cone
# no doubt there will be a problem when they do implement Value
pythonopen = open
if open.__module__ in ['__builtin__', 'io']:
pythonopen = open # to distinguish python built-in open function from the one declared here
def center(b):
if b == 2:
@@ -247,7 +249,7 @@ def export(exportList,filename):
# process Objects
print("\nStart Export 0.1d\n")
print("Open Output File")
csg = pythonopen(filename,'w', encoding="utf8")
csg = pythonopen(filename,'w')
print("Write Initial Output")
# Not sure if comments as per scad are allowed in csg file
csg.write("// CSG file generated from FreeCAD %s\n" % \

View File

@@ -33,7 +33,7 @@ __url__ = ["http://www.sloan-home.co.uk/ImportCSG"]
printverbose = False
import FreeCAD, os, sys
import FreeCAD, io, os, sys
if FreeCAD.GuiUp:
import FreeCADGui
gui = True
@@ -52,8 +52,6 @@ from OpenSCADUtils import *
params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD")
printverbose = params.GetBool('printVerbose',False)
pythonopen = open
# Get the token map from the lexer. This is required.
import tokrules
from tokrules import tokens
@@ -135,7 +133,7 @@ def processcsg(filename):
if printverbose: print('Parser Loaded')
# Give the lexer some input
#f=open('test.scad', 'r')
f = pythonopen(filename, 'r', encoding="utf8")
f = io.open(filename, 'r', encoding="utf8")
#lexer.input(f.read())
if printverbose: print('Start Parser')