1 #!/usr/bin/env python |
1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- |
2 # -*- coding: utf-8 -*- |
3 |
3 |
4 # See COPYING file for copyrights details. |
4 # See COPYING file for copyrights details. |
5 |
5 |
|
6 from connectors.ERPC_URI import schemes_desc, per_scheme_model |
|
7 from connectors.SchemeEditor import SchemeEditor |
|
8 |
|
9 ## Scheme list for the dialog's combobox |
|
10 |
|
11 Schemes = list(zip(*schemes_desc))[0] |
6 |
12 |
7 |
13 |
8 from itertools import repeat, islice, chain |
14 ## Specialized SchemeEditor panel for ERPC |
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), ("ERPC", model, False), ("ERPCS", model, True)] |
|
18 |
|
19 Schemes = list(zip(*models))[0] |
|
20 |
|
21 _PerSchemeConf = {sch: (mod, sec) for sch, mod, sec in models} |
|
22 |
|
23 |
15 |
24 class ERPC_dialog(SchemeEditor): |
16 class ERPC_dialog(SchemeEditor): |
25 def __init__(self, scheme, *args, **kwargs): |
17 def __init__(self, scheme, *args, **kwargs): |
26 # ID selector is enabled only on ERPC (secure) |
18 self.model, self.EnableIDSelector, self.parser, self.builder = per_scheme_model[scheme] |
27 self.model, self.EnableIDSelector = _PerSchemeConf[scheme] |
|
28 |
19 |
29 SchemeEditor.__init__(self, scheme, *args, **kwargs) |
20 SchemeEditor.__init__(self, scheme, *args, **kwargs) |
30 |
21 |
31 # pylint: disable=unused-variable |
|
32 def SetLoc(self, loc): |
22 def SetLoc(self, loc): |
33 hostport, ID = list(islice(chain(loc.split("#"), repeat("")), 2)) |
23 self.SetFields(self.parser(loc)) |
34 host, port = list(islice(chain(hostport.split(":"), repeat("")), 2)) |
|
35 self.SetFields(locals()) |
|
36 |
24 |
37 def GetLoc(self): |
25 def GetLoc(self): |
38 if self.model: |
26 return self.builder(self.GetFields()) |
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 '' |
|