<s> import sys <EOL> import logging <EOL> import webbrowser <EOL> from os . path import join , dirname <EOL> from optparse import OptionParser <EOL> from wsgiref . simple_server import make_server <EOL> from paste . session import SessionMiddleware <EOL> from paste . fileapp import DirectoryApp , FileApp <EOL> from muntjac . demo . util import InMemorySession <EOL> from muntjac . terminal . gwt . server . application_servlet import ApplicationServlet <EOL> from muntjac . demo . main import urlmap <EOL> from muntjac . test . suite import main as test <EOL> def muntjac ( application , host = '<STR_LIT:localhost>' , port = <NUM_LIT> , nogui = False , <EOL> debug = False , serve = True , forever = True , servletClass = None , <EOL> * args , ** kw_args ) : <EOL> if servletClass is None : <EOL> servletClass = ApplicationServlet <EOL> level = logging . DEBUG if debug else logging . INFO <EOL> logging . basicConfig ( stream = sys . stdout , level = level , <EOL> format = '<STR_LIT>' ) <EOL> wsgi_app = servletClass ( application , debug = debug , * args , ** kw_args ) <EOL> wsgi_app = SessionMiddleware ( wsgi_app , session_class = InMemorySession ) <EOL> url = '<STR_LIT>' % ( host , port ) <EOL> if nogui == False : <EOL> webbrowser . open ( url , new = <NUM_LIT:0> ) <EOL> httpd = make_server ( host , port , wsgi_app ) <EOL> if serve : <EOL> print '<STR_LIT>' % url <EOL> if forever : <EOL> httpd . serve_forever ( ) <EOL> else : <EOL> httpd . handle_request ( ) <EOL> def main ( args = sys . argv [ <NUM_LIT:1> : ] ) : <EOL> parser = OptionParser ( <EOL> usage = '<STR_LIT>' , <EOL> version = '<STR_LIT>' % '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , default = '<STR_LIT:localhost>' , type = '<STR_LIT:string>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , default = <NUM_LIT> , type = '<STR_LIT:int>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , default = '<STR_LIT>' , type = '<STR_LIT:string>' , <EOL> help = '<STR_LIT>' ) <EOL> opts , args = parser . parse_args ( args ) <EOL> level = logging . DEBUG if opts . debug else logging . INFO <EOL> logging . basicConfig ( stream = sys . stdout , level = level , <EOL> format = '<STR_LIT>' ) <EOL> if opts . test : <EOL> test ( ) <EOL> else : <EOL> nargs = len ( args ) <EOL> if nargs > <NUM_LIT:0> : <EOL> sys . stderr . write ( '<STR_LIT>' ) <EOL> parser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> rootapp = FileApp ( join ( dirname ( __file__ ) , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> cssapp = DirectoryApp ( join ( dirname ( __file__ ) , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> imgapp = DirectoryApp ( join ( dirname ( __file__ ) , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> urlmap [ '<STR_LIT:/>' ] = rootapp <EOL> urlmap [ '<STR_LIT>' ] = cssapp <EOL> urlmap [ '<STR_LIT>' ] = imgapp <EOL> if opts . contextRoot : <EOL> ctxapp = DirectoryApp ( join ( opts . contextRoot , '<STR_LIT>' ) ) <EOL> urlmap [ '<STR_LIT>' ] = ctxapp <EOL> app = SessionMiddleware ( urlmap , session_class = InMemorySession ) <EOL> url = '<STR_LIT>' % ( opts . host , opts . port ) <EOL> if not opts . nogui : <EOL> webbrowser . open ( url , new = <NUM_LIT:0> ) <EOL> print '<STR_LIT>' % url <EOL> httpd = make_server ( opts . host , opts . port , app ) <EOL> try : <EOL> httpd . serve_forever ( ) <EOL> except KeyboardInterrupt : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
