def start( app=None, port=None, runCondition=True, method=None, debug=False, color=False, log=False, config=None ): """Runs the given application (by default created by 'createApp()' as standalone.""" setLocales (LOCALES) if (debug or log) and reporter: reporter.register(reporter.StdoutReporter(color=color)) if debug: reporter.setLevel(reporter.DEBUG) if app is None: app = createApp(config=config) name = app.config("appname") port = port or app.config("port") or PORT lib_python_path = app.config("library.python.path") method = method or app.config("method") or STANDALONE info("Starting Web application {0} on {2}:{3} [{1}] ".format(name, method, app.config("host") or "0.0.0.0", app.config("port"))) if method == STANDALONE: info(app.config()) info(app.info()) Dispatcher.EnableLog() if not lib_python_path in sys.path: sys.path.insert(0, lib_python_path) return run( app = app, port = port, name = name, method = method, sessions = False, # FIXME: withReactor doesn't work!! withReactor = False, )
def run(args): if type(args) not in (type([]), type(())): args = [args] from optparse import OptionParser # We create the parse and register the options oparser = OptionParser(version="Retro[+proxy]") oparser.add_option("-p", "--port", action="store", dest="port", help=OPT_PORT, default=DEFAULT_PORT) oparser.add_option("-f", "--files", action="store_true", dest="files", help="Server local files", default=None) oparser.add_option( "-t", "--throttle", action="store", dest="throttling", help="Throttles connection speed (in Kbytes/second)", default=0, ) # We parse the options and arguments options, args = oparser.parse_args(args=args) if len(args) == 0: print("The URL to proxy is expected as first argument") return False components = createProxies(args, dict(port=options.port, throttling=options.throttling, files=options.files)) if options.files: import retro.contrib.localfiles print("Serving local files...") components.append(retro.contrib.localfiles.LocalFiles()) app = Application(components=components) import retro return retro.run(app=app, sessions=False, port=int(options.port))
def run(args): if type(args) not in (type([]), type(())): args = [args] from optparse import OptionParser # We create the parse and register the options oparser = OptionParser(version="Retro[+proxy]") oparser.add_option("-p", "--port", action="store", dest="port", help=OPT_PORT, default="8000") oparser.add_option("-f", "--files", action="store_true", dest="files", help="Server local files", default=None) # We parse the options and arguments options, args = oparser.parse_args(args=args) if len(args) == 0: print "The URL to proxy is expected as first argument" return False components = self.createProxies(args) if options.files: import retro.contrib.localfiles print "Serving local files..." components.append(retro.contrib.localfiles.LocalFiles()) app = Application(components=components) import retro return retro.run(app=app, sessions=False, port=int(options.port))
def run( args ): if type(args) not in (type([]), type(())): args = [args] from optparse import OptionParser # We create the parse and register the options oparser = OptionParser(version="Retro[+record]") oparser.add_option("-p", "--port", action="store", dest="port", help=OPT_PORT, default="8000") oparser.add_option("-f", "--files", action="store_true", dest="files", help="Server local files", default=None) # We parse the options and arguments options, args = oparser.parse_args(args=args) app = Application(components=[Record()]) import retro return retro.run(app=app,sessions=False,port=int(options.port))
def run( args ): if type(args) not in (type([]), type(())): args = [args] from optparse import OptionParser # We create the parse and register the options oparser = OptionParser(version="Retro[+proxy]") oparser.add_option("-p", "--port", action="store", dest="port", help=OPT_PORT, default="8000") oparser.add_option("-f", "--files", action="store_true", dest="files", help="Server local files", default=None) # We parse the options and arguments options, args = oparser.parse_args(args=args) if len(args) == 0: print "The URL to proxy is expected as first argument" return False components = self.createProxies(args) if options.files: import retro.contrib.localfiles print "Serving local files..." components.append(retro.contrib.localfiles.LocalFiles()) app = Application(components=components) import retro return retro.run(app=app,sessions=False,port=int(options.port))
from retro import ajax, on, run, Component import time class Watch(Component): @on(GET="/time") def getTime( self, request ): def stream(): while True: yield "<html><body><pre>%s</pre></body></html>" % (time.ctime()) time.sleep(1) return request.respondMultiple(stream()) run(components=[Watch()])
# ------------------------------------------------------------------------------ class Main(retro.Component): @retro.on(GET_POST_UPDATE_DELETE="{path:any}") async def echo( self, request, path ): body = await request.body() sys.stdout.write(retro.ensureString(body)) sys.stdout.write("\n\n") sys.stdout.flush() return request.respond(body) # ------------------------------------------------------------------------------ # # Main # # ------------------------------------------------------------------------------ if __name__ == "__main__": main = Main() retro.run( app = retro.Application(main), name = os.path.splitext(os.path.basename(__file__))[1], method = retro.STANDALONE, port = 9030, async = True ) # EOF - vim: tw=80 ts=4 sw=4 noet
from retro import ajax, on, run, Component class Telephone(Component): def __init__( self ): Component.__init__(self) self.tube = [] @ajax(GET="/listen") def listen( self ): if self.tube: m = self.tube[0] ; del self.tube[0] return m @ajax(GET="/say/{something:rest}") def say( self, something ): self.tube.append(something) run(components=[Telephone()])