runtime/WampClient.py
branchpython3
changeset 3750 f62625418bff
parent 3440 3770ded5db5c
child 3752 9f6f46dbe3ae
equal deleted inserted replaced
3749:fda6c1a37662 3750:f62625418bff
    20 # You should have received a copy of the GNU Lesser General Public
    20 # You should have received a copy of the GNU Lesser General Public
    21 # License along with this library; if not, write to the Free Software
    21 # License along with this library; if not, write to the Free Software
    22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    23 
    23 
    24 
    24 
    25 from __future__ import absolute_import
    25 
    26 from __future__ import print_function
    26 
    27 import time
    27 import time
    28 import json
    28 import json
    29 import os
    29 import os
    30 import re
    30 import re
    31 from six import text_type as text
    31 from six import text_type as text
   108 class WampSession(wamp.ApplicationSession):
   108 class WampSession(wamp.ApplicationSession):
   109 
   109 
   110     def onConnect(self):
   110     def onConnect(self):
   111         if "secret" in self.config.extra:
   111         if "secret" in self.config.extra:
   112             user = self.config.extra["ID"]
   112             user = self.config.extra["ID"]
   113             self.join(u"Automation", [u"wampcra"], user)
   113             self.join("Automation", ["wampcra"], user)
   114         else:
   114         else:
   115             self.join(u"Automation")
   115             self.join("Automation")
   116 
   116 
   117     def onChallenge(self, challenge):
   117     def onChallenge(self, challenge):
   118         if challenge.method == u"wampcra":
   118         if challenge.method == "wampcra":
   119             if "secret" in self.config.extra:
   119             if "secret" in self.config.extra:
   120                 secret = self.config.extra["secret"].encode('utf8')
   120                 secret = self.config.extra["secret"].encode('utf8')
   121                 signature = auth.compute_wcs(
   121                 signature = auth.compute_wcs(
   122                     secret, challenge.extra['challenge'].encode('utf8'))
   122                     secret, challenge.extra['challenge'].encode('utf8'))
   123                 return signature.decode("ascii")
   123                 return signature.decode("ascii")
   137                 registerOptions = types.RegisterOptions(**kwargs)
   137                 registerOptions = types.RegisterOptions(**kwargs)
   138             except TypeError as e:
   138             except TypeError as e:
   139                 registerOptions = None
   139                 registerOptions = None
   140                 print(_("TypeError register option: {}".format(e)))
   140                 print(_("TypeError register option: {}".format(e)))
   141 
   141 
   142             self.register(GetCallee(name), u'.'.join((ID, name)), registerOptions)
   142             self.register(GetCallee(name), '.'.join((ID, name)), registerOptions)
   143 
   143 
   144         for name in SubscribedEvents:
   144         for name in SubscribedEvents:
   145             self.subscribe(GetCallee(name), text(name))
   145             self.subscribe(GetCallee(name), text(name))
   146 
   146 
   147         for func in DoOnJoin:
   147         for func in DoOnJoin:
   183         except Exception as e:
   183         except Exception as e:
   184             print(_("Custom protocol options failed :"), e)
   184             print(_("Custom protocol options failed :"), e)
   185             _transportFactory = None
   185             _transportFactory = None
   186 
   186 
   187     def setClientFactoryOptions(self, options):
   187     def setClientFactoryOptions(self, options):
   188         for key, value in options.items():
   188         for key, value in list(options.items()):
   189             if key in ["maxDelay", "initialDelay", "maxRetries", "factor", "jitter"]:
   189             if key in ["maxDelay", "initialDelay", "maxRetries", "factor", "jitter"]:
   190                 setattr(self, key, value)
   190                 setattr(self, key, value)
   191 
   191 
   192     def buildProtocol(self, addr):
   192     def buildProtocol(self, addr):
   193         self.resetDelay()
   193         self.resetDelay()
   212         raise annotate.ValidateError(
   212         raise annotate.ValidateError(
   213             {"url": "Invalid URL: {}".format(url)},
   213             {"url": "Invalid URL: {}".format(url)},
   214             _("WAMP configuration error:"))
   214             _("WAMP configuration error:"))
   215 
   215 
   216 def UpdateWithDefault(d1, d2):
   216 def UpdateWithDefault(d1, d2):
   217     for k, v in d2.items():
   217     for k, v in list(d2.items()):
   218         d1.setdefault(k, v)
   218         d1.setdefault(k, v)
   219 
   219 
   220 def GetConfiguration():
   220 def GetConfiguration():
   221     global lastKnownConfig
   221     global lastKnownConfig
   222 
   222