connectors/PYRO/__init__.py
changeset 2543 2befed4d6ca8
parent 2538 2b75389575df
child 2588 25f19b76c7b6
equal deleted inserted replaced
2542:a3ec35ee94e7 2543:2befed4d6ca8
    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):