diff --git a/src/Mod/Arch/exportIFC.py b/src/Mod/Arch/exportIFC.py index e168c3bf93..e30d30bd70 100644 --- a/src/Mod/Arch/exportIFC.py +++ b/src/Mod/Arch/exportIFC.py @@ -46,6 +46,7 @@ from DraftGeomUtils import vec from importIFCHelper import dd2dms from draftutils import params from draftutils.messages import _msg, _err +from builtins import open as pyopen if FreeCAD.GuiUp: import FreeCADGui @@ -54,10 +55,6 @@ __title__ = "FreeCAD IFC export" __author__ = ("Yorik van Havre", "Jonathan Wiedemann", "Bernd Hahnebach") __url__ = "https://www.freecad.org" -# Save the Python open function because it will be redefined -if open.__module__ in ['__builtin__', 'io']: - pyopen = open - # Templates and other definitions **** # Specific FreeCAD <-> IFC slang translations translationtable = { diff --git a/src/Mod/Arch/importGBXML.py b/src/Mod/Arch/importGBXML.py index 5cc0f5ea18..ae0c6f1389 100644 --- a/src/Mod/Arch/importGBXML.py +++ b/src/Mod/Arch/importGBXML.py @@ -25,6 +25,7 @@ __url__ = "https://www.freecad.org" import FreeCAD import Draft +from builtins import open as pyopen if FreeCAD.GuiUp: from draftutils.translate import translate diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importIFC.py index 6b9340243d..0ef3528459 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importIFC.py @@ -44,6 +44,7 @@ import importIFCmulticore from draftutils import params from draftutils.messages import _msg, _err +from builtins import open as pyopen if FreeCAD.GuiUp: import FreeCADGui as Gui @@ -55,10 +56,6 @@ __url__ = "https://www.freecad.org" DEBUG = False # Set to True to see debug messages. Otherwise, totally silent ZOOMOUT = True # Set to False to not zoom extents after import -# Save the Python open function because it will be redefined -if open.__module__ in ['__builtin__', 'io']: - pyopen = open - # Templates and other definitions **** # which IFC type must create which FreeCAD type diff --git a/src/Mod/Arch/importIFClegacy.py b/src/Mod/Arch/importIFClegacy.py index 256b29056b..872e339e40 100644 --- a/src/Mod/Arch/importIFClegacy.py +++ b/src/Mod/Arch/importIFClegacy.py @@ -29,6 +29,7 @@ import FreeCAD, Arch, Draft, os, sys, time, Part, DraftVecUtils, uuid, math, re from draftutils import params from draftutils.translate import translate +from builtins import open as pyopen __title__="FreeCAD IFC importer" __author__ = "Yorik van Havre" @@ -54,8 +55,7 @@ supportedIfcTypes = ["IfcSite", "IfcBuilding", "IfcBuildingStorey", "IfcBeam", " "IfcPile", "IfcFooting", "IfcReinforcingBar", "IfcTendon"] # TODO : shading device not supported? -if open.__module__ in ['__builtin__','io']: - pyopen = open # because we'll redefine open below + def open(filename,skip=None): "called when freecad opens a file" diff --git a/src/Mod/Arch/importJSON.py b/src/Mod/Arch/importJSON.py index 32133898f9..83239da499 100644 --- a/src/Mod/Arch/importJSON.py +++ b/src/Mod/Arch/importJSON.py @@ -27,6 +27,7 @@ import FreeCAD import Draft import Mesh import Part +from builtins import open as pyopen if FreeCAD.GuiUp: import FreeCADGui @@ -37,8 +38,7 @@ else: def translate(ctxt, txt): return txt -if open.__module__ in ['__builtin__','io']: - pythonopen = open + def export(exportList, filename): @@ -52,7 +52,7 @@ def export(exportList, filename): } # Write file - outfile = pythonopen(filename, "w") + outfile = pyopen(filename, "w") json.dump(data, outfile, separators = (',', ':')) outfile.close() diff --git a/src/Mod/Arch/importOBJ.py b/src/Mod/Arch/importOBJ.py index 70f95f790b..97ae8e9ceb 100644 --- a/src/Mod/Arch/importOBJ.py +++ b/src/Mod/Arch/importOBJ.py @@ -32,6 +32,7 @@ import Mesh import MeshPart import Part from draftutils import params +from builtins import open as pyopen if FreeCAD.GuiUp: from draftutils.translate import translate @@ -50,8 +51,7 @@ else: # and supports exporting faces with more than 3 vertices # and supports object colors / materials -if open.__module__ in ['__builtin__','io']: - pythonopen = open + def findVert(aVertex,aList): "finds aVertex in aList, returns index" @@ -260,7 +260,7 @@ def export(exportList,filename,colors=None): outfile.close() FreeCAD.Console.PrintMessage(translate("Arch","Successfully written") + " " + filename + "\n") if materials: - outfile = pythonopen(filenamemtl,"w") + outfile = pyopen(filenamemtl,"w") outfile.write("# FreeCAD v" + ver[0] + "." + ver[1] + " build" + ver[2] + " Arch module\n") outfile.write("# https://www.freecad.org\n") kinds = {"AmbientColor":"Ka ","DiffuseColor":"Kd ","SpecularColor":"Ks ","EmissiveColor":"Ke ","Transparency":"Tr ","Dissolve":"d "} @@ -306,7 +306,7 @@ def insert(filename,docname): doc = FreeCAD.newDocument(docname) FreeCAD.ActiveDocument = doc - with pythonopen(filename,"r") as infile: + with pyopen(filename,"r") as infile: verts = [] facets = [] activeobject = None @@ -327,7 +327,7 @@ def insert(filename,docname): if line[:7] == "mtllib ": matlib = os.path.join(os.path.dirname(filename),line[7:]) if os.path.exists(matlib): - with pythonopen(matlib,"r") as matfile: + with pyopen(matlib,"r") as matfile: mname = None color = None trans = None diff --git a/src/Mod/Arch/importSH3D.py b/src/Mod/Arch/importSH3D.py index 6ae6f9c25e..20244470c1 100644 --- a/src/Mod/Arch/importSH3D.py +++ b/src/Mod/Arch/importSH3D.py @@ -34,6 +34,7 @@ import Arch import Draft import Mesh import Part +from builtins import open as pyopen ## @package importSH3D # \ingroup ARCH @@ -43,8 +44,7 @@ import Part DEBUG = True -if open.__module__ in ['__builtin__','io']: - pyopen = open # because we'll redefine open below + def open(filename): diff --git a/src/Mod/Arch/importSHP.py b/src/Mod/Arch/importSHP.py index 4fe6c88eb3..46f1687ce7 100644 --- a/src/Mod/Arch/importSHP.py +++ b/src/Mod/Arch/importSHP.py @@ -22,10 +22,10 @@ import os import FreeCAD +from builtins import open as pyopen translate = FreeCAD.Qt.translate -if open.__module__ in ['__builtin__','io']: - pythonopen = open + def open(filename): @@ -142,7 +142,7 @@ def checkShapeFileLibrary(): return False b = u.read() fp = os.path.join(FreeCAD.getUserMacroDir(True),"shapefile.py") - f = pythonopen(fp,"wb") + f = pyopen(fp,"wb") f.write(b) f.close() try: diff --git a/src/Mod/Arch/importWebGL.py b/src/Mod/Arch/importWebGL.py index c0c0b2df3d..aa57efb654 100644 --- a/src/Mod/Arch/importWebGL.py +++ b/src/Mod/Arch/importWebGL.py @@ -44,6 +44,7 @@ import Part import OfflineRenderingUtils import json import textwrap +from builtins import open as pyopen if FreeCAD.GuiUp: import FreeCADGui @@ -52,7 +53,7 @@ else: FreeCADGui = None def translate(ctxt, txt): return txt -if open.__module__ in ['__builtin__','io']: pythonopen = open + ## @package importWebGL # \ingroup ARCH @@ -868,7 +869,7 @@ def export( exportList, filename, colors = None, camera = None ): html = html.replace('$data', json.dumps(data, separators=(',', ':')) ) # Shape Data - outfile = pythonopen(filename, "w") + outfile = pyopen(filename, "w") outfile.write( html ) outfile.close() FreeCAD.Console.PrintMessage( translate("Arch", "Successfully written") + ' ' + filename + "\n" ) diff --git a/src/Mod/CAM/Path/Post/scripts/KineticNCBeamicon2_post.py b/src/Mod/CAM/Path/Post/scripts/KineticNCBeamicon2_post.py index ad9ad982d3..ec721a6716 100644 --- a/src/Mod/CAM/Path/Post/scripts/KineticNCBeamicon2_post.py +++ b/src/Mod/CAM/Path/Post/scripts/KineticNCBeamicon2_post.py @@ -40,6 +40,7 @@ import datetime import shlex from PathScripts import PathUtils import PathScripts.PathUtils as PathUtils +from builtins import open as pyopen TOOLTIP = """ This is a postprocessor file for the Path workbench. It is used to @@ -137,9 +138,7 @@ POST_OPERATION = """""" TOOL_CHANGE = """M05 M09""" -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): @@ -279,7 +278,7 @@ def export(objectslist, filename, argstring): print("done postprocessing.") if not filename == "-": - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/centroid_post.py b/src/Mod/CAM/Path/Post/scripts/centroid_post.py index 6f40f0ecc9..a22f663500 100644 --- a/src/Mod/CAM/Path/Post/scripts/centroid_post.py +++ b/src/Mod/CAM/Path/Post/scripts/centroid_post.py @@ -30,6 +30,7 @@ import Path.Post.Utils as PostUtils import PathScripts.PathUtils as PathUtils import datetime import Path +from builtins import open as pyopen TOOLTIP = """ This is a postprocessor file for the Path workbench. It is used to @@ -126,9 +127,7 @@ POST_OPERATION = """""" TOOL_CHANGE = """""" -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): @@ -242,7 +241,7 @@ def export(objectslist, filename, argstring): print("done postprocessing.") if not filename == "-": - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/dumper_post.py b/src/Mod/CAM/Path/Post/scripts/dumper_post.py index 0681d1da66..b3d471ae25 100644 --- a/src/Mod/CAM/Path/Post/scripts/dumper_post.py +++ b/src/Mod/CAM/Path/Post/scripts/dumper_post.py @@ -24,6 +24,7 @@ import datetime import Path.Post.Utils as PostUtils import PathScripts.PathUtils as PathUtils +from builtins import open as pyopen TOOLTIP = """ Dumper is an extremely simple postprocessor file for the Path workbench. It is used @@ -35,9 +36,7 @@ shows the dialog so you can see it. Useful for debugging, but not much else. now = datetime.datetime.now() SHOW_EDITOR = True -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def export(objectslist, filename, argstring): diff --git a/src/Mod/CAM/Path/Post/scripts/dxf_post.py b/src/Mod/CAM/Path/Post/scripts/dxf_post.py index ba9ec2e603..24d3b8cae9 100644 --- a/src/Mod/CAM/Path/Post/scripts/dxf_post.py +++ b/src/Mod/CAM/Path/Post/scripts/dxf_post.py @@ -27,6 +27,7 @@ import Path import PathScripts.PathUtils as PathUtils import datetime import importDXF +from builtins import open as pyopen TOOLTIP = """ This is a postprocessor file for the Path workbench. It is used to @@ -58,9 +59,7 @@ else: Path.Log.setLevel(Path.Log.Level.INFO, Path.Log.thisModule()) -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): diff --git a/src/Mod/CAM/Path/Post/scripts/dynapath_4060_post.py b/src/Mod/CAM/Path/Post/scripts/dynapath_4060_post.py index b19833a160..17b7fb8805 100644 --- a/src/Mod/CAM/Path/Post/scripts/dynapath_4060_post.py +++ b/src/Mod/CAM/Path/Post/scripts/dynapath_4060_post.py @@ -33,6 +33,7 @@ import datetime import shlex import Path.Post.Utils as PostUtils import PathScripts.PathUtils as PathUtils +from builtins import open as pyopen TOOLTIP = """ This is a post processor file for the FreeCAD Path workbench. It is used to @@ -151,9 +152,7 @@ M30 # Create following variable for use with the 2nd reference plane. clearanceHeight = None -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): @@ -346,7 +345,7 @@ def export(objectslist, filename, argstring): print("done postprocessing.") if not filename == "-": - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/dynapath_post.py b/src/Mod/CAM/Path/Post/scripts/dynapath_post.py index 6e6bcea513..af1ae96f62 100644 --- a/src/Mod/CAM/Path/Post/scripts/dynapath_post.py +++ b/src/Mod/CAM/Path/Post/scripts/dynapath_post.py @@ -38,6 +38,7 @@ import PathScripts.PathUtils as PathUtils import argparse import datetime import shlex +from builtins import open as pyopen TOOLTIP = """ This is a postprocessor file for the Path workbench. It is used to @@ -153,9 +154,7 @@ POST_OPERATION = """""" TOOL_CHANGE = """""" -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): @@ -284,7 +283,7 @@ def export(objectslist, filename, argstring): print("done postprocessing.") - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/estlcam_post.py b/src/Mod/CAM/Path/Post/scripts/estlcam_post.py index eb3f53ee76..5a5339891d 100644 --- a/src/Mod/CAM/Path/Post/scripts/estlcam_post.py +++ b/src/Mod/CAM/Path/Post/scripts/estlcam_post.py @@ -35,6 +35,7 @@ import argparse import datetime import shlex import re +from builtins import open as pyopen TOOLTIP = """ @@ -156,13 +157,6 @@ CURRENT_X = 0 CURRENT_Y = 0 CURRENT_Z = 0 - -# *************************************************************************** -# * to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open - - def processArguments(argstring): global OUTPUT_HEADER @@ -346,7 +340,7 @@ def export(objectslist, filename, argstring): print("Done postprocessing.") # write the file - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/example_post.py b/src/Mod/CAM/Path/Post/scripts/example_post.py index 9f2d74dfe2..6cd2f27950 100644 --- a/src/Mod/CAM/Path/Post/scripts/example_post.py +++ b/src/Mod/CAM/Path/Post/scripts/example_post.py @@ -22,6 +22,7 @@ # *************************************************************************** import datetime +from builtins import open as pyopen TOOLTIP = """ This is an example postprocessor file for the Path workbench. It is used @@ -33,9 +34,7 @@ to GCode. now = datetime.datetime.now() -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def export(objectslist, filename, argstring): @@ -48,7 +47,7 @@ def export(objectslist, filename, argstring): print("the given object is not a path") gcode = obj.Path.toGCode() gcode = parse(gcode) - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(gcode) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/example_pre.py b/src/Mod/CAM/Path/Post/scripts/example_pre.py index 8c2a0a599c..8373effa0c 100644 --- a/src/Mod/CAM/Path/Post/scripts/example_pre.py +++ b/src/Mod/CAM/Path/Post/scripts/example_pre.py @@ -35,6 +35,7 @@ from GCode. import FreeCAD import Path import os +from builtins import open as pyopen # LEVEL = Path.Log.Level.DEBUG LEVEL = Path.Log.Level.INFO @@ -44,9 +45,7 @@ if LEVEL == Path.Log.Level.DEBUG: Path.Log.trackModule(Path.Log.thisModule()) -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def open(filename): @@ -60,7 +59,7 @@ def open(filename): def insert(filename, docname): "called when freecad imports a file" Path.Log.track(filename) - gfile = pythonopen(filename) + gfile = pyopen(filename) gcode = gfile.read() gfile.close() gcode = parse(gcode) diff --git a/src/Mod/CAM/Path/Post/scripts/fablin_post.py b/src/Mod/CAM/Path/Post/scripts/fablin_post.py index d2e08fabb6..64ee445fac 100644 --- a/src/Mod/CAM/Path/Post/scripts/fablin_post.py +++ b/src/Mod/CAM/Path/Post/scripts/fablin_post.py @@ -27,6 +27,7 @@ import datetime import Path.Post.Utils as PostUtils import PathScripts.PathUtils as PathUtils +from builtins import open as pyopen now = datetime.datetime.now() @@ -90,9 +91,7 @@ POST_OPERATION = """""" TOOL_CHANGE = """""" -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): @@ -205,7 +204,7 @@ def export(objectslist, filename, argstring): print("done postprocessing.") - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/fangling_post.py b/src/Mod/CAM/Path/Post/scripts/fangling_post.py index 70b0ccd238..05b4782d2d 100644 --- a/src/Mod/CAM/Path/Post/scripts/fangling_post.py +++ b/src/Mod/CAM/Path/Post/scripts/fangling_post.py @@ -39,6 +39,7 @@ import shlex #from PathScripts import PostUtils import Path.Post.Utils as PostUtils from PathScripts import PathUtils +from builtins import open as pyopen TOOLTIP = ''' This is a postprocessor file for the Path workbench. It is used to @@ -111,9 +112,7 @@ POST_OPERATION = '''''' # Tool Change commands will be inserted before a tool change TOOL_CHANGE = '''''' -# to distinguish python built-in open function from the one declared below -if open.__module__ in ['__builtin__','io']: - pythonopen = open + def processArguments(argstring): @@ -428,7 +427,7 @@ def parse(pathobj): def writeFile(filename, final): if not filename == '-': - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/fanuc_post.py b/src/Mod/CAM/Path/Post/scripts/fanuc_post.py index 2c76e4b875..d87115c4cc 100644 --- a/src/Mod/CAM/Path/Post/scripts/fanuc_post.py +++ b/src/Mod/CAM/Path/Post/scripts/fanuc_post.py @@ -31,6 +31,7 @@ import shlex import os.path import Path.Post.Utils as PostUtils import PathScripts.PathUtils as PathUtils +from builtins import open as pyopen TOOLTIP = """ This is a postprocessor file for the Path workbench. It is used to @@ -137,9 +138,7 @@ POST_OPERATION = """""" # Tool Change commands will be inserted before a tool change TOOL_CHANGE = """""" -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): @@ -311,7 +310,7 @@ def export(objectslist, filename, argstring): print("done postprocessing.") if not filename == "-": - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/gcode_pre.py b/src/Mod/CAM/Path/Post/scripts/gcode_pre.py index f0921273b9..515bfb0bbe 100644 --- a/src/Mod/CAM/Path/Post/scripts/gcode_pre.py +++ b/src/Mod/CAM/Path/Post/scripts/gcode_pre.py @@ -48,6 +48,7 @@ import PathScripts.PathUtils as PathUtils import os import re from PySide.QtCore import QT_TRANSLATE_NOOP +from builtins import open as pyopen if FreeCAD.GuiUp: import Path.Op.Gui.Custom as PathCustomGui @@ -80,9 +81,7 @@ class PathNoJobException(Exception): super().__init__("No job object") -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def open(filename): @@ -186,7 +185,7 @@ def _identifygcodeByToolNumberList(filename): Path.Log.track(filename) gcodeByToolNumberList = [] - gfile = pythonopen(filename) + gfile = pyopen(filename) gcode = gfile.read() gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/grbl_post.py b/src/Mod/CAM/Path/Post/scripts/grbl_post.py old mode 100755 new mode 100644 index a3ab8dbbbc..a694acf7d6 --- a/src/Mod/CAM/Path/Post/scripts/grbl_post.py +++ b/src/Mod/CAM/Path/Post/scripts/grbl_post.py @@ -34,6 +34,7 @@ import argparse import datetime import shlex import re +from builtins import open as pyopen TOOLTIP = """ @@ -182,12 +183,6 @@ CURRENT_Y = 0 CURRENT_Z = 0 -# *************************************************************************** -# * to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open - - def processArguments(argstring): global OUTPUT_HEADER @@ -405,10 +400,9 @@ def export(objectslist, filename, argstring): print("Done postprocessing.") # write the file - if not filename == "-": - gfile = pythonopen(filename, "w") - gfile.write(final) - gfile.close() + if filename != "-": + with pyopen(filename, "w") as gfile: + gfile.write(final) return final diff --git a/src/Mod/CAM/Path/Post/scripts/heidenhain_post.py b/src/Mod/CAM/Path/Post/scripts/heidenhain_post.py index e8523e4e4a..570ad54f08 100644 --- a/src/Mod/CAM/Path/Post/scripts/heidenhain_post.py +++ b/src/Mod/CAM/Path/Post/scripts/heidenhain_post.py @@ -27,6 +27,7 @@ import Path import PathScripts import shlex import math +from builtins import open as pyopen # **************************************************************************# # USER EDITABLE STUFF HERE # @@ -246,8 +247,7 @@ parser.add_argument( TOOLTIP_ARGS = parser.format_help() -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): @@ -540,7 +540,7 @@ def export(objectslist, filename, argstring): if SHOW_EDITOR: PostUtils.editor(Program_Out) - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(Program_Out) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/jtech_post.py b/src/Mod/CAM/Path/Post/scripts/jtech_post.py index 3012bf1912..e58bc17925 100644 --- a/src/Mod/CAM/Path/Post/scripts/jtech_post.py +++ b/src/Mod/CAM/Path/Post/scripts/jtech_post.py @@ -29,6 +29,7 @@ import datetime import shlex import Path.Post.Utils as PostUtils import PathScripts.PathUtils as PathUtils +from builtins import open as pyopen TOOLTIP = """ This is a postprocessor file for the Path workbench. It is used to @@ -135,9 +136,7 @@ TOOL_CHANGE = """""" POWER_ON_DELAY = 0 -# to distinguish python built-in open function from the one declared below -if open.__module__ == "__builtin__": - pythonopen = open + def processArguments(argstring): @@ -253,7 +252,7 @@ def export(objectslist, filename, argstring): print("done postprocessing.") if not filename == "-": - gfile = pythonopen(filename, "wb") + gfile = pyopen(filename, "wb") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py b/src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py index a7fb3b29bc..a57d066bd6 100644 --- a/src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py +++ b/src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py @@ -29,6 +29,7 @@ import datetime import shlex import Path.Post.Utils as PostUtils import PathScripts.PathUtils as PathUtils +from builtins import open as pyopen TOOLTIP = """ This is a postprocessor file for the Path workbench. It is used to @@ -128,9 +129,7 @@ POST_OPERATION = """""" # Tool Change commands will be inserted before a tool change TOOL_CHANGE = """""" -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): @@ -290,7 +289,7 @@ def export(objectslist, filename, argstring): print("done postprocessing.") if not filename == "-": - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/mach3_mach4_post.py b/src/Mod/CAM/Path/Post/scripts/mach3_mach4_post.py index 4c25c38b36..5790586344 100644 --- a/src/Mod/CAM/Path/Post/scripts/mach3_mach4_post.py +++ b/src/Mod/CAM/Path/Post/scripts/mach3_mach4_post.py @@ -29,6 +29,7 @@ import datetime import shlex import Path.Post.Utils as PostUtils import PathScripts.PathUtils as PathUtils +from builtins import open as pyopen TOOLTIP = """ This is a postprocessor file for the Path workbench. It is used to @@ -128,9 +129,7 @@ POST_OPERATION = """""" # Tool Change commands will be inserted before a tool change TOOL_CHANGE = """""" -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): @@ -291,7 +290,7 @@ def export(objectslist, filename, argstring): print("done postprocessing.") if not filename == "-": - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/opensbp_post.py b/src/Mod/CAM/Path/Post/scripts/opensbp_post.py index 8826a5a0e5..afe4b60f1a 100644 --- a/src/Mod/CAM/Path/Post/scripts/opensbp_post.py +++ b/src/Mod/CAM/Path/Post/scripts/opensbp_post.py @@ -24,6 +24,7 @@ import datetime import Path.Post.Utils as PostUtils import PathScripts.PathUtils as PathUtils +from builtins import open as pyopen TOOLTIP = """ @@ -79,9 +80,7 @@ POST_OPERATION = """""" # Tool Change commands will be inserted before a tool change TOOL_CHANGE = """""" -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + CurrentState = {} @@ -183,7 +182,7 @@ def export(objectslist, filename, argstring): print("done postprocessing.") # Write the output - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/opensbp_pre.py b/src/Mod/CAM/Path/Post/scripts/opensbp_pre.py index 42e6ab9704..0772b0031d 100644 --- a/src/Mod/CAM/Path/Post/scripts/opensbp_pre.py +++ b/src/Mod/CAM/Path/Post/scripts/opensbp_pre.py @@ -52,6 +52,7 @@ import FreeCAD import Path import os import Path +from builtins import open as pyopen AXIS = ( "X", @@ -62,9 +63,7 @@ AXIS = ( ) # OpenSBP always puts multiaxis move parameters in this order SPEEDS = "XY", "Z", "A", "B" -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def open(filename): @@ -78,7 +77,7 @@ def insert(filename, docname): """called when freecad imports a file This insert expects parse to return a list of strings each string will become a separate path""" - gfile = pythonopen(filename) + gfile = pyopen(filename) gcode = gfile.read() gfile.close() gcode = parse(gcode) diff --git a/src/Mod/CAM/Path/Post/scripts/philips_post.py b/src/Mod/CAM/Path/Post/scripts/philips_post.py index d52cb6eb59..5561bc0c94 100644 --- a/src/Mod/CAM/Path/Post/scripts/philips_post.py +++ b/src/Mod/CAM/Path/Post/scripts/philips_post.py @@ -30,6 +30,7 @@ import time import Path.Post.Utils as PostUtils import PathScripts.PathUtils as PathUtils import math +from builtins import open as pyopen TOOLTIP = """Post processor for Maho M 600E mill @@ -296,8 +297,7 @@ GCODE_FOOTER = "M30" linenr = 0 # variable has to be global because it is used by linenumberify and export -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def angleUnder180(command, lastX, lastY, x, y, i, j): @@ -623,6 +623,6 @@ def export(objectslist, filename, argstring): gcode += linenumberify(GCODE_FOOTER) if SHOW_EDITOR: PostUtils.editor(gcode) - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(gcode) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/rml_post.py b/src/Mod/CAM/Path/Post/scripts/rml_post.py index c2e27e31f6..e39b735256 100644 --- a/src/Mod/CAM/Path/Post/scripts/rml_post.py +++ b/src/Mod/CAM/Path/Post/scripts/rml_post.py @@ -37,10 +37,9 @@ http://paulbourke.net/dataformats/hpgl/ import FreeCAD import Part import Path.Post.Utils as PostUtils +from builtins import open as pyopen + -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open # Entrypoint used by FreeCAD @@ -51,7 +50,7 @@ def export(objectslist, filename, argstring): for obj in objectslist: code += convertobject(obj) - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(code) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/slic3r_pre.py b/src/Mod/CAM/Path/Post/scripts/slic3r_pre.py index 69084e74f7..538f90646b 100644 --- a/src/Mod/CAM/Path/Post/scripts/slic3r_pre.py +++ b/src/Mod/CAM/Path/Post/scripts/slic3r_pre.py @@ -28,10 +28,9 @@ This is an preprocessor to read gcode files produced from slic3r. import os import Path import FreeCAD +from builtins import open as pyopen + -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open def open(filename): @@ -43,7 +42,7 @@ def open(filename): def insert(filename, docname): "called when freecad imports a file" - gfile = pythonopen(filename) + gfile = pyopen(filename) gcode = gfile.read() gfile.close() gcode = parse(gcode) diff --git a/src/Mod/CAM/Path/Post/scripts/smoothie_post.py b/src/Mod/CAM/Path/Post/scripts/smoothie_post.py index bfde5be85a..127e0aca8a 100644 --- a/src/Mod/CAM/Path/Post/scripts/smoothie_post.py +++ b/src/Mod/CAM/Path/Post/scripts/smoothie_post.py @@ -29,6 +29,7 @@ import PathScripts.PathUtils as PathUtils import FreeCAD from FreeCAD import Units import shlex +from builtins import open as pyopen TOOLTIP = """ This is a postprocessor file for the Path workbench. It is used to @@ -140,9 +141,7 @@ TOOL_CHANGE = """""" # Number of digits after the decimal point PRECISION = 5 -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): @@ -280,7 +279,7 @@ def export(objectslist, filename, argstring): else: if not filename == "-": - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/uccnc_post.py b/src/Mod/CAM/Path/Post/scripts/uccnc_post.py index 15ea139e1d..b7506cf966 100644 --- a/src/Mod/CAM/Path/Post/scripts/uccnc_post.py +++ b/src/Mod/CAM/Path/Post/scripts/uccnc_post.py @@ -39,6 +39,7 @@ import datetime # import shlex import Path.Post.Utils as PostUtils +from builtins import open as pyopen VERSION = "0.0.4" @@ -280,13 +281,6 @@ parser.add_argument( parser.add_argument("--repeat", action="store_true", help="repeat axis arguments") TOOLTIP_ARGS = parser.format_help() -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open - -# to distinguish python built-in open function from the one declared below -if open.__module__ == "__builtin__": - pythonopen = open # debug option, trace to screen while processing to see where things break up. trace_gcode = False @@ -538,7 +532,7 @@ def export(objectslist, filename, argstring): if not filename == "-": print("export: writing to '{}'".format(filename)) - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/CAM/Path/Post/scripts/wedm_post.py b/src/Mod/CAM/Path/Post/scripts/wedm_post.py index 6fd1042cd9..ca64fc5e34 100644 --- a/src/Mod/CAM/Path/Post/scripts/wedm_post.py +++ b/src/Mod/CAM/Path/Post/scripts/wedm_post.py @@ -32,6 +32,7 @@ import datetime import shlex import Path.Post.Utils as PostUtils import PathScripts.PathUtils as PathUtils +from builtins import open as pyopen TOOLTIP = """ This is a postprocessor file for the Path workbench. It is used to @@ -184,9 +185,7 @@ POST_OPERATION = """""" # Tool Change commands will be inserted before a tool change TOOL_CHANGE = """""" -# to distinguish python built-in open function from the one declared below -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open + def processArguments(argstring): @@ -401,7 +400,7 @@ def export(objectslist, filename, argstring): print("done postprocessing.") if not filename == "-": - gfile = pythonopen(filename, "w") + gfile = pyopen(filename, "w") gfile.write(final) gfile.close() diff --git a/src/Mod/Draft/importAirfoilDAT.py b/src/Mod/Draft/importAirfoilDAT.py index 0611d26dcd..eb83199fbc 100644 --- a/src/Mod/Draft/importAirfoilDAT.py +++ b/src/Mod/Draft/importAirfoilDAT.py @@ -45,6 +45,7 @@ import Draft import Part from FreeCAD import Vector from FreeCAD import Console as FCC +from builtins import open as pyopen if FreeCAD.GuiUp: @@ -53,8 +54,7 @@ else: def translate(context, txt): return txt -if open.__module__ in ['__builtin__', 'io']: - pythonopen = open + useDraftWire = True @@ -133,7 +133,7 @@ def process(filename): _regex = r'^\s*' + xval + r'\,?\s*' + yval + r'\s*$' regex = re.compile(_regex) - afile = pythonopen(filename, 'r') + afile = pyopen(filename, 'r') # read the airfoil name which is always at the first line airfoilname = afile.readline().strip() diff --git a/src/Mod/Draft/importDWG.py b/src/Mod/Draft/importDWG.py index e6655a8f6e..6f46db4ea8 100644 --- a/src/Mod/Draft/importDWG.py +++ b/src/Mod/Draft/importDWG.py @@ -50,9 +50,7 @@ else: def translate(context, txt): return txt -# Save the native open function to avoid collisions -if open.__module__ == '__builtin__': - pythonopen = open + def open(filename): diff --git a/src/Mod/Draft/importDXF.py b/src/Mod/Draft/importDXF.py index a3e8ac4212..12b98e1569 100644 --- a/src/Mod/Draft/importDXF.py +++ b/src/Mod/Draft/importDXF.py @@ -66,6 +66,7 @@ from FreeCAD import Console as FCC from Draft import LinearDimension from draftutils import params from draftutils import utils +from builtins import open as pyopen gui = FreeCAD.GuiUp draftui = None @@ -85,11 +86,6 @@ dxfReader = None dxfColorMap = None dxfLibrary = None -# Save the native open function to avoid collisions -# with the function declared here -if open.__module__ in ['__builtin__', 'io']: - pythonopen = open - def errorDXFLib(gui): """Download the files required to convert DXF files. @@ -3625,7 +3621,7 @@ def export(objectslist, filename, nospline=False, lwPoly=False): # arch view: export it "as is" dxf = exportList[0].Proxy.getDXF() if dxf: - f = pythonopen(filename, "w") + f = pyopen(filename, "w") f.write(dxf) f.close() @@ -3906,11 +3902,11 @@ def exportPage(page, filename): template = os.path.splitext(page.Template)[0] + ".dxf" views = page.Group if os.path.exists(template): - f = pythonopen(template, "U") + f = pyopen(template, "U") template = f.read() f.close() # find & replace editable texts - f = pythonopen(page.Template, "rb") + f = pyopen(page.Template, "rb") svgtemplate = f.read() f.close() editables = re.findall("freecad:editable=\"(.*?)\"", svgtemplate) @@ -3950,7 +3946,7 @@ def exportPage(page, filename): c = dxfcounter() pat = re.compile("(_handle_)") template = pat.sub(c.incr, template) - f = pythonopen(filename, "w") + f = pyopen(filename, "w") f.write(template) f.close() diff --git a/src/Mod/Draft/importOCA.py b/src/Mod/Draft/importOCA.py index 5d09e99899..d1d2e61411 100644 --- a/src/Mod/Draft/importOCA.py +++ b/src/Mod/Draft/importOCA.py @@ -45,6 +45,7 @@ import FreeCAD, os, Part, DraftVecUtils, DraftGeomUtils from FreeCAD import Vector from FreeCAD import Console as FCC from draftutils import params +from builtins import open as pyopen if FreeCAD.GuiUp: from draftutils.translate import translate @@ -52,9 +53,7 @@ else: def translate(context, txt): return txt -# Save the native open function to avoid collisions -if open.__module__ in ['__builtin__', 'io']: - pythonopen = open + def getpoint(data): @@ -286,7 +285,7 @@ def parse(filename, doc): ------- None """ - filebuffer = pythonopen(filename) + filebuffer = pyopen(filename) global objects objects = {} global color @@ -416,7 +415,7 @@ def export(exportList, filename): return # writing file - oca = pythonopen(filename, 'w') + oca = pyopen(filename, 'w') oca.write("#oca file generated from FreeCAD\r\n") oca.write("# edges\r\n") count = 1 diff --git a/src/Mod/Draft/importSVG.py b/src/Mod/Draft/importSVG.py index 155e9af735..dda9191981 100644 --- a/src/Mod/Draft/importSVG.py +++ b/src/Mod/Draft/importSVG.py @@ -61,6 +61,7 @@ from draftutils import params from draftutils import utils from draftutils.translate import translate from draftutils.messages import _err, _msg, _wrn +from builtins import open as pyopen if FreeCAD.GuiUp: from PySide import QtWidgets @@ -74,9 +75,7 @@ else: gui = False draftui = None -# Save the native open function to avoid collisions -if open.__module__ in ['__builtin__', 'io']: - pythonopen = open + svgcolors = { 'Pink': (255, 192, 203), @@ -1701,8 +1700,8 @@ def getContents(filename, tag, stringmode=False): if stringmode: contents = filename else: - # Use the native Python open which was saved as `pythonopen` - f = pythonopen(filename) + # Use the native Python open which was saved as `pyopen` + f = pyopen(filename) contents = f.read() f.close() @@ -1746,8 +1745,8 @@ def open(filename): parser.setContentHandler(svgHandler()) parser._cont_handler.doc = doc - # Use the native Python open which was saved as `pythonopen` - f = pythonopen(filename) + # Use the native Python open which was saved as `pyopen` + f = pyopen(filename) parser.parse(f) f.close() doc.recompute() @@ -1785,8 +1784,8 @@ def insert(filename, docname): parser.setContentHandler(svgHandler()) parser._cont_handler.doc = doc - # Use the native Python open which was saved as `pythonopen` - parser.parse(pythonopen(filename)) + # Use the native Python open which was saved as `pyopen` + parser.parse(pyopen(filename)) doc.recompute() @@ -1854,8 +1853,8 @@ def export(exportList, filename): sizey = maxy - miny miny += margin - # Use the native Python open which was saved as `pythonopen` - svg = pythonopen(filename, 'w') + # Use the native Python open which was saved as `pyopen` + svg = pyopen(filename, 'w') # Write header. # We specify the SVG width and height in FreeCAD's physical units (mm), diff --git a/src/Mod/Fem/feminout/importCcxDatResults.py b/src/Mod/Fem/feminout/importCcxDatResults.py index 342a79a8c6..86bf48c207 100644 --- a/src/Mod/Fem/feminout/importCcxDatResults.py +++ b/src/Mod/Fem/feminout/importCcxDatResults.py @@ -34,13 +34,14 @@ import os import FreeCAD from FreeCAD import Console +from builtins import open as pyopen EIGENVALUE_OUTPUT_SECTION = " E I G E N V A L U E O U T P U T" # ********* generic FreeCAD import and export methods ********* -pyopen = open + def open( diff --git a/src/Mod/Fem/feminout/importCcxFrdResults.py b/src/Mod/Fem/feminout/importCcxFrdResults.py index 82208aafe7..e2d4f63699 100644 --- a/src/Mod/Fem/feminout/importCcxFrdResults.py +++ b/src/Mod/Fem/feminout/importCcxFrdResults.py @@ -35,10 +35,11 @@ import os import FreeCAD from FreeCAD import Console +from builtins import open as pyopen # ********* generic FreeCAD import and export methods ********* -pyopen = open + def open(filename): diff --git a/src/Mod/Fem/feminout/importFenicsMesh.py b/src/Mod/Fem/feminout/importFenicsMesh.py index afe7b6eed0..5a52f7d227 100644 --- a/src/Mod/Fem/feminout/importFenicsMesh.py +++ b/src/Mod/Fem/feminout/importFenicsMesh.py @@ -38,6 +38,7 @@ from . import importToolsFem from . import readFenicsXML from . import writeFenicsXML from . import writeFenicsXDMF +from builtins import open as pyopen if FreeCAD.GuiUp: import FreeCADGui @@ -46,7 +47,7 @@ if FreeCAD.GuiUp: # Template copied from importZ88Mesh.py. Thanks Bernd! # ********* generic FreeCAD import and export methods ********* -pyopen = open + if FreeCAD.GuiUp: class WriteXDMFTaskPanel: diff --git a/src/Mod/Fem/feminout/importInpMesh.py b/src/Mod/Fem/feminout/importInpMesh.py index 04740cd70e..1fab942412 100644 --- a/src/Mod/Fem/feminout/importInpMesh.py +++ b/src/Mod/Fem/feminout/importInpMesh.py @@ -35,10 +35,11 @@ import os import FreeCAD from FreeCAD import Console +from builtins import open as pyopen # ********* generic FreeCAD import and export methods ********* -pyopen = open + def open(filename): diff --git a/src/Mod/Fem/feminout/importPyMesh.py b/src/Mod/Fem/feminout/importPyMesh.py index 5012c29bd8..4ebb2eea6e 100644 --- a/src/Mod/Fem/feminout/importPyMesh.py +++ b/src/Mod/Fem/feminout/importPyMesh.py @@ -32,13 +32,14 @@ __url__ = "https://www.freecad.org" import FreeCAD from femmesh import meshtools +from builtins import open as pyopen # ************************************************************************************************ # ********* generic FreeCAD import and export methods ******************************************** # names are fix given from FreeCAD, these methods are called from FreeCAD # they are set in FEM modules Init.py -pyopen = open + # export mesh to python diff --git a/src/Mod/Fem/feminout/importVTKResults.py b/src/Mod/Fem/feminout/importVTKResults.py index 7b1ca8be34..ea8938a2d1 100644 --- a/src/Mod/Fem/feminout/importVTKResults.py +++ b/src/Mod/Fem/feminout/importVTKResults.py @@ -36,10 +36,11 @@ import FreeCAD from FreeCAD import Console import Fem +from builtins import open as pyopen # ********* generic FreeCAD import and export methods ********* -pyopen = open + def open( diff --git a/src/Mod/Fem/feminout/importYamlJsonMesh.py b/src/Mod/Fem/feminout/importYamlJsonMesh.py index c47ffeac6b..29e88dcf2e 100644 --- a/src/Mod/Fem/feminout/importYamlJsonMesh.py +++ b/src/Mod/Fem/feminout/importYamlJsonMesh.py @@ -36,6 +36,7 @@ import FreeCAD from FreeCAD import Console from . import importToolsFem +from builtins import open as pyopen has_yaml = True try: @@ -53,7 +54,7 @@ except ImportError: # names are fix given from FreeCAD, these methods are called from FreeCAD # they are set in FEM modules Init.py -pyopen = open + def open( diff --git a/src/Mod/Fem/feminout/importZ88Mesh.py b/src/Mod/Fem/feminout/importZ88Mesh.py index 4d6739c24f..82f3cc11f5 100644 --- a/src/Mod/Fem/feminout/importZ88Mesh.py +++ b/src/Mod/Fem/feminout/importZ88Mesh.py @@ -35,13 +35,14 @@ import FreeCAD from FreeCAD import Console from femmesh import meshtools +from builtins import open as pyopen # ************************************************************************************************ # ********* generic FreeCAD import and export methods ******************************************** # names are fix given from FreeCAD, these methods are called from FreeCAD # they are set in FEM modules Init.py -pyopen = open + def open( diff --git a/src/Mod/Fem/feminout/importZ88O2Results.py b/src/Mod/Fem/feminout/importZ88O2Results.py index b322cf1c90..4abd383913 100644 --- a/src/Mod/Fem/feminout/importZ88O2Results.py +++ b/src/Mod/Fem/feminout/importZ88O2Results.py @@ -33,10 +33,11 @@ import os import FreeCAD from FreeCAD import Console +from builtins import open as pyopen # ********* generic FreeCAD import and export methods ********* -pyopen = open + def open( diff --git a/src/Mod/Idf/Idf.py b/src/Mod/Idf/Idf.py index a4f02157a0..707a0c9891 100644 --- a/src/Mod/Idf/Idf.py +++ b/src/Mod/Idf/Idf.py @@ -25,10 +25,7 @@ import FreeCAD, Part, os, FreeCADGui from FreeCAD import Base from math import * import ImportGui - -# to distinguish python built-in open function from the one declared here -if open.__module__ in ['__builtin__','io']: - pythonopen = open +from builtins import open as pyopen ########################################################## # Script version dated 19-Jan-2012 # @@ -74,7 +71,7 @@ def insert(filename,docname): def process_emn(doc,filename): """process_emn(document, filename)-> adds emn geometry from emn file""" - emnfile=pythonopen(filename, "r") + emnfile=pyopen(filename, "r") emn_unit=1.0 #presume millimeter like emn unit emn_version=2 #presume emn_version 2 board_thickness=0 #presume 0 board height @@ -227,7 +224,7 @@ def split_records(line_record): def process_emp(doc,filename,placement,board_thickness): """process_emp(doc,filename,placement,board_thickness) -> place components from emn file to board""" filename=filename.partition(".emn")[0]+".emp" - empfile=pythonopen(filename, "r") + empfile=pyopen(filename, "r") emp_unit=1.0 #presume millimeter like emn unit emp_version=2 #presume emn_version 2 comp_height=0 #presume 0 part height @@ -274,7 +271,7 @@ def process_emp(doc,filename,placement,board_thickness): FreeCAD.Console.PrintMessage("\n".join(passed_sections)+"\n") #Write file with list of footprint if IDF_diag==1: - empfile=pythonopen(IDF_diag_path+"/footprint.lst", "w") + empfile=pyopen(IDF_diag_path+"/footprint.lst", "w") for compx in comps: empfile.writelines(str(compx[1][1])+"\n") empfile.close() @@ -331,12 +328,12 @@ def place_steps(doc,placement,board_thickness): list of models and path to step files is set at start of this script model_tab_filename= "" & step_path="" """ - model_file=pythonopen(model_tab_filename, "r") + model_file=pyopen(model_tab_filename, "r") model_lines=model_file.readlines() model_file.close() model_dict=[] if IDF_diag==1: - model_file=pythonopen(IDF_diag_path+"/missing_models.lst", "w") + model_file=pyopen(IDF_diag_path+"/missing_models.lst", "w") keys=[] #prev_step="*?.*?" #hope nobody will insert this step filename step_dict=[] diff --git a/src/Mod/Material/importFCMat.py b/src/Mod/Material/importFCMat.py index 63865d6018..524ce60a15 100644 --- a/src/Mod/Material/importFCMat.py +++ b/src/Mod/Material/importFCMat.py @@ -31,14 +31,13 @@ import FreeCAD from materialtools.cardutils import get_material_template import Materials +from builtins import open as pyopen if FreeCAD.GuiUp: from PySide import QtGui -# to distinguish python built-in open function from the one declared below -if open.__module__ in ['__builtin__', 'io']: - pythonopen = open + def open(filename): @@ -119,7 +118,7 @@ def read_old(filename): # print(filename) card_name_file = os.path.splitext(os.path.basename(filename))[0] - f = pythonopen(filename, encoding="utf8") + f = pyopen(filename, encoding="utf8") try: content = f.readlines() # print(len(content)) @@ -194,7 +193,7 @@ def read2(filename): # print(filename) card_name_file = os.path.splitext(os.path.basename(filename))[0] - f = pythonopen(filename, encoding="utf8") + f = pyopen(filename, encoding="utf8") try: content = f.readlines() # print(len(content)) @@ -335,7 +334,7 @@ def write(filename, dictionary, write_group_section=True): if FreeCAD.GuiUp: QtGui.QMessageBox.critical(None, "No card name", error_message) return - f = pythonopen(filename, "w", encoding="utf-8") + f = pyopen(filename, "w", encoding="utf-8") # write header # first five lines are the same in any card file, see comment above read def if header["CardName"] != card_name_file: diff --git a/src/Mod/OpenSCAD/exportCSG.py b/src/Mod/OpenSCAD/exportCSG.py index 1036e2e0a5..cc4ea2e455 100644 --- a/src/Mod/OpenSCAD/exportCSG.py +++ b/src/Mod/OpenSCAD/exportCSG.py @@ -29,6 +29,7 @@ __author__ = "Keith Sloan " __url__ = ["http://www.sloan-home.co.uk/Export/Export.html"] import FreeCAD +from builtins import open as pyopen if FreeCAD.GuiUp: gui = True @@ -48,9 +49,6 @@ 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 -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: @@ -254,7 +252,7 @@ def export(exportList, filename): # process Objects print("\nStart Export 0.1d\n") print("Open Output File") - csg = pythonopen(filename,'w') + csg = pyopen(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" % \ diff --git a/src/Mod/OpenSCAD/importCSG.py b/src/Mod/OpenSCAD/importCSG.py index 1760b43a35..c1fc501595 100644 --- a/src/Mod/OpenSCAD/importCSG.py +++ b/src/Mod/OpenSCAD/importCSG.py @@ -44,9 +44,7 @@ import Draft from OpenSCADFeatures import * from OpenSCADUtils import * -# Save the native open function to avoid collisions -if open.__module__ in ['__builtin__', 'io']: - pythonopen = open + import ply.lex as lex import ply.yacc as yacc @@ -66,6 +64,7 @@ original_root_objects = [] # Get the token map from the lexer. This is required. import tokrules from tokrules import tokens +from builtins import open as pyopen translate = FreeCAD.Qt.translate @@ -897,8 +896,8 @@ def processSVG(fname, ext): # pathName is a Global filename = os.path.join(pathName,fname+'.'+ext) - # Use the native Python open which was saved as `pythonopen` - parser.parse(pythonopen(filename)) + # Use the native Python open which was saved as `pyopen` + parser.parse(pyopen(filename)) #combine SVG objects into one shapes = [] diff --git a/src/Mod/OpenSCAD/prototype.py b/src/Mod/OpenSCAD/prototype.py index 2c8122fc31..1d38949abe 100644 --- a/src/Mod/OpenSCAD/prototype.py +++ b/src/Mod/OpenSCAD/prototype.py @@ -12,9 +12,9 @@ import re from OpenSCADFeatures import * from OpenSCAD2Dgeom import * from OpenSCADUtils import * +from builtins import open as pyopen + -if open.__module__ in ['__builtin__','io']: - pythonopen = open # to distinguish python built-in open function from the one declared here def openscadmesh(doc, scadstr, objname): @@ -661,9 +661,9 @@ def readfile(filename): tmpfile=callopenscad(filename) if OpenSCADUtils.workaroundforissue128needed(): lastimportpath = os.getcwd() #https://github.com/openscad/openscad/issues/128 - f = pythonopen(tmpfile) + f = pyopen(tmpfile) else: - f = pythonopen(filename) + f = pyopen(filename) rootnode = parsenode(f.read())[0] f.close() if isopenscad and tmpfile: diff --git a/src/Mod/Sandbox/exportDRAWEXE.py b/src/Mod/Sandbox/exportDRAWEXE.py index f06f4b10fe..313748d1be 100644 --- a/src/Mod/Sandbox/exportDRAWEXE.py +++ b/src/Mod/Sandbox/exportDRAWEXE.py @@ -24,9 +24,9 @@ __title__="FreeCAD OpenSCAD Workbench - DRAWEXE exporter" __author__ = "Sebastian Hoogen " import FreeCAD, Part +from builtins import open as pyopen + -if open.__module__ == '__builtin__': - pythonopen = open # unsupported primitives # Part:: Wedge, Helix, Spiral, Elipsoid @@ -252,7 +252,7 @@ def isDeform(ob): class Drawexporter(object): def __init__(self, filename): self.objectcache=set() - self.csg = pythonopen(filename,'w') + self.csg = pyopen(filename,'w') #self.csg=csg self.filename=filename #settings diff --git a/src/Mod/Spreadsheet/importXLSX.py b/src/Mod/Spreadsheet/importXLSX.py index 2b8cd5bd94..c59014446b 100644 --- a/src/Mod/Spreadsheet/importXLSX.py +++ b/src/Mod/Spreadsheet/importXLSX.py @@ -63,9 +63,6 @@ except ValueError: else: gui = True -if open.__module__ in ["__builtin__", "io"]: - pythonopen = open - # The sepToken structure is used in the tokenizer functions isKey and # getNextToken.