python3 support: pylint, W1607 # (file-builtin) file built-in referenced
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 09 Oct 2018 14:03:44 +0300
changeset 2442 b13f021c68a5
parent 2441 c553769a65af
child 2443 75a274023970
python3 support: pylint, W1607 # (file-builtin) file built-in referenced
ProjectController.py
canfestival/canfestival.py
etherlab/EthercatMaster.py
py_ext/PythonFileCTNMixin.py
runtime/PLCObject.py
svgui/pyjs/pyjs.py
svgui/svgui.py
tests/tools/check_source.sh
--- a/ProjectController.py	Tue Oct 09 13:50:29 2018 +0300
+++ b/ProjectController.py	Tue Oct 09 14:03:44 2018 +0300
@@ -859,9 +859,9 @@
         H_files = map(
             lambda filename: os.path.join(buildpath, filename), H_files)
         for H_file in H_files:
-            with file(H_file, 'r') as original:
+            with open(H_file, 'r') as original:
                 data = original.read()
-            with file(H_file, 'w') as modified:
+            with open(H_file, 'w') as modified:
                 modified.write('#include "beremiz.h"\n' + data)
 
         self.logger.write(_("Extracting Located Variables...\n"))
@@ -1289,7 +1289,7 @@
                 self._IECCodeView.SetTextSyntax("ALL")
                 self._IECCodeView.SetKeywords(IEC_KEYWORDS)
                 try:
-                    text = file(plc_file).read()
+                    text = open(plc_file).read()
                 except Exception:
                     text = '(* No IEC code have been generated at that time ! *)'
                 self._IECCodeView.SetText(text=text)
--- a/canfestival/canfestival.py	Tue Oct 09 13:50:29 2018 +0300
+++ b/canfestival/canfestival.py	Tue Oct 09 14:03:44 2018 +0300
@@ -617,6 +617,6 @@
         if can_driver is not None:
             can_driver_path = os.path.join(CanFestivalPath, "drivers", can_driver, can_driver_name)
             if os.path.exists(can_driver_path):
-                res += ((can_driver_name, file(can_driver_path, "rb")),)
+                res += ((can_driver_name, open(can_driver_path, "rb")),)
 
         return res
--- a/etherlab/EthercatMaster.py	Tue Oct 09 13:50:29 2018 +0300
+++ b/etherlab/EthercatMaster.py	Tue Oct 09 14:03:44 2018 +0300
@@ -94,7 +94,7 @@
         ethelabfile.close()
 
         return ((["etherlab_ext"], [(Gen_etherlabfile_path, IECCFLAGS)], True), "",
-                ("runtime_etherlab.py", file(GetLocalPath("runtime_etherlab.py"))))
+                ("runtime_etherlab.py", open(GetLocalPath("runtime_etherlab.py"))))
 
 # --------------------------------------------------
 #                 Ethercat MASTER
--- a/py_ext/PythonFileCTNMixin.py	Tue Oct 09 13:50:29 2018 +0300
+++ b/py_ext/PythonFileCTNMixin.py	Tue Oct 09 14:03:44 2018 +0300
@@ -318,4 +318,4 @@
         return ([(Gen_PyCfile_path, matiec_CFLAGS)],
                 "",
                 True,
-                ("runtime_%s.py" % location_str, file(runtimefile_path, "rb")))
+                ("runtime_%s.py" % location_str, open(runtimefile_path, "rb")))
--- a/runtime/PLCObject.py	Tue Oct 09 13:50:29 2018 +0300
+++ b/runtime/PLCObject.py	Tue Oct 09 14:03:44 2018 +0300
@@ -566,7 +566,7 @@
             try:
                 if replace_PLC_shared_object:
                     os.remove(old_PLC_filename)
-                for filename in file(extra_files_log, "r").readlines() + [extra_files_log]:
+                for filename in open(extra_files_log, "rt").readlines() + [extra_files_log]:
                     try:
                         os.remove(os.path.join(self.workingdir, filename.strip()))
                     except Exception:
@@ -583,7 +583,7 @@
                 open(self._GetMD5FileName(), "w").write(md5sum)
 
                 # Then write the files
-                log = file(extra_files_log, "w")
+                log = open(extra_files_log, "w")
                 for fname, fdata in extrafiles:
                     fpath = os.path.join(self.workingdir, fname)
                     open(fpath, "wb").write(fdata)
--- a/svgui/pyjs/pyjs.py	Tue Oct 09 13:50:29 2018 +0300
+++ b/svgui/pyjs/pyjs.py	Tue Oct 09 14:03:44 2018 +0300
@@ -1532,7 +1532,7 @@
 
 
 def translate(file_name, module_name, debug=False):
-    f = file(file_name, "r")
+    f = open(file_name, "r")
     src = f.read()
     f.close()
     output = cStringIO()
@@ -1686,7 +1686,7 @@
 
         output = cStringIO()
 
-        f = file(file_name, "r")
+        f = open(file_name, "r")
         src = f.read()
         f.close()
 
@@ -1749,7 +1749,7 @@
                 if self.verbose:
                     print('Including JS', js)
                 print('\n//\n// BEGIN JS '+js+'\n//\n', file=lib_code)
-                print(file(path).read(), file=lib_code)
+                print(open(path).read(), file=lib_code)
                 print('\n//\n// END JS '+js+'\n//\n', file=lib_code)
             else:
                 print('Warning: Unable to find imported javascript:', js, file=sys.stderr)
--- a/svgui/svgui.py	Tue Oct 09 13:50:29 2018 +0300
+++ b/svgui/svgui.py	Tue Oct 09 14:03:44 2018 +0300
@@ -93,7 +93,7 @@
 
         svgfile = self._getSVGpath()
         if os.path.exists(svgfile):
-            res += (("gui.svg", file(svgfile, "rb")),)
+            res += (("gui.svg", open(svgfile, "rb")),)
 
         svguiserverfile = open(self._getSVGUIserverpath(), 'r')
         svguiservercode = svguiserverfile.read()
@@ -111,7 +111,7 @@
         svguilibfile.write(open(os.path.join(fpath, "livesvg.js"), 'r').read())
         svguilibfile.close()
         jsmodules = {"LiveSVGPage": "svguilib.js"}
-        res += (("svguilib.js", file(svguilibpath, "rb")),)
+        res += (("svguilib.js", open(svguilibpath, "rb")),)
 
         runtimefile_path = os.path.join(buildpath, "runtime_%s.py" % location_str)
         runtimefile = open(runtimefile_path, 'w')
@@ -128,7 +128,7 @@
                "jsmodules": str(jsmodules)})
         runtimefile.close()
 
-        res += (("runtime_%s.py" % location_str, file(runtimefile_path, "rb")),)
+        res += (("runtime_%s.py" % location_str, open(runtimefile_path, "rb")),)
 
         return res
 
--- a/tests/tools/check_source.sh	Tue Oct 09 13:50:29 2018 +0300
+++ b/tests/tools/check_source.sh	Tue Oct 09 14:03:44 2018 +0300
@@ -361,6 +361,7 @@
     enable=$enable,W1619          # (old-division) division w/o __future__ statement
     enable=$enable,W1601          # (apply-builtin) apply built-in referenced
     enable=$enable,W1659          # (xreadlines-attribute) Accessing a removed xreadlines attribute
+    enable=$enable,W1607          # (file-builtin) file built-in referenced
     # enable=
 
     options=