connectors/WAMP_dialog.py
author Edouard Tisserant
Fri, 01 Feb 2019 14:14:13 +0100
changeset 2486 44c2a4e2b84d
parent 2334 d1470c052662
child 2492 7dd551ac2fa0
permissions -rw-r--r--
Fixed deadlock in runtime's Worker. Was discovered while using WAMP and PYRO simultaneously.
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# See COPYING file for copyrights details.

from __future__ import absolute_import

from itertools import repeat, islice, chain
import wx

from connectors.SchemeEditor import SchemeEditor

Schemes = ["WAMP", "WAMPS"]

model = [('host',_("Host:")),
         ('port',_("Port:")),
         ('realm',_("Realm:"))]

class WAMP_dialog(SchemeEditor):
    def __init__(self, *args, **kwargs):
        self.model = model
        self.EnableIDSelector = True
        SchemeEditor.__init__(self, *args, **kwargs)

    def SetLoc(self, loc):
        hostport, realm, ID = list(islice(chain(loc.split("#"), repeat("")),3))
        host, port = list(islice(chain(hostport.split(":"), repeat("")),2))
        self.SetFields(locals())

    def GetLoc(self):
        fields = self.GetFields()

        #TODO : input validation test

        template = "{host}" + \
                   (":{port}" if fields['port'] else '') +\
                   "#{realm}#{ID}"

        return template.format(**fields)