PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
authorEdouard Tisserant
Thu, 18 Oct 2018 13:17:48 +0200
changeset 2314 e927c101ce6d
parent 2313 2eaf235270f8
child 2315 523559fe6352
child 2316 5416c76df9e2
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
connectors/PYRO/PSK_Adapter.py
connectors/PYRO/__init__.py
--- a/connectors/PYRO/PSK_Adapter.py	Thu Oct 18 11:01:14 2018 +0200
+++ b/connectors/PYRO/PSK_Adapter.py	Thu Oct 18 13:17:48 2018 +0200
@@ -2,8 +2,10 @@
 from __future__ import print_function
 
 import socket
+import re
 import sslpsk
 import Pyro
+from Pyro.core import PyroURI
 from Pyro.protocol import _connect_socket,TCPConnection,PYROAdapter
 from Pyro.errors import ConnectionDeniedError, ProtocolError
 from Pyro.util import Log
@@ -45,8 +47,8 @@
                     self.conn=conn
                     self.conn.connected=1
                     Log.msg('PYROAdapter','connected to',str(URI))
-                    if URI.protocol=='PYROLOC':
-                        self.resolvePYROLOC_URI("PYRO") # updates self.URI
+                    if URI.protocol=='PYROLOCPSK':
+                        self.resolvePYROLOC_URI("PYROPSK") # updates self.URI
                 elif msg[:len(self.denyMSG)]==self.denyMSG:
                     try:
                         raise ConnectionDeniedError(Pyro.constants.deniedReasons[int(msg[-1])])
@@ -64,3 +66,18 @@
 
 Pyro.protocol.getProtocolAdapter = getProtocolAdapter
 
+_processStringURI = Pyro.core.processStringURI
+def processStringURI(URI):
+    x=re.match(r'(?P<protocol>PYROLOCPSK)://(?P<hostname>[^\s:]+):?(?P<port>\d+)?/(?P<name>\S*)',URI)
+    if x:
+        protocol=x.group('protocol')
+        hostname=x.group('hostname')
+        port=x.group('port')
+        if port:
+            port=int(port)
+        else:
+            port=0
+        name=x.group('name')
+        return PyroURI(hostname,name,port,protocol)
+    return _processStringURI(URI)
+Pyro.core.processStringURI = processStringURI
--- a/connectors/PYRO/__init__.py	Thu Oct 18 11:01:14 2018 +0200
+++ b/connectors/PYRO/__init__.py	Thu Oct 18 13:17:48 2018 +0200
@@ -53,7 +53,7 @@
     servicetype, location = uri.split("://")
     if servicetype == "PYROS":
         import connectors.PYRO.PSK_Adapter
-        schemename = "PYROPSK"
+        schemename = "PYROLOCPSK"
         url, ID = location.split('#')
         # load PSK from project
         secpath = os.path.join(str(confnodesroot.ProjectPath), 'psk', ID+'.secret')