def main(args=None, returnWithoutLooping=False): 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("-n", "--naming", action="store_true", default=False, help="register with nameserver") parser.add_option("-N", "--nameserver", action="store_true", default=False, help="also start a nameserver") parser.add_option("-v", "--verbose", action="store_true", default=False, help="verbose output") 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 options.verbose: options.quiet = False if not options.quiet: print("Starting Pyro's built-in test echo server.") config.SERVERTYPE = "multiplex" 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!") nameserver = None if options.nameserver: options.naming = True nameserver = startNameServer(options.host, hmac=hmac) d = core.Daemon(host=options.host, port=options.port, unixsocket=options.unixsocket) if hmac: d._pyroHmacKey = hmac echo = EchoServer() echo._verbose = options.verbose objectName = "test.echoserver" uri = d.register(echo, objectName) if options.naming: host, port = None, None if nameserver is not None: host, port = nameserver.uri.host, nameserver.uri.port ns = naming.locateNS(host, port, hmac_key=hmac) ns.register(objectName, uri) if options.verbose: print("using name server at %s" % ns._pyroUri) if nameserver is not None: if nameserver.bc_server: print("broadcast server running at %s" % nameserver.bc_server.locationStr) else: print("not using a broadcast server") else: if options.verbose: print("not using a name server.") if not options.quiet: print("object name: %s" % objectName) print("echo uri: %s" % uri) print("echoserver running.") if returnWithoutLooping: return d, echo, uri # for unit testing else: d.requestLoop(loopCondition=lambda: not echo._must_shutdown) d.close()
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