python3 support: pylint, W1648 # (bad-python3-import) Module moved in Python 3
--- a/BeremizIDE.py Wed Oct 03 15:47:59 2018 +0300
+++ b/BeremizIDE.py Thu Oct 04 11:25:42 2018 +0300
@@ -35,7 +35,7 @@
from time import time as gettime
from threading import Lock, Timer, currentThread
-import cPickle
+from six.moves import cPickle
import wx.lib.buttons
import wx.lib.statbmp
import wx.stc
--- a/Beremiz_service.py Wed Oct 03 15:47:59 2018 +0300
+++ b/Beremiz_service.py Thu Oct 04 11:25:42 2018 +0300
@@ -32,7 +32,7 @@
import threading
from threading import Thread, Semaphore, Lock
import traceback
-import __builtin__
+from six.moves import builtins
import Pyro
import Pyro.core as pyro
@@ -143,7 +143,7 @@
argv = [WorkingDir]
if __name__ == '__main__':
- __builtin__.__dict__['_'] = lambda x: x
+ builtins.__dict__['_'] = lambda x: x
# TODO: add a cmdline parameter if Trying Preloading Xenomai makes problem
TryPreloadXenomai()
version()
@@ -162,12 +162,12 @@
domain = "Beremiz"
# Define locale for wx
- loc = __builtin__.__dict__.get('loc', None)
+ loc = builtins.__dict__.get('loc', None)
if loc is None:
wx.LogGui.EnableLogging(False)
loc = wx.Locale(langid)
wx.LogGui.EnableLogging(True)
- __builtin__.__dict__['loc'] = loc
+ builtins.__dict__['loc'] = loc
# Define location for searching translation files
loc.AddCatalogLookupPathPrefix(localedir)
# Define locale domain
@@ -186,8 +186,8 @@
return wx.GetTranslation(message).encode(default_locale)
if __name__ == '__main__':
- __builtin__.__dict__['_'] = unicode_translation
- # __builtin__.__dict__['_'] = wx.GetTranslation
+ builtins.__dict__['_'] = unicode_translation
+ # builtins.__dict__['_'] = wx.GetTranslation
# Life is hard... have a candy.
--- a/IDEFrame.py Wed Oct 03 15:47:59 2018 +0300
+++ b/IDEFrame.py Thu Oct 04 11:25:42 2018 +0300
@@ -24,13 +24,13 @@
from __future__ import absolute_import
import sys
-import cPickle
from types import TupleType
import base64
import wx
import wx.grid
import wx.aui
+from six.moves import cPickle
from editors.EditorPanel import EditorPanel
from editors.SFCViewer import SFC_Viewer
--- a/controls/TextCtrlAutoComplete.py Wed Oct 03 15:47:59 2018 +0300
+++ b/controls/TextCtrlAutoComplete.py Thu Oct 04 11:25:42 2018 +0300
@@ -24,7 +24,7 @@
from __future__ import absolute_import
-import cPickle
+from six.moves import cPickle
import wx
MAX_ITEM_COUNT = 10
--- a/docutil/docpdf.py Wed Oct 03 15:47:59 2018 +0300
+++ b/docutil/docpdf.py Thu Oct 04 11:25:42 2018 +0300
@@ -34,16 +34,16 @@
def get_acroversion():
" Return version of Adobe Acrobat executable or None"
- import _winreg
- adobesoft = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'Software\Adobe')
- for index in range(_winreg.QueryInfoKey(adobesoft)[0]):
- key = _winreg.EnumKey(adobesoft, index)
+ from six.moves import winreg
+ adobesoft = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'Software\Adobe')
+ for index in range(winreg.QueryInfoKey(adobesoft)[0]):
+ key = winreg.EnumKey(adobesoft, index)
if "acrobat" in key.lower():
- acrokey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s' % key)
- for index in range(_winreg.QueryInfoKey(acrokey)[0]):
- numver = _winreg.EnumKey(acrokey, index)
+ acrokey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s' % key)
+ for index in range(winreg.QueryInfoKey(acrokey)[0]):
+ numver = winreg.EnumKey(acrokey, index)
try:
- res = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s\\%s\\InstallPath' % (key, numver))
+ res = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s\\%s\\InstallPath' % (key, numver))
return res
except Exception:
pass
--- a/docutil/docsvg.py Wed Oct 03 15:47:59 2018 +0300
+++ b/docutil/docsvg.py Thu Oct 04 11:25:42 2018 +0300
@@ -31,13 +31,13 @@
def get_inkscape_path():
""" Return the Inkscape path """
- import _winreg
+ from six.moves import winreg
try:
- svgexepath = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE,
- 'Software\\Classes\\svgfile\\shell\\Inkscape\\command')
+ svgexepath = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
+ 'Software\\Classes\\svgfile\\shell\\Inkscape\\command')
except OSError:
- svgexepath = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE,
- 'Software\\Classes\\inkscape.svg\\shell\\open\\command')
+ svgexepath = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
+ 'Software\\Classes\\inkscape.svg\\shell\\open\\command')
svgexepath = svgexepath.replace('"%1"', '')
return svgexepath.replace('"', '')
--- a/runtime/PLCObject.py Wed Oct 03 15:47:59 2018 +0300
+++ b/runtime/PLCObject.py Thu Oct 04 11:25:42 2018 +0300
@@ -23,7 +23,6 @@
from __future__ import absolute_import
-import thread
from threading import Thread, Lock, Semaphore, Event, Condition
import ctypes
import os
@@ -33,6 +32,7 @@
import _ctypes # pylint: disable=wrong-import-order
import Pyro.core as pyro
import six
+from six.moves import _thread
from runtime.typemapping import TypeTranslator
from runtime.loglevels import LogLevelsDefault, LogLevelsCount
@@ -104,7 +104,7 @@
"""
meant to be called by worker thread (blocking)
"""
- self._threadID = thread.get_ident()
+ self._threadID = _thread.get_ident()
if args or kwargs:
job(*args, **kwargs).do()
# result is ignored
@@ -128,7 +128,7 @@
_job = job(*args, **kwargs)
- if self._threadID == thread.get_ident() or self._threadID is None:
+ if self._threadID == _thread.get_ident() or self._threadID is None:
# if caller is worker thread execute immediately
_job.do()
else:
--- a/svgui/pyjs/build.py Wed Oct 03 15:47:59 2018 +0300
+++ b/svgui/pyjs/build.py Thu Oct 04 11:25:42 2018 +0300
@@ -10,7 +10,7 @@
from os.path import join, basename, abspath, split, isfile, isdir
from hashlib import md5
from optparse import OptionParser
-from cStringIO import StringIO
+from six.moves import cStringIO
from svgui.pyjs import pyjs
@@ -254,7 +254,7 @@
# the selector templ is added to the selectScript function
select_tmpl = """O(["true","%s"],"%s");"""
- script_selectors = StringIO()
+ script_selectors = cStringIO()
for platform, file_prefix in app_files:
print(select_tmpl % (platform, file_prefix), file=script_selectors)
@@ -453,7 +453,7 @@
if dynamic:
mod_cache_html_output = open(join(output, mod_cache_name), "w")
else:
- mod_cache_html_output = StringIO()
+ mod_cache_html_output = cStringIO()
print(mod_cache_html_template % dict(
mod_name=mod_name,
--- a/svgui/pyjs/pyjs.py Wed Oct 03 15:47:59 2018 +0300
+++ b/svgui/pyjs/pyjs.py Thu Oct 04 11:25:42 2018 +0300
@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# pylint: disable=no-absolute-import
+# pylint: disable=no-absolute-import,bad-python3-import
from __future__ import print_function
import sys
@@ -22,7 +22,7 @@
from compiler import ast
import os
import copy
-import cStringIO
+from six.moves import cStringIO
# the standard location for builtins (e.g. pyjslib) can be
# over-ridden by changing this. it defaults to sys.prefix
@@ -1443,7 +1443,7 @@
raise TranslationError("varargs are not supported in Lambdas", node)
if node.kwargs:
raise TranslationError("kwargs are not supported in Lambdas", node)
- res = cStringIO.StringIO()
+ res = cStringIO()
arg_names = list(node.argnames)
function_args = ", ".join(arg_names)
for child in node.getChildNodes():
@@ -1534,7 +1534,7 @@
f = file(file_name, "r")
src = f.read()
f.close()
- output = cStringIO.StringIO()
+ output = cStringIO()
mod = compiler.parseFile(file_name)
Translator(module_name, module_name, module_name, src, debug, mod, output)
return output.getvalue()
@@ -1683,7 +1683,7 @@
file_name = self.findFile(module_name + self.extension)
- output = cStringIO.StringIO()
+ output = cStringIO()
f = file(file_name, "r")
src = f.read()
@@ -1718,8 +1718,8 @@
def translate(self, module_name, is_app=True, debug=False,
library_modules=None):
- app_code = cStringIO.StringIO()
- lib_code = cStringIO.StringIO()
+ app_code = cStringIO()
+ lib_code = cStringIO()
imported_js = set()
self.library_modules = []
self.overrides = {}
--- a/tests/tools/check_source.sh Wed Oct 03 15:47:59 2018 +0300
+++ b/tests/tools/check_source.sh Thu Oct 04 11:25:42 2018 +0300
@@ -347,6 +347,9 @@
enable=$enable,W0612 # (unused-variable) Unused variable 'X'
enable=$enable,C0330 # (bad-continuation) Wrong hanging indentation before block
enable=$enable,R0123 # (literal-comparison) Comparison to literal
+
+ # python3 compatibility checks
+ enable=$enable,W1648 # (bad-python3-import) Module moved in Python 3
# enable=
options=
--- a/util/TranslationCatalogs.py Wed Oct 03 15:47:59 2018 +0300
+++ b/util/TranslationCatalogs.py Thu Oct 04 11:25:42 2018 +0300
@@ -25,14 +25,14 @@
from __future__ import absolute_import
import os
-import __builtin__
+from six.moves import builtins
import wx
locale = None
-__builtin__.__dict__['_'] = wx.GetTranslation
+builtins.__dict__['_'] = wx.GetTranslation
def GetDomain(path):
--- a/xmlclass/xmlclass.py Wed Oct 03 15:47:59 2018 +0300
+++ b/xmlclass/xmlclass.py Thu Oct 04 11:25:42 2018 +0300
@@ -31,7 +31,6 @@
from types import *
from xml.dom import minidom
from xml.sax.saxutils import unescape
-from new import classobj
from collections import OrderedDict
from lxml import etree
@@ -1168,7 +1167,7 @@
classmembers["getElementInfos"] = generateGetElementInfos(self, classinfos)
classmembers["setElementValue"] = generateSetElementValue(self, classinfos)
- class_definition = classobj(str(name), bases, classmembers)
+ class_definition = type(str(name), bases, classmembers)
setattr(class_definition, "__getattr__", generateGetattrMethod(self, class_definition, classinfos))
setattr(class_definition, "__setattr__", generateSetattrMethod(self, class_definition, classinfos))
class_infos = {