def make_wsgi_app(): # BasicAuth applications create = AuthBasicHandler(BlogCreate, 'www', authfunc) update = AuthBasicHandler(BlogUpdate, 'www', authfunc) delete = AuthBasicHandler(BlogDelete, 'www', authfunc) # URL dispatching middleware dispatch = selector.Selector() dispatch.add('/', GET=BlogIndex) dispatch.prefix = '/article' dispatch.add('/add', GET=create, POST=create) dispatch.add('/{id:digits}', GET=BlogRead) dispatch.add('/{id:digits}/edit', GET=update, POST=update) dispatch.add('/{id:digits}/delete', GET=delete) # Static files from paste.urlparser import StaticURLParser static_app = StaticURLParser("my_wsgi_blog/static/") from paste import urlmap mapping = urlmap.URLMap() mapping['/static'] = static_app from paste.cascade import Cascade app = Cascade([mapping, dispatch]) return app
def __init__(self, server, config, outputter): outputter.add_observer(self._output) self.config = config self.server = server self._wsgi_app = urlmap.URLMap() self._csp = csp.Listener() self._wsgi_app['/csp'] = self._csp static_path = os.path.join( os.path.split(os.path.abspath(__file__))[0], 'static') self._wsgi_app['/'] = urlparser.StaticURLParser(static_path) self._rtjp_server = rtjp_eventlet.RTJPServer() self.console_buffer = "" self._wrap_output() self.conns = [] self.watched_channels = {} self.watched_users = {} self.watched_connections = {} self.channel_list_watchers = [] self.user_list_watchers = [] self.watching_index = {} self.console_watchers = [] self.webhooks_watchers = [] self.webhooks_history = [] eventlet.spawn(self._run)
def map(): # デフォルトのアプリケーションを渡す mapping = urlmap.URLMap(simple.hello) # /fib に来たらフィボナッチな感じ mapping['/fib'] = simple.fib simple.run(mapping)
def application(env, start_response): """wsgiハンドラー """ def is_application(cls): """アプリケーションチェック """ if ('do_logic' in cls.__dict__ and 'JvnApplication' in [x.__name__ for x in cls.__bases__ ]): return True else: for x in cls.__bases__: return is_application(x) return False ###########################本体ロジック######################################### try: jvn_path = os.path.abspath(os.path.dirname(__file__)) app_path = os.path.join(jvn_path, 'webapp') log_path = os.path.join(jvn_path, 'logs') tmp_path = os.path.join(jvn_path, 'tmp') logging.config.fileConfig(os.path.join(jvn_path,"jvn_log.conf") ,defaults={'log_filename': os.path.join(log_path, "jvn.log")}) #------ 動的にアプリケーションをローディングし、URLマップを作成する ----------- # 例 chaing['/jvn_list/index'] = jvn_list.Index()のように動的に設定する sys.path.append(app_path) chain = urlmap.URLMap(logout) chain['/jvn_logout'] = logout l = [os.path.basename(x) for x in glob.glob(os.path.join(app_path, 'jvn*.py'))] for obj in [f.replace('.py','') for f in l ]: m = importlib.import_module(obj) for k in m.__dict__.keys(): cls = m.__dict__[k] # class Hogeの場合は if (type(cls) is types.ClassType if (type(cls) is type) and (True == is_application(cls)): chain['/' + cls.__module__ + '/' + cls.__name__.lower()] = cls() logging.debug('/' + cls.__module__ + '/' + cls.__name__.lower()) #------ プログラム実行 ------------ app = make_session_middleware(chain,{},session_file_path=tmp_path, cookie_name=JVN_SID) return app(env, start_response) except Exception as e: start_response('500 Server Error', [('Content-type', 'text/plain')]) return 'System Error \n' + str(e) + "\n" + traceback.format_exc()
def __init__(self): """Initialisation """ self.urls = urlmap.URLMap( ) # Dispatch for all the registered applications self.apps = {} # List of all the registered applications
from pyramid.wsgi import wsgiapp @wsgiapp def hello_world(environ, start_response): body = 'Hello world' start_response('200 OK', [('Content-Type', 'text/plain'), ('Content-Length', str(len(body)))]) return [body] if __name__ == '__main__': config = Configurator() config.add_route('hello_world', '/') config.add_route('hello_world_wsgi', '/hello_wsgi') config.add_view(hello, route_name='hello_world') config.add_view(hello_world, route_name='hello_world_wsgi') from my_wsgi_blog import make_wsgi_app blog_app = make_wsgi_app() from paste import urlmap mapping = urlmap.URLMap() mapping['/blog'] = blog_app from paste.cascade import Cascade pyramid_app = config.make_wsgi_app() app = Cascade([mapping, pyramid_app]) server = make_server('0.0.0.0', 8000, app) server.serve_forever()
def main(): from paste import httpserver, urlmap, urlparser root_app = urlmap.URLMap() root_app["/js"] = urlparser.make_static({}, os.path.join("public", "js")) root_app["/"] = app httpserver.serve(root_app, host='127.0.0.1', port='8080')
listid=listid, feedbacktype=feedbacktype, feedbackcondition=feedbackcondition, responsetimetype=responsetimetype, experimentname=experimentname, formtype=formtype, recorder_url=recorder_url, debugmode=1 if amz_dict['debug'] else 0, startitem=startitem, # on preview, don't bother loading heavy flash assets preview=in_preview) resp = Response() resp.content_type = 'text/html' resp.unicode_body = t session.close() return resp(environ, start_response) if __name__ == '__main__': import os from paste import httpserver, fileapp, urlmap app = urlmap.URLMap() app['/hit'] = BaeseberkGoldrickRep1Server(app) app['/'] = fileapp.DirectoryApp( os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static')) # app['/mturk/experiments/interactive_communication/img'] = fileapp.DirectoryApp(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'img')) # app['/mturk/experiments/interactive_communication/js'] = fileapp.DirectoryApp(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'js')) # app['/mturk/experiments/interactive_communication/Wami.swf'] = fileapp.FileApp(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'Wami.swf')) httpserver.serve(app, host='127.0.0.1', port=8080)