connectors/WAMP_dialog.py
author Edouard Tisserant
Thu, 09 Dec 2021 10:21:45 +0100
branchRuntimeLists
changeset 3395 93ad018fb602
parent 2610 7e31997b2799
child 3750 f62625418bff
permissions -rw-r--r--
RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# See COPYING file for copyrights details.

from __future__ import absolute_import

from itertools import repeat, islice, chain

from connectors.SchemeEditor import SchemeEditor

Schemes = ["WAMP", "WAMPS"]

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


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

    # pylint: disable=unused-variable
    def SetLoc(self, loc):
        hostportpath, realm, ID = list(islice(chain(loc.split("#"), repeat("")), 3))
        hostport, path = list(islice(chain(hostportpath.split("/"), repeat("")), 2))
        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 '') +\
                   ("/{path}" if fields['path'] else '') +\
                   "#{realm}#{ID}"

        return template.format(**fields)