beremiz

WAMP: more fixes related to backport from python2 to python3
py2compat
15 months ago, Edouard Tisserant
4876b441a291
Parents 0a845372bc88
Children 0413874f2462
WAMP: more fixes related to backport from python2 to python3
--- a/PSKManagement.py Wed Mar 12 13:19:11 2025 +0100
+++ b/PSKManagement.py Wed Mar 12 13:21:47 2025 +0100
@@ -181,7 +181,7 @@
ID, _sep, PSK = open(own_identity).read().partition(':')
secretstring = PSK.rstrip('\n\r')
else:
- ID = os.urandom(8).hex()
+ ID = "".join([hex(ord(c)).translate(None,'x')[-2:] for c in os.urandom(8)])
# secret string length is 256
# b2a_base64 output len is 4/3 input len
secret = os.urandom(192) # int(256/1.3333)
--- a/connectors/PYRO/__init__.py Wed Mar 12 13:19:11 2025 +0100
+++ b/connectors/PYRO/__init__.py Wed Mar 12 13:21:47 2025 +0100
@@ -36,6 +36,7 @@
import Pyro.util
from Pyro.errors import PyroError
+from connectors.ConnectorBase import ConnectorBase
import PSKManagement as PSK
from connectors.PYRO.PSK_Adapter import setupPSKAdapter
@@ -123,7 +124,7 @@
ID, secret = IDPSK
PSK.UpdateID(confnodesroot.ProjectPath, ID, secret, uri)
- class PyroProxyProxy(object):
+ class PyroProxyProxy(ConnectorBase):
"""
A proxy proxy class to handle Beremiz Pyro interface specific behavior.
And to put Pyro exception catcher in between caller and Pyro proxy
@@ -141,4 +142,4 @@
self.__dict__[attrName] = member
return member
- return PyroProxyProxy
+ return PyroProxyProxy()
--- a/connectors/WAMP/__init__.py Wed Mar 12 13:19:11 2025 +0100
+++ b/connectors/WAMP/__init__.py Wed Mar 12 13:21:47 2025 +0100
@@ -55,7 +55,7 @@
class WampSession(wamp.ApplicationSession):
def onConnect(self):
user = self.config.extra["IDE_ID"]
- self.join(self.config.realm, ["wampcra"], user)
+ self.join(unicode(self.config.realm), [u"wampcra"], unicode(user))
def onChallenge(self, challenge):
if challenge.method == "wampcra":
@@ -89,7 +89,7 @@
elif details.reason == "wamp.error.not_authorized":
_WampError = "WAMP authentication failed. Check IDE identity in security manager."
else:
- _WampError = f"WAMP closed with error {details.reason}: {details.message}"
+ _WampError = "WAMP closed with error {}: {}".format(details.reason, details.message)
_WampConnectEvent.set()
@@ -165,7 +165,7 @@
trustRoot=OpenSSLCertificateAuthorities([cert])
else:
confnodesroot.logger.write_warning("Wamp trust store not found")
- contextFactory = optionsForClientTLS(transport_factory.host, trustRoot=trustRoot)
+ contextFactory = optionsForClientTLS(unicode(transport_factory.host), trustRoot=trustRoot)
# start the client from a Twisted endpoint
conn = connectWS(transport_factory, contextFactory)
@@ -197,7 +197,7 @@
return None
else:
if _WampSession is None:
- confnodesroot.logger.write_error(f"WAMP connection failed: {_WampError}\n")
+ confnodesroot.logger.write_error("WAMP connection failed: {}\n".format(_WampError))
return None
@@ -209,7 +209,7 @@
# reactor.stop()
def WampSessionProcMapper(self, funcname):
- wampfuncname = text('.'.join((ID, funcname)))
+ wampfuncname = text('.'.join((PLC_ID, funcname)))
def catcher_func(*args, **kwargs):
if _WampSession is not None:
--- a/connectors/__init__.py Wed Mar 12 13:19:11 2025 +0100
+++ b/connectors/__init__.py Wed Mar 12 13:21:47 2025 +0100
@@ -110,15 +110,8 @@
# import module according to uri type and get connector specific baseclass
# first call to import the module,
- # then call with parameters to create the class
- connector_specific_class = connectors[scheme]()(uri, confnodesroot)
-
- if connector_specific_class is None:
- return None
-
- # new class inheriting from generic and specific connector base classes
- return type(_scheme + "_connector",
- (ConnectorBase, connector_specific_class), {})()
+ # then call with parameters to create the connector object
+ return connectors[scheme]()(uri, confnodesroot)
def EditorClassFromScheme(scheme):
--- a/controls/CertBrowser.py Wed Mar 12 13:19:11 2025 +0100
+++ b/controls/CertBrowser.py Wed Mar 12 13:21:47 2025 +0100
@@ -11,12 +11,12 @@
from dialogs.MsgConfirmDialog import MsgConfirmDialog
-class CertBrowserModel(dv.DataViewIndexListModel):
+class CertBrowserModel(dv.PyDataViewIndexListModel):
def __init__(self, columncount, log):
self.columncount = columncount
self.log = log
self.data = GetData(log)
- dv.DataViewIndexListModel.__init__(self, len(self.data))
+ dv.PyDataViewIndexListModel.__init__(self, len(self.data))
def _saveData(self):
SaveData(self.data)
--- a/controls/IDBrowser.py Wed Mar 12 13:19:11 2025 +0100
+++ b/controls/IDBrowser.py Wed Mar 12 13:21:47 2025 +0100
@@ -11,12 +11,12 @@
from dialogs.MsgConfirmDialog import MsgConfirmDialog
-class IDBrowserModel(dv.DataViewIndexListModel):
+class IDBrowserModel(dv.PyDataViewIndexListModel):
def __init__(self, project_path, columncount):
self.project_path = project_path
self.columncount = columncount
self.data = PSK.GetData(project_path)
- dv.DataViewIndexListModel.__init__(self, len(self.data))
+ dv.PyDataViewIndexListModel.__init__(self, len(self.data))
def _saveData(self):
PSK.SaveData(self.project_path, self.data)
--- a/runtime/WampClient.py Wed Mar 12 13:19:11 2025 +0100
+++ b/runtime/WampClient.py Wed Mar 12 13:21:47 2025 +0100
@@ -119,7 +119,7 @@
def onConnect(self):
user = self.config.extra["ID"]
- self.join(self.config.realm, ["wampcra"], user)
+ self.join(unicode(self.config.realm), [u"wampcra"], unicode(user))
def onChallenge(self, challenge):
if challenge.method == "wampcra":
@@ -220,16 +220,14 @@
def clientConnectionFailed(self, connector, reason):
print("WAMP Client connection failed (%s) .. retrying .." %
time.ctime())
- super(ReconnectingWampWebSocketClientFactory,
- self).clientConnectionFailed(connector, reason)
self._clientConnectionLostOrFailed(connector, reason)
+ ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
def clientConnectionLost(self, connector, reason):
print("WAMP Client connection lost (%s) .. retrying .." %
time.ctime())
- super(ReconnectingWampWebSocketClientFactory,
- self).clientConnectionFailed(connector, reason)
self._clientConnectionLostOrFailed(connector, reason)
+ ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
def CheckConfiguration(WampClientConf):
@@ -389,10 +387,10 @@
if os.path.exists(_WampTrust):
cert = crypto.load_certificate(
crypto.FILETYPE_PEM,
- six.u(open(_WampTrust, 'r').read())
+ open(_WampTrust, 'rb').read()
)
trustRoot=OpenSSLCertificateAuthorities([cert])
- return optionsForClientTLS(_transportFactory.host, trustRoot=trustRoot)
+ return optionsForClientTLS(unicode(_transportFactory.host), trustRoot=trustRoot)
def StopReconnectWampClient():
if _transportFactory is not None: