35 import Pyro.core |
35 import Pyro.core |
36 import Pyro.util |
36 import Pyro.util |
37 from Pyro.errors import PyroError |
37 from Pyro.errors import PyroError |
38 |
38 |
39 import PSKManagement as PSK |
39 import PSKManagement as PSK |
|
40 import connectors.PYRO.PSK_Adapter |
40 from runtime import PlcStatus |
41 from runtime import PlcStatus |
41 |
42 |
42 # this module attribute contains a list of DNS-SD (Zeroconf) service types |
43 |
43 # supported by this connector confnode. |
44 def switch_pyro_adapter(use_ssl): |
44 # |
45 """ |
45 # for connectors that do not support DNS-SD, this attribute can be omitted |
46 Reloads Pyro module with new settings. |
46 # or set to an empty list. |
47 This is workaround for Pyro, because it doesn't work with SSL wrapper. |
|
48 """ |
|
49 # Pyro.config.PYRO_BROKEN_MSGWAITALL = use_ssl |
|
50 reload(Pyro.protocol) |
|
51 if use_ssl: |
|
52 connectors.PYRO.PSK_Adapter.setupPSKAdapter() |
47 |
53 |
48 |
54 |
49 def PYRO_connector_factory(uri, confnodesroot): |
55 def PYRO_connector_factory(uri, confnodesroot): |
50 """ |
56 """ |
51 This returns the connector to Pyro style PLCobject |
57 This returns the connector to Pyro style PLCobject |
52 """ |
58 """ |
53 confnodesroot.logger.write(_("PYRO connecting to URI : %s\n") % uri) |
59 confnodesroot.logger.write(_("PYRO connecting to URI : %s\n") % uri) |
54 |
60 |
55 scheme, location = uri.split("://") |
61 scheme, location = uri.split("://") |
56 if scheme == "PYROS": |
62 use_ssl = scheme == "PYROS" |
57 import connectors.PYRO.PSK_Adapter # pylint: disable=wrong-import-order,unused-import,wrong-import-position |
63 switch_pyro_adapter(use_ssl) |
|
64 if use_ssl: |
58 schemename = "PYROLOCPSK" |
65 schemename = "PYROLOCPSK" |
59 url, ID = location.split('#') # TODO fix exception when # not found |
66 url, ID = location.split('#') # TODO fix exception when # not found |
60 # load PSK from project |
67 # load PSK from project |
61 secpath = os.path.join(str(confnodesroot.ProjectPath), 'psk', ID+'.secret') |
68 secpath = os.path.join(str(confnodesroot.ProjectPath), 'psk', ID+'.secret') |
62 if not os.path.exists(secpath): |
69 if not os.path.exists(secpath): |
71 schemename = "PYROLOC" |
78 schemename = "PYROLOC" |
72 |
79 |
73 # Try to get the proxy object |
80 # Try to get the proxy object |
74 try: |
81 try: |
75 RemotePLCObjectProxy = Pyro.core.getAttrProxyForURI(schemename + "://" + location + "/PLCObject") |
82 RemotePLCObjectProxy = Pyro.core.getAttrProxyForURI(schemename + "://" + location + "/PLCObject") |
76 except Exception, e: |
83 except Exception as e: |
77 confnodesroot.logger.write_error( |
84 confnodesroot.logger.write_error( |
78 _("Connection to {loc} failed with exception {ex}\n").format( |
85 _("Connection to {loc} failed with exception {ex}\n").format( |
79 loc=location, exo=str(e))) |
86 loc=location, ex=str(e))) |
80 return None |
87 return None |
81 |
88 |
82 RemotePLCObjectProxy.adapter.setTimeout(60) |
89 RemotePLCObjectProxy.adapter.setTimeout(60) |
83 |
90 |
84 def PyroCatcher(func, default=None): |
91 def PyroCatcher(func, default=None): |