denis@2007: #!/usr/bin/env python
denis@2007: # -*- coding: utf-8 -*-
denis@2007: 
denis@2007: # See COPYING file for copyrights details.
denis@2007: 
kinsamanka@3750: 
denis@2007: 
Edouard@2329: from itertools import repeat, islice, chain
andrej@2182: 
Edouard@2329: from connectors.SchemeEditor import SchemeEditor
andrej@2182: 
Edouard@2329: Schemes = ["WAMP", "WAMPS"]
denis@2007: 
edouard@2492: model = [('host', _("Host:")),
Edouard@2610:          ('path', _("Path:")),
edouard@2492:          ('port', _("Port:")),
edouard@2492:          ('realm', _("Realm:"))]
edouard@2492: 
denis@2007: 
Edouard@2329: class WAMP_dialog(SchemeEditor):
Edouard@2329:     def __init__(self, *args, **kwargs):
Edouard@2329:         self.model = model
Edouard@2334:         self.EnableIDSelector = True
Edouard@2329:         SchemeEditor.__init__(self, *args, **kwargs)
denis@2007: 
edouard@2492:     # pylint: disable=unused-variable
Edouard@2329:     def SetLoc(self, loc):
Edouard@2610:         hostportpath, realm, ID = list(islice(chain(loc.split("#"), repeat("")), 3))
Edouard@2610:         hostport, path = list(islice(chain(hostportpath.split("/"), repeat("")), 2))
edouard@2492:         host, port = list(islice(chain(hostport.split(":"), repeat("")), 2))
Edouard@2329:         self.SetFields(locals())
denis@2007: 
Edouard@2329:     def GetLoc(self):
Edouard@2329:         fields = self.GetFields()
denis@2007: 
edouard@2492:         # TODO : input validation test
denis@2007: 
Edouard@2329:         template = "{host}" + \
Edouard@2329:                    (":{port}" if fields['port'] else '') +\
Edouard@2610:                    ("/{path}" if fields['path'] else '') +\
Edouard@2329:                    "#{realm}#{ID}"
denis@2007: 
Edouard@2329:         return template.format(**fields)