def share_local_objects(wait=False, host="localhost", port=0): """ Share all local objects of the given name over the network. :param bool wait: whether to wait for a loop exit (e.g. if not running this function's code locally) :param str host: ip address of the local sharing server :param int port: port of the local sharing server This function shares all possible python code (dangerous) and not just a custom object with whitelisted attributes (secure). """ Pyro4.config.FLAME_ENABLED = True Pyro4.config.SERIALIZER = "pickle" Pyro4.config.SERIALIZERS_ACCEPTED = {"pickle"} # pyro daemon pyro_daemon = Pyro4.Daemon(host=host, port=port) LOG.debug("Pyro4 daemon started successfully") # main retrieval of the local objects from Pyro4.utils import flame _uri = flame.start(pyro_daemon) # lgtm [py/unused-local-variable] # request loop loop = DaemonLoop(pyro_daemon) loop.start() if wait: loop.join()
def run(self, plugins=None): Pyro4.config.SERIALIZERS_ACCEPTED = set(['pickle']) Pyro4.config.FLAME_ENABLED = True self._daemon = Pyro4.Daemon( host=self._host, port=self._port, unixsocket=self._unixsocket, ) if plugins is None: plugins = {} for plugin_name, plugin in plugins.items(): self._daemon.register(plugin, 'plugin-%s' % plugin_name) self._daemon.register(self, 'server') flame.start(self._daemon) self._daemon.requestLoop()
def main(args=None, returnWithoutLooping=False): from optparse import OptionParser parser = OptionParser() parser.add_option("-H", "--host", default="localhost", help="hostname to bind server on (default=%default)") parser.add_option("-p", "--port", type="int", default=0, help="port to bind server on") parser.add_option("-u", "--unixsocket", help="Unix domain socket name to bind server on") parser.add_option("-q", "--quiet", action="store_true", default=False, help="don't output anything") parser.add_option("-k", "--key", help="the HMAC key to use") options, args = parser.parse_args(args) if not options.quiet: print("Starting Pyro Flame server.") hmac = (options.key or "").encode("utf-8") if not hmac and not options.quiet: print("Warning: HMAC key not set. Anyone can connect to this server!") config.SERIALIZERS_ACCEPTED = { "pickle" } # flame requires pickle serializer, doesn't work with the others. daemon = core.Daemon(host=options.host, port=options.port, unixsocket=options.unixsocket) if hmac: daemon._pyroHmacKey = hmac uri = flame.start(daemon) if not options.quiet: print("server uri: %s" % uri) print("server is running.") if returnWithoutLooping: return daemon, uri # for unit testing else: daemon.requestLoop() daemon.close() return 0
def main(args=None, returnWithoutLooping=False): from optparse import OptionParser parser = OptionParser() parser.add_option("-H", "--host", default="localhost", help="hostname to bind server on (default=%default)") parser.add_option("-p", "--port", type="int", default=0, help="port to bind server on") parser.add_option("-u", "--unixsocket", help="Unix domain socket name to bind server on") parser.add_option("-q", "--quiet", action="store_true", default=False, help="don't output anything") parser.add_option("-k", "--key", help="the HMAC key to use (deprecated)") options, args = parser.parse_args(args) if options.key: warnings.warn( "using -k to supply HMAC key on the command line is a security problem " "and is deprecated since Pyro 4.72. See the documentation for an alternative." ) if "PYRO_HMAC_KEY" in os.environ: if options.key: raise SystemExit( "error: don't use -k and PYRO_HMAC_KEY at the same time") options.key = os.environ["PYRO_HMAC_KEY"] if not options.quiet: print("Starting Pyro Flame server.") hmac = (options.key or "").encode("utf-8") if not hmac and not options.quiet: print("Warning: HMAC key not set. Anyone can connect to this server!") config.SERIALIZERS_ACCEPTED = { "pickle" } # flame requires pickle serializer, doesn't work with the others. daemon = core.Daemon(host=options.host, port=options.port, unixsocket=options.unixsocket) if hmac: daemon._pyroHmacKey = hmac uri = flame.start(daemon) if not options.quiet: print("server uri: %s" % uri) print("server is running.") if returnWithoutLooping: return daemon, uri # for unit testing else: daemon.requestLoop() daemon.close() return 0