1 #!/usr/bin/env python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # See COPYING file for copyrights details. |
|
5 |
|
6 |
|
7 |
|
8 from itertools import repeat, islice, chain |
|
9 |
|
10 from connectors.SchemeEditor import SchemeEditor |
|
11 |
|
12 |
|
13 model = [('host', _("Host:")), |
|
14 ('port', _("Port:"))] |
|
15 |
|
16 # (scheme, model, secure) |
|
17 models = [("LOCAL", [], False), ("PYRO", model, False)] |
|
18 |
|
19 Schemes = list(zip(*models))[0] |
|
20 |
|
21 _PerSchemeConf = {sch: (mod, sec) for sch, mod, sec in models} |
|
22 |
|
23 |
|
24 class PYRO_dialog(SchemeEditor): |
|
25 def __init__(self, scheme, *args, **kwargs): |
|
26 # ID selector is enabled only on PYROS (secure) |
|
27 self.model, self.EnableIDSelector = _PerSchemeConf[scheme] |
|
28 |
|
29 SchemeEditor.__init__(self, scheme, *args, **kwargs) |
|
30 |
|
31 # pylint: disable=unused-variable |
|
32 def SetLoc(self, loc): |
|
33 hostport, ID = list(islice(chain(loc.split("#"), repeat("")), 2)) |
|
34 host, port = list(islice(chain(hostport.split(":"), repeat("")), 2)) |
|
35 self.SetFields(locals()) |
|
36 |
|
37 def GetLoc(self): |
|
38 if self.model: |
|
39 fields = self.GetFields() |
|
40 template = "{host}" |
|
41 if fields['port']: |
|
42 template += ":{port}" |
|
43 if self.EnableIDSelector: |
|
44 if fields['ID']: |
|
45 template += "#{ID}" |
|
46 |
|
47 return template.format(**fields) |
|
48 return '' |
|