예제 #1
0
    def test_route_as_wsgiapp(self):
        from pyramid.wsgi import wsgiapp2

        config1 = self._makeConfig(autocommit=True)

        def view1(context, request):  # pragma: no cover
            return 'view1'

        config1.add_route('foo', '/a/b', request_method='POST')
        config1.add_view(view=view1, route_name='foo')

        config2 = self._makeConfig(autocommit=True)
        config2.add_route('foo', '/a/b', request_method='POST')
        config2.add_view(wsgiapp2(config1.make_wsgi_app()), route_name='foo')

        command = self._makeOne()
        L = []
        command.out = L.append
        command.bootstrap = dummy.DummyBootstrap(registry=config2.registry)
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = ['foo', '/a/b', '<wsgiapp>', 'POST']
        self.assertEqual(compare_to, expected)
예제 #2
0
    def test_route_as_wsgiapp(self):
        from pyramid.wsgi import wsgiapp2

        config1 = self._makeConfig(autocommit=True)
        def view1(context, request): return 'view1'
        config1.add_route('foo', '/a/b', request_method='POST')
        config1.add_view(view=view1, route_name='foo')

        config2 = self._makeConfig(autocommit=True)
        config2.add_route('foo', '/a/b', request_method='POST')
        config2.add_view(
            wsgiapp2(config1.make_wsgi_app()),
            route_name='foo',
        )

        command = self._makeOne()
        L = []
        command.out = L.append
        command.bootstrap = (dummy.DummyBootstrap(registry=config2.registry),)
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = [
            'foo', '/a/b',
            '<wsgiapp>',
            'POST',
        ]
        self.assertEqual(compare_to, expected)
예제 #3
0
def includeme(config):
    # Go parse the settings
    settings = parse_settings(config.registry.settings)

    # Update the config
    config.registry.settings.update(settings)

    # Create the application
    application = make_sub_application(config.registry.settings,
                                       config.registry)

    # Add the API route
    route_kw = {}

    if config.registry.settings['usingnamespace.management.domain'] != '':
        route_kw['is_management_domain'] = config.registry.settings[
            'usingnamespace.management.domain']

    config.add_route_predicate(
        'is_management_domain',
        config.maybe_dotted('.predicates.route.Management'))
    config.add_route(
        'usingnamespace.management',
        config.registry.settings['usingnamespace.management.route_path'] +
        '/*subpath', **route_kw)

    # Add the management view
    config.add_view(wsgiapp2(application),
                    route_name='usingnamespace.management')
예제 #4
0
def includeme(config):
    """ Activate the debug toolbar; usually called via
    ``config.include('pyramid_debugtoolbar')`` instead of being invoked
    directly. """
    introspection = getattr(config, 'introspection', True)
    # dont register any introspectables for Pyramid 1.3a9+
    config.introspection = False

    # Parse the settings
    settings = parse_settings(config.registry.settings)

    # Update the current registry with the new settings
    config.registry.settings.update(settings)

    config.include('pyramid_mako')
    config.add_mako_renderer('.dbtmako', settings_prefix='dbtmako.')
    config.add_tween('pyramid_debugtoolbar.toolbar_tween_factory')
    config.add_subscriber(
        'pyramid_debugtoolbar.toolbar.beforerender_subscriber',
        'pyramid.events.BeforeRender')
    config.add_directive('set_debugtoolbar_request_authorization',
                         set_request_authorization_callback)

    # Do the transform and update the settings dictionary
    settings.update(transform_settings(settings))

    # Create the new application using the updated settings
    application = make_application(settings, config.registry)
    config.add_route('debugtoolbar', '/_debug_toolbar/*subpath')
    config.add_view(wsgiapp2(application),
                    route_name='debugtoolbar',
                    permission=NO_PERMISSION_REQUIRED)
    config.add_static_view('/_debug_toolbar/static', STATIC_PATH, static=True)
    config.introspection = introspection
예제 #5
0
def includeme(config):
    """ Activate the debug toolbar; usually called via
    ``config.include('pyramid_debugtoolbar')`` instead of being invoked
    directly. """
    introspection = getattr(config, 'introspection', True)
    # dont register any introspectables for Pyramid 1.3a9+
    config.introspection = False

    # Parse the settings
    settings = parse_settings(config.registry.settings)

    # Update the current registry with the new settings
    config.registry.settings.update(settings)

    config.include('pyramid_mako')
    config.add_mako_renderer('.dbtmako', settings_prefix='dbtmako.')
    config.add_tween('pyramid_debugtoolbar.toolbar_tween_factory')
    config.add_subscriber(
        'pyramid_debugtoolbar.toolbar.beforerender_subscriber',
        'pyramid.events.BeforeRender')
    config.add_directive('set_debugtoolbar_request_authorization',
                         set_request_authorization_callback)

    # Do the transform and update the settings dictionary
    settings.update(transform_settings(settings))

    # Create the new application using the updated settings
    application = make_application(settings, config.registry)
    config.add_route('debugtoolbar', '/_debug_toolbar/*subpath')
    config.add_view(
        wsgiapp2(application),
        route_name='debugtoolbar',
        permission=NO_PERMISSION_REQUIRED)
    config.add_static_view('/_debug_toolbar/static', STATIC_PATH, static=True)
    config.introspection = introspection
예제 #6
0
def includeme(config):
    app = Flask('annotator')  # Create the annotator-store app
    app.register_blueprint(store.store)  # and register the store api.

    # Set up the models
    settings = config.get_settings()
    if 'es.host' in settings:
        app.config['ELASTICSEARCH_HOST'] = settings['es.host']
    if 'es.index' in settings:
        app.config['ELASTICSEARCH_INDEX'] = settings['es.index']
    es.init_app(app)
    with app.test_request_context():
        Annotation.create_all()
        Document.create_all()

    # Configure authentication and authorization
    app.config['AUTHZ_ON'] = True
    app.before_request(before_request)

    # Configure the API views -- version 1 is just an annotator.store proxy
    api_v1 = wsgiapp2(app)

    config.add_view(api_v1, route_name='api')

    if not config.registry.queryUtility(interfaces.IStoreClass):
        config.registry.registerUtility(Store, interfaces.IStoreClass)
예제 #7
0
파일: api.py 프로젝트: martinq/h
def includeme(config):
    """Include the annotator-store API backend.

    Example INI file:

        [app:h]
        api.key: 00000000-0000-0000-0000-000000000000

    """

    app = Flask('annotator')  # Create the annotator-store app
    app.register_blueprint(store.store)  # and register the store api.

    # Set up the models
    settings = config.get_settings()
    if 'es.host' in settings:
        app.config['ELASTICSEARCH_HOST'] = settings['es.host']
    if 'es.index' in settings:
        app.config['ELASTICSEARCH_INDEX'] = settings['es.index']
    es.init_app(app)
    with app.test_request_context():
        try:
            Annotation.create_all()
        except:
            Annotation.update_settings()
            Annotation.create_all()

    # Configure authentication (ours) and authorization (store)
    authenticator = auth.Authenticator(models.Consumer.get_by_key)

    def before_request():
        g.auth = authenticator
        g.authorize = authz.authorize

    app.before_request(before_request)

    # Configure the API view -- version 1 is just an annotator.store proxy
    config.add_view(wsgiapp2(app), context='h.resources.APIFactory', name='v1')
    config.add_view(wsgiapp2(app), context='h.resources.APIFactory',
                    name='current')

    # And pick up the token view
    config.scan(__name__)
예제 #8
0
파일: app.py 프로젝트: juli-so/h
def create_app(global_config, **settings):
    """Configure and add static routes and views. Return the WSGI app."""
    settings = get_settings(global_config, **settings)

    config = Configurator(settings=settings)

    config.set_root_factory('h.resources.create_root')

    config.add_subscriber('h.subscribers.add_renderer_globals',
                          'pyramid.events.BeforeRender')

    config.include('h.features')

    config.include('h.views')
    config.include('h.renderers')
    config.include('h.api_client')

    config.include('pyramid_jinja2')
    config.add_jinja2_renderer('.js')
    config.add_jinja2_renderer('.txt')
    config.add_jinja2_renderer('.html')
    config.add_jinja2_renderer('.xml')

    config.add_tween('h.tweens.csrf_tween_factory')

    if config.registry.feature('accounts'):
        config.set_authentication_policy(session_authn)
        config.set_authorization_policy(acl_authz)
        config.include('h.accounts')

    if config.registry.feature('api'):
        api_app = create_api(settings)
        api_view = wsgiapp2(api_app)
        config.add_view(api_view, name='api', decorator=strip_vhm)
        # Add the view again with the 'index' route name, otherwise it will
        # not take precedence over the index when a virtual root is in use.
        config.add_view(api_view, name='api', decorator=strip_vhm,
                        route_name='index')

    if config.registry.feature('claim'):
        config.include('h.claim')

    if config.registry.feature('queue'):
        config.include('h.queue')

    if config.registry.feature('streamer'):
        config.include('h.streamer')

    if config.registry.feature('notification'):
        config.include('h.notification')

    return config.make_wsgi_app()
예제 #9
0
def create_app(global_config, **settings):
    """Configure and add static routes and views. Return the WSGI app."""
    settings = get_settings(global_config, **settings)

    config = Configurator(settings=settings)

    config.set_root_factory('h.resources.create_root')

    config.add_subscriber('h.subscribers.add_renderer_globals',
                          'pyramid.events.BeforeRender')

    config.include('.features')
    config.include('.queue')
    config.include('.views')
    config.include('.renderers')
    config.include('.api_client')

    config.include('pyramid_jinja2')
    config.add_jinja2_renderer('.js')
    config.add_jinja2_renderer('.txt')
    config.add_jinja2_renderer('.html')
    config.add_jinja2_renderer('.xml')

    config.add_tween('h.tweens.csrf_tween_factory')

    if config.registry.feature('accounts'):
        config.set_authentication_policy(session_authn)
        config.set_authorization_policy(acl_authz)
        config.include('.accounts')

    if config.registry.feature('api'):
        api_app = create_api(settings)
        api_view = wsgiapp2(api_app)
        config.add_view(api_view, name='api', decorator=strip_vhm)
        # Add the view again with the 'index' route name, otherwise it will
        # not take precedence over the index when a virtual root is in use.
        config.add_view(api_view,
                        name='api',
                        decorator=strip_vhm,
                        route_name='index')

    if config.registry.feature('claim'):
        config.include('.claim')

    if config.registry.feature('streamer'):
        config.include('.streamer')

    if config.registry.feature('notification'):
        config.include('.notification')

    return config.make_wsgi_app()
예제 #10
0
파일: app.py 프로젝트: brittanystoroz/h
def create_app(global_config, **settings):
    """Configure and add static routes and views. Return the WSGI app."""
    settings = get_settings(global_config, **settings)

    config = Configurator(settings=settings)

    config.set_root_factory("h.resources.create_root")

    config.add_subscriber("h.subscribers.add_renderer_globals", "pyramid.events.BeforeRender")

    config.include("h.features")

    config.include("h.db")
    config.include("h.views")
    config.include("h.renderers")
    config.include("h.api_client")

    config.include("pyramid_jinja2")
    config.add_jinja2_renderer(".js")
    config.add_jinja2_renderer(".txt")
    config.add_jinja2_renderer(".html")
    config.add_jinja2_renderer(".xml")

    config.add_tween("h.tweens.csrf_tween_factory")

    if config.registry.feature("accounts"):
        config.set_authentication_policy(session_authn)
        config.set_authorization_policy(acl_authz)
        config.include("h.accounts")

    if config.registry.feature("api"):
        api_app = create_api(settings)
        api_view = wsgiapp2(api_app)
        config.add_view(api_view, name="api", decorator=strip_vhm)
        # Add the view again with the 'index' route name, otherwise it will
        # not take precedence over the index when a virtual root is in use.
        config.add_view(api_view, name="api", decorator=strip_vhm, route_name="index")

    if config.registry.feature("claim"):
        config.include("h.claim")

    if config.registry.feature("queue"):
        config.include("h.queue")

    if config.registry.feature("streamer"):
        config.include("h.streamer")

    if config.registry.feature("notification"):
        config.include("h.notification")

    return config.make_wsgi_app()
예제 #11
0
def includeme(config):
    """ Activate the switchboard; usually called via
    ``config.include('pyramid_switchboard')`` instead of being invoked
    directly. """
    settings = config.registry.settings
    # By setting nested to True, we're only looking for switchboard.* settings.
    configure(settings, nested=True)

    # Create the new application using the updated settings.
    switchboard = SwitchboardMiddleware(app)
    config.add_route('switchboard', '/_switchboard/*subpath')
    permission = settings.get('switchboard.permission', 'admin')
    config.add_view(wsgiapp2(switchboard), route_name='switchboard',
                    permission=permission)
예제 #12
0
파일: api.py 프로젝트: pablomarti/h
def includeme(config):
    """Include the annotator-store API backend.

    Example INI file:

        [app:h]
        consumer_key: primary_consumer
        consumer_secret: 00000000-0000-0000-0000-000000000000

    """

    settings = config.get_settings()

    if not settings.has_key('h.consumer_key'):
        raise KeyError('h.consumer_key')

    if not settings.has_key('h.consumer_secret'):
        raise KeyError('h.consumer_secret')

    # Create the annotator-store app
    app = Flask(__name__)
    app.register_blueprint(store.store)

    # Set up the models
    es.init_app(app)
    with app.test_request_context():
        try:
            Annotation.create_all()
        except:
            Annotation.update_settings()
            Annotation.create_all()

    # Configure authentication (ours) and authorization (store)
    authenticator = auth.Authenticator(consumer_fetcher)

    def before_request():
        g.auth = authenticator
        g.authorize = authz.authorize

    app.before_request(before_request)

    # Configure the API views
    config.add_view(wsgiapp2(app), route_name='api')
    config.add_view(token, route_name='token', permission='authenticated')
    config.add_view(users,
                    route_name='users',
                    request_method='GET',
                    permission='authenticated',
                    renderer='json')
예제 #13
0
파일: api.py 프로젝트: hyperstudio/h
def includeme(config):
    """Include the annotator-store API backend.

    Example INI file:

        [app:h]
        consumer_key: primary_consumer
        consumer_secret: 00000000-0000-0000-0000-000000000000

    """

    settings = config.get_settings()

    if not settings.has_key('h.consumer_key'):
        raise KeyError('h.consumer_key')

    if not settings.has_key('h.consumer_secret'):
        raise KeyError('h.consumer_secret')

    # Create the annotator-store app
    app = Flask(__name__)
    app.register_blueprint(store.store)

    # Set up the models
    es.init_app(app)
    with app.test_request_context():
        try:
            Annotation.create_all()
        except:
            Annotation.update_settings()
            Annotation.create_all()

    # Configure authentication (ours) and authorization (store)
    authenticator = auth.Authenticator(consumer_fetcher)
    def before_request():
        g.auth = authenticator
        g.authorize = authz.authorize
    app.before_request(before_request)

    # Configure the API views
    config.add_view(wsgiapp2(app), route_name='api')
    config.add_view(token, route_name='token', permission='authenticated')
    config.add_view(users, route_name='users', request_method='GET',
                    permission='authenticated',
                    renderer='json')
예제 #14
0
파일: gui.py 프로젝트: rastabrane/juju-gui
def gui(config):
    options.update(config.registry.settings)
    # We use regex separators for the prefix and file sections of the
    # jujugui.ui route to make sure we capture *everything* before the
    # juju-ui section and get the file path as one string rather than
    # several separated by "/".
    config.add_route('jujugui.ui', '/{prefix:.*}juju-ui/{file:.*}')
    config.add_route('jujugui.config', '/config.js')
    config.add_route('jujugui.version', '/version')
    config.add_route('jujugui.convoy', '/{cachebuster}/combo')
    js_files = _APP_DIR + '/static/gui/build'
    headers = [('Cache-Control', 'max-age=3600, public')]
    application = combo_app(js_files, additional_headers=headers)
    config.add_view(wsgiapp2(application), route_name='jujugui.convoy')
    config.add_route('jujugui.app', '/*state')
    config.include('pyramid_mako')
    config.add_renderer('prettyjson', JSON(indent=4))
    config.scan('jujugui.views')
예제 #15
0
파일: gui.py 프로젝트: codeyash/juju-gui
def gui(config):
    options.update(config.registry.settings)
    # We use regex separators for the prefix and file sections of the
    # jujugui.ui route to make sure we capture *everything* before the
    # static/gui/build/app section and get the file path as one string
    # rather than several separated by "/".
    config.add_route("jujugui.ui", "/{prefix:.*}static/gui/build/app/{file:.*}")
    config.add_route("jujugui.config", "/config.js")
    config.add_route("jujugui.version", "/version")
    config.add_route("jujugui.convoy", "/{cachebuster}/combo")
    js_files = _APP_DIR + "/static/gui/build"
    headers = [("Cache-Control", "max-age=3600, public")]
    application = combo_app(js_files, additional_headers=headers)
    config.add_view(wsgiapp2(application), route_name="jujugui.convoy")
    config.add_route("jujugui.app", "/*state")
    config.include("pyramid_mako")
    config.add_renderer("prettyjson", JSON(indent=4))
    config.scan("jujugui.views")
예제 #16
0
def main(global_config, **settings):
    """
    This function returns a Pyramid WSGI application.
    """
    
    # get secret stuff from files not in source control
    with open(settings['sqlalchemy.url_file']) as source:
        db_url = source.read().strip()
    with open(settings['session.secret_file']) as source:
        secret = source.read().strip()

    # set up config
    config = Configurator(
        settings=settings,
        authentication_policy=SessionAuthenticationPolicy(),
        authorization_policy=AuthorizationPolicy(),
        session_factory=SessionFactory(secret),
        )

    # set up database
    registerSession(db_url)

    # setup velruse
    velruse = make_velruse_app(settings['velruse_config_file'])
    velruse.__name__='velruse'
    config.registry.registerUtility(DirectAccess(velruse))
    config.add_view(wsgiapp2(velruse), name='velruse')

    # set up transactions
    config.include('pyramid_tm')

    # static views
    config.add_static_view('static','jobs:static')
    config.add_static_view('favicon.ico',
                           'jobs:static/favicon.ico')
    
    # scan for everything else
    config.scan()
    
    return config.make_wsgi_app()
예제 #17
0
def includeme(config):
    # Go parse the settings
    settings = parse_settings(config.registry.settings)

    # Update the config
    config.registry.settings.update(settings)
    
    # Create the application
    application = make_sub_application(config.registry.settings, config.registry)

    # Add the API route
    route_kw = {}

    if config.registry.settings['usingnamespace.api.domain'] != '':
        route_kw['is_api_domain'] = config.registry.settings['usingnamespace.api.domain']

    config.add_route_predicate('is_api_domain', config.maybe_dotted('.predicates.route.API'))
    config.add_route('usingnamespace.api',
            config.registry.settings['usingnamespace.api.route_path'] + '/*subpath',
            **route_kw)

    # Add the API view
    config.add_view(wsgiapp2(application), route_name='usingnamespace.api')
예제 #18
0
def includeme(config):
    """ Activate the debug toolbar; usually called via
    ``config.include('pyramid_debugtoolbar')`` instead of being invoked
    directly. """
    introspection = getattr(config, 'introspection', True)
    # dont register any introspectables for Pyramid 1.3a9+
    config.introspection = False
    settings = parse_settings(config.registry.settings)
    config.registry.settings.update(settings)
    config.include('pyramid_mako')
    config.add_mako_renderer('.dbtmako', settings_prefix='dbtmako.')
    config.add_tween('pyramid_debugtoolbar.toolbar_tween_factory')
    config.add_subscriber(
        'pyramid_debugtoolbar.toolbar.beforerender_subscriber',
        'pyramid.events.BeforeRender')
    config.add_directive('set_debugtoolbar_request_authorization',
                         set_request_authorization_callback)

    application = make_application(settings, config.registry)
    config.add_route('debugtoolbar', '/_debug_toolbar/*subpath')
    config.add_view(wsgiapp2(application), route_name='debugtoolbar')
    config.add_static_view('/_debug_toolbar/static', STATIC_PATH, static=True)
    config.introspection = introspection
예제 #19
0
파일: store.py 프로젝트: shepazu/h
def includeme(config):
    """Include the annotator-store API backend via http or route embedding.

    Example INI file:
    .. code-block:: ini
        [app:h]
        api.key: 00000000-0000-0000-0000-000000000000
        api.endpoint: https://example.com/api

    or use a relative path for the endpoint to embed the annotation store
    directly in the application.
    .. code-block:: ini
        [app:h]
        api.endpoint: /api

    The default is to embed the store as a route bound to "/api".
    """

    app = flask.Flask('annotator')  # Create the annotator-store app
    app.register_blueprint(store.store)  # and register the store api.
    settings = config.get_settings()

    if 'es.host' in settings:
        app.config['ELASTICSEARCH_HOST'] = settings['es.host']
    if 'es.index' in settings:
        app.config['ELASTICSEARCH_INDEX'] = settings['es.index']
    es.init_app(app)
    try:
        with app.test_request_context():
            Annotation.create_all()
            Document.create_all()
    except socket.error:
        raise Exception(
            "Can not access ElasticSearch at %s! Are you sure it's running?" %
            (app.config["ELASTICSEARCH_HOST"], ))
    except:
        with app.test_request_context():
            Annotation.update_settings()
            Annotation.create_all()
            Document.create_all()

    # Configure authentication and authorization
    app.config['AUTHZ_ON'] = True
    app.before_request(before_request)
    app.after_request(after_request)

    # Configure the API routes
    api_config = {'static': True}
    api_endpoint = config.registry.settings.get('api.endpoint', None)
    api_url = config.registry.settings.get('api.url', api_endpoint)

    if api_endpoint is not None:
        api_path = api_endpoint.rstrip('/')
        api_pattern = '/'.join([api_path, '*subpath'])

        # Configure the API views -- version 1 is just an annotator.store proxy
        api_v1 = wsgiapp2(app)

        config.add_route('api_real', api_pattern)
        config.add_view(api_v1, route_name='api_real')
        config.add_view(api_v1, name='api_virtual')

    if api_url is not None:
        api_url = api_url.strip('/')
        if urlparse.urlparse(api_url).scheme:

            def set_app_url(request, elements, kw):
                kw.setdefault('_app_url', api_url)
                return (elements, kw)

            api_config['pregenerator'] = set_app_url
            config.add_route('api', '/*subpath', **api_config)
        else:
            config.add_route('api', api_url + '/*subpath', **api_config)

    if not config.registry.queryUtility(interfaces.IStoreClass):
        config.registry.registerUtility(Store, interfaces.IStoreClass)
예제 #20
0
파일: store.py 프로젝트: mrienstra/h
def includeme(config):
    """Include the annotator-store API backend via http or route embedding.

    Example INI file:
    .. code-block:: ini
        [app:h]
        api.key: 00000000-0000-0000-0000-000000000000
        api.endpoint: https://example.com/api

    or use a relative path for the endpoint to embed the annotation store
    directly in the application.
    .. code-block:: ini
        [app:h]
        api.endpoint: /api

    The default is to embed the store as a route bound to "/api".
    """

    app = flask.Flask('annotator')  # Create the annotator-store app
    app.register_blueprint(store.store)  # and register the store api.
    settings = config.get_settings()

    if 'es.host' in settings:
        app.config['ELASTICSEARCH_HOST'] = settings['es.host']
    if 'es.index' in settings:
        app.config['ELASTICSEARCH_INDEX'] = settings['es.index']
    es.init_app(app)
    try:
        with app.test_request_context():
            Annotation.create_all()
            Document.create_all()
    except socket.error:
        raise Exception(
            "Can not access ElasticSearch at %s! Are you sure it's running?" %
            (app.config["ELASTICSEARCH_HOST"],)
        )

    # Configure authentication and authorization
    app.config['AUTHZ_ON'] = True
    app.before_request(before_request)
    app.after_request(after_request)

    # Configure the API routes
    api_config = {'static': True}
    api_endpoint = config.registry.settings.get('api.endpoint', None)
    api_url = config.registry.settings.get('api.url', api_endpoint)

    if api_endpoint is not None:
        api_path = api_endpoint.rstrip('/')
        api_pattern = '/'.join([api_path, '*subpath'])

        # Configure the API views -- version 1 is just an annotator.store proxy
        api_v1 = wsgiapp2(app)

        config.add_route('api_real', api_pattern)
        config.add_view(api_v1, route_name='api_real')
        config.add_view(api_v1, name='api_virtual')

    if api_url is not None:
        api_url = api_url.strip('/')
        if urlparse.urlparse(api_url).scheme:
            def set_app_url(request, elements, kw):
                kw.setdefault('_app_url', api_url)
                return (elements, kw)
            api_config['pregenerator'] = set_app_url
            config.add_route('api', '/*subpath', **api_config)
        else:
            config.add_route('api', api_url + '/*subpath', **api_config)

    if not config.registry.queryUtility(interfaces.IStoreClass):
        config.registry.registerUtility(Store, interfaces.IStoreClass)
예제 #21
0
"""

def appinclude(config):
    config.include('pyramid_party')
    config.add_subscriber(party_invite, PartylineInvitation)
    config.add_route('home', '')
    config.add_view(view, route_name='home')

def app():
    config = Configurator()
    config.include(appinclude)
    return config.make_wsgi_app()

if __name__ == '__main__':
    import os
    from werkzeug.serving import run_simple
    from wsgi_party import WSGIParty
    config = Configurator()
    config.include(appinclude)
    config.add_route('one', '/one*subpath')
    config.add_route('two', '/two*subpath')
    config.add_view(wsgiapp2(app()), route_name='one')
    config.add_view(wsgiapp2(app()), route_name='two')
    base = config.make_wsgi_app()
    party = WSGIParty(
        base, ('/__invite__', '/one/__invite__', '/two/__invite__')
        )
    # Bind to PORT if defined, otherwise default to 5000.
    port = int(os.environ.get('PORT', 5000))
    run_simple('0.0.0.0', port, party, use_reloader=True)
예제 #22
0
    def _callFUT(self, app):
        from pyramid.wsgi import wsgiapp2

        return wsgiapp2(app)
예제 #23
0
 def _callFUT(self, app):
     from pyramid.wsgi import wsgiapp2
     return wsgiapp2(app)
예제 #24
0
def create_view_callable(mapproxy_config):
    app = MapProxyApp(mapproxy_config.configured_services(),
                      mapproxy_config.base_config)
    return wsgiapp2(app.__call__)
예제 #25
0
파일: api.py 프로젝트: nlholdem/h
def includeme(config):
    """Include the annotator-store API backend via http or route embedding.

    Example INI file:
    .. code-block:: ini
        [app:h]
        api.key: 00000000-0000-0000-0000-000000000000
        api.endpoint: https://example.com/api

    or use a relative path for the endpoint to embed the annotation store
    directly in the application.
    .. code-block:: ini
        [app:h]
        api.endpoint: /api

    The default is to embed the store as a route bound to "/api".
    """
    registry = config.registry
    settings = registry.settings

    config.include('pyramid_oauthlib')
    config.add_token_type(Token)

    # Configure the token policy
    authn_debug = config.registry.settings.get('debug_authorization')
    authn_policy = OAuthAuthenticationPolicy(
        environ_key='HTTP_X_ANNOTATOR_AUTH_TOKEN',
        debug=authn_debug,
    )
    config.set_authentication_policy(authn_policy)

    # Configure the token view
    config.add_route('api_token', '/api/token')
    config.add_view(token, renderer='string', route_name='api_token')

    # Configure the annotator-store flask app
    app = store_from_settings(settings)

    # Maybe initialize the models
    if asbool(settings.get('basemodel.should_drop_all', False)):
        delete_db(app)
    if asbool(settings.get('basemodel.should_create_all', True)):
        create_db(app)

    # Configure authentication and authorization
    app.config['AUTHZ_ON'] = True
    app.before_request(before_request)
    app.after_request(after_request)

    # Configure the API routes
    api_endpoint = settings.get('api.endpoint', '/api').rstrip('/')
    api_pattern = '/'.join([api_endpoint, '*subpath'])
    config.add_route('api_real', api_pattern)

    api_url = settings.get('api.url', api_endpoint)
    config.add_route('api', api_url + '/*subpath')

    # Configure the API views -- version 1 is just an annotator.store proxy
    api_v1 = wsgiapp2(app)
    config.add_view(api_v1, route_name='api_real')
    config.add_view(api_v1, name='api_virtual')

    if not registry.queryUtility(interfaces.IStoreClass):
        registry.registerUtility(Store, interfaces.IStoreClass)
예제 #26
0
def includeme(config):
    """Include the annotator-store API backend via http or route embedding.

    Example INI file:
    .. code-block:: ini
        [app:h]
        api.key: 00000000-0000-0000-0000-000000000000
        api.endpoint: https://example.com/api

    or use a relative path for the endpoint to embed the annotation store
    directly in the application.
    .. code-block:: ini
        [app:h]
        api.endpoint: /api

    The default is to embed the store as a route bound to "/api".
    """
    registry = config.registry
    settings = registry.settings

    # Configure the token policy
    authn_debug = settings.get('pyramid.debug_authorization') \
        or settings.get('debug_authorization')
    authn_policy = LocalAuthenticationPolicy(
        environ_key='HTTP_X_ANNOTATOR_AUTH_TOKEN',
        debug=authn_debug,
    )
    config.set_authentication_policy(authn_policy)

    # Configure the token view
    config.add_route('api_token', '/api/token')
    config.add_view(token, renderer='string', route_name='api_token')

    # Configure the annotator-store flask app
    app = store_from_settings(settings)

    # Maybe initialize the models
    if asbool(settings.get('basemodel.should_drop_all', False)):
        delete_db(app)
    if asbool(settings.get('basemodel.should_create_all', True)):
        create_db(app)

    # Configure authentication and authorization
    app.config['AUTHZ_ON'] = True
    app.before_request(before_request)
    app.after_request(after_request)

    # Configure the API routes
    api_endpoint = settings.get('api.endpoint', '/api').rstrip('/')
    api_pattern = '/'.join([api_endpoint, '*subpath'])
    config.add_route('api_real', api_pattern)

    api_url = settings.get('api.url', api_endpoint)
    config.add_route('api', api_url + '/*subpath')

    # Configure the API views -- version 1 is just an annotator.store proxy
    api_v1 = wsgiapp2(app)
    config.add_view(api_v1, route_name='api_real')
    config.add_view(api_v1, name='api_virtual')

    if not registry.queryUtility(interfaces.IStoreClass):
        registry.registerUtility(Store, interfaces.IStoreClass)
예제 #27
0
def build_routes(config):
    """Add any routes to the config"""

    config.add_route("home", "/")
    config.add_route("dashboard", "/dashboard")

    # Add routes for the combo loader to match up to static file requests.
    config.add_route('convoy', '/combo')

    JS_FILES = config.get_settings()['app_root'] + '/bookie/static/js/build'
    application = combo_app(JS_FILES)
    config.add_view(
        wsgiapp2(application),
        route_name='convoy')

    # auth routes
    config.add_route("login", "login")
    config.add_route("logout", "logout")
    config.add_route("reset", "{username}/reset/{reset_key}")
    config.add_route("signup", "signup")
    config.add_route("signup_process", "signup_process")

    # celery routes
    config.add_route("celery_hourly_stats", "jobhourly")

    # bmark routes
    config.add_route("bmark_recent", "recent")
    config.add_route("bmark_recent_tags", "recent/*tags")

    config.add_route("bmark_recent_rss", "rss")
    config.add_route("bmark_recent_rss_tags", "rss/*tags")

    config.add_route("bmark_readable", "bmark/readable/{hash_id}")

    # user based bmark routes
    config.add_route("user_bmark_recent", "{username}/recent")
    config.add_route("user_bmark_recent_tags", "{username}/recent/*tags")

    config.add_route("user_bmark_rss", "{username}/rss")
    config.add_route("user_bmark_rss_tags", "{username}/rss/*tags")

    config.add_route("user_bmark_edit", "{username}/edit/{hash_id}")
    config.add_route("user_bmark_edit_error",
                     "{username}/edit_error/{hash_id}")
    config.add_route("user_bmark_new", "{username}/new")
    config.add_route("user_bmark_new_error", "{username}/new_error")

    # config.add_route("bmark_delete", "/bmark/delete")
    # config.add_route("bmark_confirm_delete", "/bmark/confirm/delete/{bid}")

    # tag related routes
    config.add_route("tag_list", "tags")
    config.add_route("tag_bmarks", "tags/*tags")

    # user tag related
    config.add_route("user_tag_list", "{username}/tags")
    config.add_route("user_tag_bmarks", "{username}/tags/*tags")

    config.add_route("user_import", "{username}/import")
    config.add_route("search", "search")
    config.add_route("user_search", "{username}/search")

    config.add_route("search_results", "results")
    config.add_route("user_search_results", "{username}/results")

    # matches based on the header
    # HTTP_X_REQUESTED_WITH
    # ajax versions are used in the mobile search interface
    config.add_route("search_results_ajax", "results/*terms", xhr=True)
    config.add_route("search_results_rest", "results/*terms")
    config.add_route("user_search_results_ajax",
                     "{username}/results*terms",
                     xhr=True)
    config.add_route("user_search_results_rest", "{username}/results*terms")

    config.add_route("redirect", "redirect/{hash_id}")
    config.add_route("user_redirect", "{username}/redirect/{hash_id}")

    config.add_route("user_account", "{username}/account")
    config.add_route("user_export", "{username}/export")

    #
    # NEW API
    #

    # ping checks
    config.add_route('api_ping',
                     '/api/v1/{username}/ping',
                     request_method='GET')
    config.add_route('api_ping_missing_user',
                     '/api/v1/ping',
                     request_method='GET')
    config.add_route('api_ping_missing_api',
                     '/ping',
                     request_method='GET')

    # auth related
    config.add_route("api_user_account",
                     "/api/v1/{username}/account",
                     request_method="GET")
    config.add_route("api_user_account_update",
                     "/api/v1/{username}/account",
                     request_method="POST")
    config.add_route("api_user_api_key",
                     "/api/v1/{username}/api_key")
    config.add_route("api_user_reset_password",
                     "/api/v1/{username}/password",
                     request_method="POST")

    config.add_route("api_user_suspend_remove",
                     "api/v1/suspend",
                     request_method="DELETE")
    config.add_route("api_user_suspend",
                     "api/v1/suspend",
                     request_method="POST")
    config.add_route("api_user_invite",
                     "api/v1/{username}/invite",
                     request_method="POST")

    # many bookmark api calls
    config.add_route("api_bmarks_export", "api/v1/{username}/bmarks/export")

    # we have to search before we hit the bmarks keys so that it doesn't think
    # the tag is "search"
    config.add_route("api_bmark_search", "api/v1/bmarks/search/*terms")
    config.add_route("api_bmark_search_user",
                     "/api/v1/{username}/bmarks/search/*terms")

    config.add_route('api_bmarks', 'api/v1/bmarks')
    config.add_route('api_bmarks_tags', 'api/v1/bmarks/*tags')
    config.add_route('api_bmarks_user', 'api/v1/{username}/bmarks')
    config.add_route('api_bmarks_user_tags', 'api/v1/{username}/bmarks/*tags')

    config.add_route('api_bmarks_popular', 'api/v1/bmarks/popular')
    config.add_route('api_bmarks_popular_user',
                     'api/v1/{username}/bmarks/popular')

    # user bookmark api calls
    config.add_route("api_bmark_add",
                     "/api/v1/{username}/bmark",
                     request_method="POST")
    config.add_route("api_bmark_update",
                     "/api/v1/{username}/bmark/{hash_id}",
                     request_method="POST")
    config.add_route("api_extension_sync", "/api/v1/{username}/extension/sync")

    config.add_route("api_bmark_hash",
                     "/api/v1/{username}/bmark/{hash_id}",
                     request_method="GET")
    config.add_route("api_bmark_remove",
                     "/api/v1/{username}/bmark/{hash_id}",
                     request_method="DELETE")

    config.add_route("api_tag_complete_user",
                     "/api/v1/{username}/tags/complete")
    config.add_route("api_tag_complete",
                     "/api/v1/tags/complete")

    # admin api calls
    config.add_route("api_admin_readable_todo", "/api/v1/a/readable/todo")
    config.add_route(
        "api_admin_readable_reindex",
        "/api/v1/a/readable/reindex")
    config.add_route(
        "api_admin_accounts_inactive",
        "/api/v1/a/accounts/inactive")
    config.add_route(
        "api_admin_accounts_invites_add",
        "/api/v1/a/accounts/invites/{username}/{count}",
        request_method="POST")
    config.add_route(
        "api_admin_accounts_invites",
        "/api/v1/a/accounts/invites",
        request_method="GET")
    config.add_route(
        "api_admin_imports_list",
        "/api/v1/a/imports/list",
        request_method="GET")
    config.add_route(
        "api_admin_imports_reset",
        "/api/v1/a/imports/reset/{id}",
        request_method="POST")

    config.add_route(
        "api_admin_users_list",
        "/api/v1/a/users/list",
        request_method="GET")
    config.add_route(
        "api_admin_new_user",
        "/api/v1/a/users/add",
        request_method="POST")
    config.add_route(
        "api_admin_del_user",
        "/api/v1/a/users/delete/{username}",
        request_method="DELETE")
    config.add_route(
        "api_admin_bmark_remove",
        "/api/v1/a/bmark/{username}/{hash_id}",
        request_method="DELETE")

    config.add_route(
        "api_admin_applog",
        "/api/v1/a/applog/list",
        request_method="GET")

    # these are single word matching, they must be after /recent /popular etc
    config.add_route("user_home", "{username}")

    return config