def makeService(config): """Return a service that will be attached to the application.""" if config["file"]: # If I was given a "file" option... # Read quotes from a file, selecting a random one each time, quoter = quoters.FortuneQuoter([config['file']]) else: # otherwise, # read a single quote from the command line (or use the default). quoter = quoters.StaticQuoter(config['static']) port = int(config["port"]) # TCP port to listen on factory = quoteproto.QOTDFactory(quoter) # here we create a QOTDFactory # Finally, set up our factory, with its custom quoter, to create QOTD # protocol instances when events arrive on the specified port. return internet.TCPServer(port, factory)
def makeService(config): svc = service.MultiService() if config["file"]: # If I was given a "file" option... # Read quotes from a file, selecting a random one each time, quoter = quoters.FortuneQuoter([config["file"]]) else: # otherwise, # read a single quote from the command line (or use the default). quoter = quoters.StaticQuoter(config["static"]) port = int(config["port"]) # TCP port to listen on factory = quoteproto.QOTDFactory(quoter) # here we create a QOTDFactory # Finally, set up our factory, with its custom quoter, to create QOTD # protocol instances when events arrive on the specified port. pbport = config["pb"] # TCP PB port to listen on if pbport: pbfact = pb.PBServerFactory(pbquote.QuoteReader(quoter)) svc.addService(internet.TCPServer(int(pbport), pbfact)) svc.addService(internet.TCPServer(port, factory)) return svc