예제 #1
0
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether this application provides a full WSGI stack (by default,
        meaning it handles its own exceptions and errors). Disable
        full_stack when this application is "managed" by another WSGI
        middleware.

    ``static_files``
        Whether this application serves its own static files; disable
        when another web server is responsible for serving them.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp()

    # Routing/Session/Cache Middleware
    app = RoutesMiddleware(app, config['routes.map'])
    app = SessionMiddleware(app, config)
    app = CacheMiddleware(app, config)

    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
    app = twa.make_middleware(app, {
        'toscawidgets.framework': 'pylons',
        'toscawidgets.framework.default_view': 'mako',
        })

    if asbool(full_stack):
        # Handle Python exceptions
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])

        # Display error documents for 401, 403, 404 status codes (and
        # 500 when debug is disabled)
        if asbool(config['debug']):
            app = StatusCodeRedirect(app)
        else:
            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

    # Establish the Registry for this application
    app = RegistryManager(app)

    if asbool(static_files):
        # Serve static files
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
        app = Cascade([static_app, app])

    return app
예제 #2
0
파일: wsgiapp.py 프로젝트: lmacken/moksha
 def __init__(self, global_conf={}, template_dirs=None, interactive=False,
              docs_dir=None, full_stack=True):
     if isinstance(template_dirs, basestring):
         template_dirs = template_dirs.split()
     template_dirs = template_dirs or []
     template_dirs.append(resource_filename('moksha.widgetbrowser', 'templates'))
     self.loader = TemplateLoader(template_dirs)
     self.interactive = asbool(interactive)
     if self.interactive:
         self.http_repl = repl.WidgetReplApp(globals(), weakref.proxy(self))
         self.context = self.http_repl.repl.locals
     else:
         self.context = None
         self.http_repl = exc.HTTPForbidden("Interactive mode is disabled")
     if docs_dir:
         from paste.cascade import Cascade
         dest_dir = os.path.abspath(os.path.join(docs_dir))
         #log.info('Building docs...')
         #try:
         #    util.build_docs(docs_dir, dest_dir)
         #except Exception, e:
         #    log.warning('Skipping building docs: %s' % str(e))
         self.built_docs = dest_dir
         self.app = Cascade([self.docs_app, self.app])
     if asbool(full_stack):
         self.app = make_middleware(self.app, {
             'toscawidgets.framework.default_view': 'genshi',
             }, stack_registry = True)
     self._default_controllers = dict(demo=self.show_demo,
                                      index=self.show_index,
                                      template=self.show_template,
                                      parameters=self.show_parameters,
                                      source=self.show_source,
                                      demo_source=self.show_demo_source)
예제 #3
0
    def setup_tw(repl_app):
        # Stack TW's middleware configured with dummy default_view to signal
        # that a widget is being displayed so we can wrap and register its
        # output.
        conf = {
            'toscawidgets.framework.default_view': 'tw_repl',
            'toscawidgets.middleware.inject_resources': True
        }
        repl_app.app = make_middleware(repl_app.app, conf)

        # monkey-patch display and render to hijack output
        def wrap(f):
            if f.func_name == 'wrapper':
                return f

            def wrapper(self, value=None, **kw):
                if self.displays_on == 'tw_repl':
                    o = DeferredDisplay(self, value, **kw)
                    repl_app.displayed_widgets[o.id] = o
                else:
                    o = f(self, value, **kw)
                return o

            return wrapper

        Widget.display = wrap(Widget.display)
        Widget.render = wrap(Widget.render)
예제 #4
0
 def __init__(self,
              global_conf={},
              template_dirs=None,
              interactive=False,
              docs_dir=None,
              full_stack=True):
     if isinstance(template_dirs, basestring):
         template_dirs = template_dirs.split()
     template_dirs = template_dirs or []
     template_dirs.append(
         resource_filename('moksha.widgetbrowser', 'templates'))
     self.loader = TemplateLoader(template_dirs)
     self.interactive = asbool(interactive)
     if self.interactive:
         self.http_repl = repl.WidgetReplApp(globals(), weakref.proxy(self))
         self.context = self.http_repl.repl.locals
     else:
         self.context = None
         self.http_repl = exc.HTTPForbidden("Interactive mode is disabled")
     if docs_dir:
         from paste.cascade import Cascade
         dest_dir = os.path.abspath(os.path.join(docs_dir))
         #log.info('Building docs...')
         #try:
         #    util.build_docs(docs_dir, dest_dir)
         #except Exception, e:
         #    log.warning('Skipping building docs: %s' % str(e))
         self.built_docs = dest_dir
         self.app = Cascade([self.docs_app, self.app])
     if asbool(full_stack):
         self.app = make_middleware(
             self.app, {
                 'toscawidgets.framework.default_view': 'genshi',
             },
             stack_registry=True)
     self._default_controllers = dict(demo=self.show_demo,
                                      index=self.show_index,
                                      template=self.show_template,
                                      parameters=self.show_parameters,
                                      source=self.show_source,
                                      demo_source=self.show_demo_source)
예제 #5
0
파일: repl.py 프로젝트: lmacken/moksha
 def setup_tw(repl_app):
     # Stack TW's middleware configured with dummy default_view to signal
     # that a widget is being displayed so we can wrap and register its
     # output.
     conf = {'toscawidgets.framework.default_view' : 'tw_repl',
             'toscawidgets.middleware.inject_resources' : True}
     repl_app.app = make_middleware(repl_app.app, conf)
     # monkey-patch display and render to hijack output
     def wrap(f):
         if f.func_name == 'wrapper':
             return f
         def wrapper(self, value=None, **kw):
             if self.displays_on == 'tw_repl':
                 o = DeferredDisplay(self, value, **kw)
                 repl_app.displayed_widgets[o.id] = o
             else:
                 o = f(self, value, **kw)
             return o
         return wrapper
     Widget.display = wrap(Widget.display)
     Widget.render = wrap(Widget.render)
예제 #6
0
import os, index, upload, recordlist, details
from siteglobals import config
from tw.api import make_middleware

@route('/images/:filename')
def image_file(filename):
	return send_file( filename, root=os.getcwd()+'/images/' )

@route('/static/:filename')
def static_file(filename):
	return send_file( filename, root=os.getcwd()+'/static/' )

uploads = '/%s/' % config.get('site','uploads')
@route(uploads + ':filename')
def log_file(filename):
	return send_file( filename, root=os.getcwd()+ uploads )

@route('/favicon.ico')
def favi():
	return send_file( 'favicon.ico', root=os.getcwd()+'/images/' )

if __name__=="__main__":
	port = config.getint('site','port')
	is_debug = config.getboolean('site','debug')
	app = default_app()
	application = make_middleware(app, {
		'toscawidgets.framework.default_view': 'jinja2',
		'toscawidgets.middleware.inject_resources': True,
		}, stack_registry=True)
	debug(is_debug)
	run(app=application,server=PasteServer,host='localhost',port=port , reloader=is_debug)	
예제 #7
0
@route("/static/:filename")
def static_file(filename):
    return send_file(filename, root=os.getcwd() + "/static/")


uploads = "/%s/" % config.get("site", "uploads")


@route(uploads + ":filename")
def log_file(filename):
    return send_file(filename, root=os.getcwd() + uploads)


@route("/favicon.ico")
def favi():
    return send_file("favicon.ico", root=os.getcwd() + "/images/")


if __name__ == "__main__":
    port = config.getint("site", "port")
    host = config.get("site", "host")
    app = default_app()
    application = make_middleware(
        app,
        {"toscawidgets.framework.default_view": "jinja2", "toscawidgets.middleware.inject_resources": True},
        stack_registry=True,
    )
    debug(is_debug)
    run(app=application, server=PasteServer, host=host, port=port, reloader=False)
예제 #8
0
def make_app(global_conf, full_stack=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether or not this application provides a full WSGI stack (by
        default, meaning it handles its own exceptions and errors).
        Disable full_stack when this application is "managed" by
        another WSGI middleware.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    config = load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    #app = PylonsApp()
    app = PylonsApp(config=config)
    
    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
    from facebook.wsgi import create_pylons_facebook_middleware
    app = create_pylons_facebook_middleware(app, app_conf)
    
    from tw.api import make_middleware
    app = make_middleware(app, {
            'toscawidgets.framework' : 'pylons',
            'toscawidgets.framework.default_view' : 'mako',
            'toscawidgets.middleware.inject_resources' : True,
            })
    

    # Routing/Session/Cache Middleware
    app = RoutesMiddleware(app, config['routes.map'])
    app = SessionMiddleware(app, config)
    app = CacheMiddleware(app, config)
    
    if asbool(full_stack):
        # Handle Python exceptions
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])

        # Display error documents for 401, 403, 404 status codes (and
        # 500 when debug is disabled)
        if asbool(config['debug']):
            app = StatusCodeRedirect(app)
        else:
            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

    # Establish the Registry for this application
    app = RegistryManager(app)

    # Static files (If running in production, and Apache or another web 
    # server is handling this static content, remove the following 2 lines)
    static_app = StaticURLParser(config['pylons.paths']['static_files'])
    app = Cascade([static_app, app])
    app.config = config
    return app
예제 #9
0
from flask import request, session, make_response, app
from myojin.utils import redirect, redirect_to

module = submodule.SubModule(__name__, url_prefix="/crud")
from ..models import User, Memo
from flask import url_for

import tw.api as twa

from tw.forms.samples import AddUserForm

test_form = AddUserForm('mytest')

from tw.api import make_middleware

current_app.wsgi_app = make_middleware(current_app.wsgi_app,
                                       stack_registry=True)


# トップ画面。
@module.route('/')
@module.templated(
)  # @module.templated('index.html')と同様。templates/main/top/index.htmlが使用される。
def index():
    return dict(test_form=test_form)
    #return "hello"


test_json = """
{
  "page": "1",
  "records": "10",
예제 #10
0
def tw_middleware(app):
    from tw.api import make_middleware
    conf = {'toscawidgets.framework.default_view':'genshi',
            'toscawidgets.middleware.inject_resources': 'true'}
    return make_middleware(app, conf, stack_registry=True)