# HG changeset patch # User Andrey Skvortsov # Date 1538663080 -10800 # Node ID 07f48018b6f5e0f8db3680e3e18cdd40c194594b # Parent 2e8bf28a890970c4d27da9bcf80cf31cfc89c70c python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced diff -r 2e8bf28a8909 -r 07f48018b6f5 CodeFileTreeNode.py --- a/CodeFileTreeNode.py Thu Oct 04 12:09:23 2018 +0300 +++ b/CodeFileTreeNode.py Thu Oct 04 17:24:40 2018 +0300 @@ -27,8 +27,9 @@ import os import re import traceback - +from builtins import str as text from copy import deepcopy + from lxml import etree from xmlclass import GenerateParserFromXSDstring @@ -124,7 +125,7 @@ self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src)) self.CreateCodeFileBuffer(True) except Exception as exc: - msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=self.CTNName(), a2=unicode(exc)) + msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=self.CTNName(), a2=text(exc)) self.GetCTRoot().logger.write_error(msg) self.GetCTRoot().logger.write_error(traceback.format_exc()) raise Exception diff -r 2e8bf28a8909 -r 07f48018b6f5 ConfigTreeNode.py --- a/ConfigTreeNode.py Thu Oct 04 12:09:23 2018 +0300 +++ b/ConfigTreeNode.py Thu Oct 04 17:24:40 2018 +0300 @@ -36,10 +36,11 @@ import traceback import types import shutil +from builtins import str as text + from lxml import etree from xmlclass import GenerateParserFromXSDstring - from PLCControler import LOCATION_CONFNODE from editors.ConfTreeNodeEditor import ConfTreeNodeEditor @@ -277,7 +278,7 @@ LDFLAGS = [] if CTNLDFLAGS is not None: # LDFLAGS can be either string - if isinstance(CTNLDFLAGS, (str, unicode)): + if isinstance(CTNLDFLAGS, (str, text)): LDFLAGS += [CTNLDFLAGS] # or list of strings elif isinstance(CTNLDFLAGS, list): @@ -627,7 +628,7 @@ self.MandatoryParams = ("BaseParams", self.BaseParams) basexmlfile.close() except Exception as exc: - msg = _("Couldn't load confnode base parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=unicode(exc)) + msg = _("Couldn't load confnode base parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=text(exc)) self.GetCTRoot().logger.write_error(msg) self.GetCTRoot().logger.write_error(traceback.format_exc()) @@ -644,7 +645,7 @@ self.CTNParams = (name, obj) xmlfile.close() except Exception as exc: - msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=unicode(exc)) + msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=text(exc)) self.GetCTRoot().logger.write_error(msg) self.GetCTRoot().logger.write_error(traceback.format_exc()) @@ -657,6 +658,6 @@ try: self.CTNAddChild(pname, ptype) except Exception as exc: - msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1=pname, a2=ptype, a3=unicode(exc)) + msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1=pname, a2=ptype, a3=text(exc)) self.GetCTRoot().logger.write_error(msg) self.GetCTRoot().logger.write_error(traceback.format_exc()) diff -r 2e8bf28a8909 -r 07f48018b6f5 IDEFrame.py --- a/IDEFrame.py Thu Oct 04 12:09:23 2018 +0300 +++ b/IDEFrame.py Thu Oct 04 17:24:40 2018 +0300 @@ -26,6 +26,7 @@ import sys from types import TupleType import base64 +from builtins import str as text import wx import wx.grid @@ -108,7 +109,7 @@ def DecodeFileSystemPath(path, is_base64=True): if is_base64: path = base64.decodestring(path) - return unicode(path, sys.getfilesystemencoding()) + return text(path, sys.getfilesystemencoding()) def AppendMenu(parent, help, id, kind, text): diff -r 2e8bf28a8909 -r 07f48018b6f5 connectors/WAMP/__init__.py --- a/connectors/WAMP/__init__.py Thu Oct 04 12:09:23 2018 +0300 +++ b/connectors/WAMP/__init__.py Thu Oct 04 17:24:40 2018 +0300 @@ -28,6 +28,7 @@ import sys import traceback from threading import Thread, Event +from builtins import str as text from twisted.internet import reactor, threads from autobahn.twisted import wamp @@ -83,7 +84,7 @@ # create a WAMP application session factory component_config = types.ComponentConfig( - realm=unicode(realm), + realm=text(realm), extra={"ID": ID}) session_factory = wamp.ApplicationSessionFactory( config=component_config) @@ -109,7 +110,7 @@ reactor.run(installSignalHandlers=False) def WampSessionProcMapper(funcname): - wampfuncname = unicode('.'.join((ID, funcname))) + wampfuncname = text('.'.join((ID, funcname))) def catcher_func(*args, **kwargs): if _WampSession is not None: diff -r 2e8bf28a8909 -r 07f48018b6f5 controls/VariablePanel.py --- a/controls/VariablePanel.py Thu Oct 04 12:09:23 2018 +0300 +++ b/controls/VariablePanel.py Thu Oct 04 17:24:40 2018 +0300 @@ -26,6 +26,7 @@ from __future__ import absolute_import import re from types import TupleType, StringType, UnicodeType +from builtins import str as text import wx import wx.grid @@ -607,7 +608,7 @@ model = re.compile("%[IQM][XBWLD]?(.*\.|)") prefix = model.match(old_location).group(0) addr = int(re.split(model, old_location)[-1]) + 1 - row_content.Location = prefix + unicode(addr) + row_content.Location = prefix + text(addr) if not row_content.Class: row_content.Class = self.DefaultTypes.get(self.Filter, self.Filter) diff -r 2e8bf28a8909 -r 07f48018b6f5 dialogs/ForceVariableDialog.py --- a/dialogs/ForceVariableDialog.py Thu Oct 04 12:09:23 2018 +0300 +++ b/dialogs/ForceVariableDialog.py Thu Oct 04 17:24:40 2018 +0300 @@ -25,6 +25,7 @@ from __future__ import absolute_import import re import datetime +from builtins import str as text import wx @@ -200,7 +201,7 @@ def ToggleBoolValue(self, event): value = self.ToggleButton.GetValue() - self.ValueTextCtrl.SetValue(unicode(value)) + self.ValueTextCtrl.SetValue(text(value)) def OnOK(self, event): message = None diff -r 2e8bf28a8909 -r 07f48018b6f5 editors/CodeFileEditor.py --- a/editors/CodeFileEditor.py Thu Oct 04 12:09:23 2018 +0300 +++ b/editors/CodeFileEditor.py Thu Oct 04 17:24:40 2018 +0300 @@ -25,6 +25,7 @@ from __future__ import absolute_import import re +from builtins import str as text import wx import wx.grid @@ -32,6 +33,7 @@ import wx.lib.buttons from six.moves import xrange + from plcopen.plcopen import TestTextElement from plcopen.structures import TestIdentifier, IEC_KEYWORDS, DefaultType from controls import CustomGrid, CustomTable @@ -630,7 +632,7 @@ if col == 0: return row + 1 else: - return unicode(self.data[row].get(self.GetColLabelValue(col, False), "")) + return text(self.data[row].get(self.GetColLabelValue(col, False), "")) def _updateColAttrs(self, grid): """ diff -r 2e8bf28a8909 -r 07f48018b6f5 etherlab/CommonEtherCATFunction.py --- a/etherlab/CommonEtherCATFunction.py Thu Oct 04 12:09:23 2018 +0300 +++ b/etherlab/CommonEtherCATFunction.py Thu Oct 04 17:24:40 2018 +0300 @@ -9,8 +9,10 @@ # See COPYING file for copyrights details. from __future__ import absolute_import +from builtins import str as text import wx + mailbox_protocols = ["AoE", "EoE", "CoE", "FoE", "SoE", "VoE"] @@ -894,7 +896,7 @@ vendor_spec_strings = [] for element in device.getType().getcontent(): data += element - if data != "" and isinstance(data, unicode): + if data != "" and isinstance(data, text): for vendor_spec_string in vendor_spec_strings: if data == vendor_spec_string: self.OrderIdx = vendor_spec_strings.index(data)+1 @@ -913,7 +915,7 @@ # element2-1; ---- data = device.getGroupType() - if data is not None and isinstance(data, unicode): + if data is not None and isinstance(data, text): for vendor_spec_string in vendor_spec_strings: if data == vendor_spec_string: self.GroupIdx = vendor_spec_strings.index(data)+1 @@ -937,7 +939,7 @@ for device_item in group_etc["devices"]: if device == device_item[1]: data = group_type - if data is not None and isinstance(data, unicode): + if data is not None and isinstance(data, text): for vendor_spec_string in vendor_spec_strings: if data == vendor_spec_string: self.GroupIdx = vendor_spec_strings.index(data)+1 @@ -961,7 +963,7 @@ for device_item in group_etc["devices"]: if device == device_item[1]: data = group_etc["name"] - if data != "" and isinstance(data, unicode): + if data != "" and isinstance(data, text): for vendor_spec_string in vendor_spec_strings: if data == vendor_spec_string: groupnameflag = True @@ -980,7 +982,7 @@ for element in device.getName(): if element.getLcId() == 1 or element.getLcId() == 1033: data = element.getcontent() - if data != "" and isinstance(data, unicode): + if data != "" and isinstance(data, text): for vendor_spec_string in vendor_spec_strings: if data == vendor_spec_string: self.NameIdx = vendor_spec_strings.index(data)+1 @@ -1000,7 +1002,7 @@ # element5-1; ---- if device.getcontent() is not None: data = device.getcontent() - if data is not None and isinstance(data, unicode): + if data is not None and isinstance(data, text): for vendor_spec_string in vendor_spec_strings: if data == vendor_spec_string: self.ImgIdx = vendor_spec_strings.index(data)+1 @@ -1024,7 +1026,7 @@ for device_item in group_etc["devices"]: if device == device_item[1]: data = group_etc - if data is not None and isinstance(data, unicode): + if data is not None and isinstance(data, text): for vendor_spec_string in vendor_spec_strings: if data == vendor_spec_string: self.ImgIdx = vendor_spec_strings.index(data)+1 diff -r 2e8bf28a8909 -r 07f48018b6f5 etherlab/etherlab.py --- a/etherlab/etherlab.py Thu Oct 04 12:09:23 2018 +0300 +++ b/etherlab/etherlab.py Thu Oct 04 17:24:40 2018 +0300 @@ -13,8 +13,9 @@ import os import shutil import csv +from builtins import str as text + from lxml import etree - import wx from xmlclass import * @@ -227,7 +228,7 @@ self.GetCTRoot().logger.write_warning( XSDSchemaErrorMessage % (filepath + error)) except Exception as exc: - self.modules_infos, error = None, unicode(exc) + self.modules_infos, error = None, text(exc) xmlfile.close() if self.modules_infos is not None: diff -r 2e8bf28a8909 -r 07f48018b6f5 py_ext/PythonFileCTNMixin.py --- a/py_ext/PythonFileCTNMixin.py Thu Oct 04 12:09:23 2018 +0300 +++ b/py_ext/PythonFileCTNMixin.py Thu Oct 04 17:24:40 2018 +0300 @@ -27,8 +27,9 @@ from __future__ import absolute_import import os import re +from builtins import str as text + import util.paths as paths - from xmlclass import GenerateParserFromXSD from CodeFileTreeNode import CodeFile @@ -74,7 +75,7 @@ self.CreateCodeFileBuffer(False) self.OnCTNSave() except Exception as exc: - error = unicode(exc) + error = text(exc) if error is not None: self.GetCTRoot().logger.write_error( diff -r 2e8bf28a8909 -r 07f48018b6f5 runtime/WampClient.py --- a/runtime/WampClient.py Thu Oct 04 12:09:23 2018 +0300 +++ b/runtime/WampClient.py Thu Oct 04 17:24:40 2018 +0300 @@ -28,6 +28,7 @@ import json import os import re +from builtins import str as text from autobahn.twisted import wamp from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS from autobahn.wamp import types, auth @@ -131,7 +132,7 @@ yield self.register(GetCallee(name), u'.'.join((ID, name)), registerOptions) for name in SubscribedEvents: - yield self.subscribe(GetCallee(name), unicode(name)) + yield self.subscribe(GetCallee(name), text(name)) for func in DoOnJoin: yield func(self) diff -r 2e8bf28a8909 -r 07f48018b6f5 svgui/pyjs/jsonrpc/django/jsonrpc.py --- a/svgui/pyjs/jsonrpc/django/jsonrpc.py Thu Oct 04 12:09:23 2018 +0300 +++ b/svgui/pyjs/jsonrpc/django/jsonrpc.py Thu Oct 04 17:24:40 2018 +0300 @@ -4,6 +4,7 @@ from __future__ import absolute_import import datetime +from builtins import str as text from django.core.serializers import serialize @@ -74,7 +75,7 @@ if error not in d: d[error] = [] for errorval in form.errors[error]: - d[error].append(unicode(errorval)) + d[error].append(text(errorval)) return d @@ -101,7 +102,7 @@ field_type = field.__class__.__name__ msgs = {} for n, m in field.error_messages.items(): - msgs[n] = unicode(m) + msgs[n] = text(m) res['error_messages'] = msgs if field_type in ['ComboField', 'MultiValueField', 'SplitDateTimeField']: res['fields'] = map(describe_field, field.fields) diff -r 2e8bf28a8909 -r 07f48018b6f5 svgui/pyjs/pyjs.py --- a/svgui/pyjs/pyjs.py Thu Oct 04 12:09:23 2018 +0300 +++ b/svgui/pyjs/pyjs.py Thu Oct 04 17:24:40 2018 +0300 @@ -22,6 +22,7 @@ from compiler import ast import os import copy +from builtins import str as text from six.moves import cStringIO # the standard location for builtins (e.g. pyjslib) can be @@ -1359,7 +1360,7 @@ return str(node.value) elif isinstance(node.value, basestring): v = node.value - if isinstance(node.value, unicode): + if isinstance(node.value, text): v = v.encode('utf-8') return "String('%s')" % escapejs(v) elif node.value is None: diff -r 2e8bf28a8909 -r 07f48018b6f5 svgui/svgui_server.py --- a/svgui/svgui_server.py Thu Oct 04 12:09:23 2018 +0300 +++ b/svgui/svgui_server.py Thu Oct 04 17:24:40 2018 +0300 @@ -25,6 +25,7 @@ from __future__ import absolute_import import os +from builtins import str as text from nevow import tags, loaders import simplejson as json # pylint: disable=import-error @@ -122,13 +123,13 @@ def HMIinitialisation(self): gadgets = [] for gadget in svguiWidgets.values(): - gadgets.append(unicode(json.dumps(gadget, default=get_object_init_state, indent=2), 'ascii')) + gadgets.append(text(json.dumps(gadget, default=get_object_init_state, indent=2), 'ascii')) d = self.callRemote('init', gadgets) d.addCallback(self.HMIinitialised) def sendData(self, data): if self.initialised: - return self.callRemote('receiveData', unicode(json.dumps(data, default=get_object_current_state, indent=2), 'ascii')) + return self.callRemote('receiveData', text(json.dumps(data, default=get_object_current_state, indent=2), 'ascii')) return None def setattr(self, id, attrname, value): @@ -139,7 +140,7 @@ id = getNewId() gad = SvguiWidget(args[0], id, **kwargs) svguiWidgets[id] = gad - gadget = [unicode(json.dumps(gad, default=get_object_init_state, indent=2), 'ascii')] + gadget = [text(json.dumps(gad, default=get_object_init_state, indent=2), 'ascii')] interface = website.getHMI() if isinstance(interface, SVGUI_HMI) and interface.initialised: interface.callRemote('init', gadget) diff -r 2e8bf28a8909 -r 07f48018b6f5 tests/tools/check_source.sh --- a/tests/tools/check_source.sh Thu Oct 04 12:09:23 2018 +0300 +++ b/tests/tools/check_source.sh Thu Oct 04 17:24:40 2018 +0300 @@ -357,6 +357,7 @@ # python3 compatibility checks enable=$enable,W1648 # (bad-python3-import) Module moved in Python 3 enable=$enable,W1613 # (xrange-builtin) xrange built-in referenced + enable=$enable,W1612 # (unicode-builtin) unicode built-in referenced # enable= options= diff -r 2e8bf28a8909 -r 07f48018b6f5 util/paths.py --- a/util/paths.py Thu Oct 04 12:09:23 2018 +0300 +++ b/util/paths.py Thu Oct 04 17:24:40 2018 +0300 @@ -26,11 +26,12 @@ from __future__ import absolute_import import os import sys +from builtins import str as text def AbsFile(file): if isinstance(file, str): - file = unicode(file, sys.getfilesystemencoding()) + file = text(file, sys.getfilesystemencoding()) return file diff -r 2e8bf28a8909 -r 07f48018b6f5 xmlclass/xmlclass.py --- a/xmlclass/xmlclass.py Thu Oct 04 12:09:23 2018 +0300 +++ b/xmlclass/xmlclass.py Thu Oct 04 17:24:40 2018 +0300 @@ -32,6 +32,8 @@ from xml.dom import minidom from xml.sax.saxutils import unescape from collections import OrderedDict +from builtins import str as text + from six.moves import xrange from lxml import etree @@ -50,9 +52,9 @@ def NodeSetAttr(node, name, value): attr = minidom.Attr(name) - text = minidom.Text() - text.data = value - attr.childNodes[0] = text + txt = minidom.Text() + txt.data = value + attr.childNodes[0] = txt node._attrs[name] = attr @@ -138,13 +140,13 @@ if not extract: return attr if len(attr.childNodes) == 1: - return unicode(unescape(attr.childNodes[0].data)) + return text(unescape(attr.childNodes[0].data)) else: # content is a CDATA - text = u'' + txt = u'' for node in attr.childNodes: if not (node.nodeName == "#text" and node.data.strip() == u''): - text += unicode(unescape(node.data)) + txt += text(unescape(node.data)) return text