コード例 #1
0
ファイル: app.py プロジェクト: dave-shawley/imbi
def make_application(**settings) -> app.Application:
    """Create the web application instance after building the settings

    :param dict settings: kwarg settings passed in for the application

    """
    _set_default_settings(settings)
    if settings['environment'] in ('development', 'testing'):
        os.environ.pop('SENTRY_DSN', None)
        settings.setdefault('debug', True)

    urls = [
        web.url(r'/static/(.*)', web.StaticFileHandler,
                {'path': settings['static_path']})
    ]
    urls += endpoints.URLS

    settings['permissions'] = _get_permissions(urls)

    application = Application(
        urls,
        log_function=correlation.mixins.correlation_id_logger,
        **settings)

    # Content handling setup
    content.install(application, 'application/json', 'utf-8')
    content.add_transcoder(application, transcoders.JSONTranscoder())
    content.add_transcoder(
        application, transcoders.JSONTranscoder('application/json-patch+json'))
    content.add_transcoder(application, transcoders.MsgPackTranscoder())
    content.add_transcoder(application, html.HTMLTranscoder())

    # Instrument which libraries to include in sentry reports
    """
    sentry.install(
        app,
        include_paths=[
            'aiopg',
            'aioredis',
            'arrow',
            'imbi',
            'jsonpatch',
            'jsonschema',
            'sprockets.http',
            'sprockets.handlers.status',
            'sprockets.mixins.correlation',
            'sprockets.mixins.mediatype',
            'sprockets.mixins.metrics',
            'sprockets_postgres'],
        release=__version__,
        tags={'environment': settings['environment']})
    """
    return application
コード例 #2
0
def make_application(**settings):
    application = web.Application([web.url(r'/', SimpleHandler)], **settings)
    content.set_default_content_type(application,
                                     'application/json',
                                     encoding='utf-8')
    content.add_transcoder(application, transcoders.MsgPackTranscoder())
    content.add_transcoder(application, transcoders.JSONTranscoder())
    return application
コード例 #3
0
 def __init__(self, simplify_error_response=True):
     self._exceptions = []
     self._finish = None
     self._json = transcoders.JSONTranscoder()
     self._msgpack = transcoders.MsgPackTranscoder()
     self._responses = []
     self._start = time.time()
     self._simplify_error_response = simplify_error_response
コード例 #4
0
 def test_that_content_type_suffix_is_handled(self):
     content.add_transcoder(self._app, transcoders.JSONTranscoder(),
                            'application/vendor+json')
     body = {'hello': 'world'}
     response = self.fetch(
         '/',
         method='POST',
         body=json.dumps(body),
         headers={'Content-Type': 'application/vendor+json'})
     self.assertEqual(response.code, 200)
     self.assertEqual(json.loads(response.body.decode()), body)
コード例 #5
0
 def setUp(self):
     super(JSONTranscoderTests, self).setUp()
     self.transcoder = transcoders.JSONTranscoder()
コード例 #6
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.__hcm_json = transcoders.JSONTranscoder()
     self.__hcm_msgpack = transcoders.MsgPackTranscoder()
     self.simplify_error_response = True