connectors/WAMP_dialog.py
changeset 2329 e5703dc8848e
parent 2182 eeca1aff0691
child 2334 d1470c052662
equal deleted inserted replaced
2328:7eb6cb70bf5b 2329:e5703dc8848e
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 # See COPYING file for copyrights details.
       
     5 
       
     6 from __future__ import absolute_import
       
     7 
       
     8 from itertools import repeat, islice, chain
       
     9 import wx
       
    10 
       
    11 from connectors.SchemeEditor import SchemeEditor
       
    12 
       
    13 Schemes = ["WAMP", "WAMPS"]
       
    14 
       
    15 model = [('host',_("Host:")),
       
    16          ('port',_("Port:")),
       
    17          ('realm',_("Realm:")),
       
    18          ('ID',_("ID:"))]
       
    19 
       
    20 class WAMP_dialog(SchemeEditor):
       
    21     def __init__(self, *args, **kwargs):
       
    22         self.model = model
       
    23         SchemeEditor.__init__(self, *args, **kwargs)
       
    24 
       
    25     def SetLoc(self, loc):
       
    26         hostport, realm, ID = list(islice(chain(loc.split("#"), repeat("")),3))
       
    27         host, port = list(islice(chain(hostport.split(":"), repeat("")),2))
       
    28         self.SetFields(locals())
       
    29 
       
    30     def GetLoc(self):
       
    31         fields = self.GetFields()
       
    32 
       
    33         #TODO : input validation test
       
    34 
       
    35         template = "{host}" + \
       
    36                    (":{port}" if fields['port'] else '') +\
       
    37                    "#{realm}#{ID}"
       
    38 
       
    39         return template.format(**fields)
       
    40