builder.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:memex-dossier-open 作者: dossier 项目源码 文件源码
def get_app(self):
        '''Eliminate the builder by producing a new Bottle application.

        This should be the final call in your method chain. It uses all
        of the built up options to create a new Bottle application.

        :rtype: :class:`bottle.Bottle`
        '''
        if self.config is None:
            # If the user never sets a config instance, then just create
            # a default.
            self.config = Config()
        if self.mount_prefix is None:
            self.mount_prefix = self.config.config.get('url_prefix')

        self.inject('config', lambda: self.config)
        self.inject('kvlclient', lambda: self.config.kvlclient)
        self.inject('store', lambda: self.config.store)
        self.inject('label_store', lambda: self.config.label_store)
        self.inject('tags', lambda: self.config.tags)
        self.inject('search_engines', lambda: self.search_engines)
        self.inject('filters', lambda: self.filters)
        self.inject('request', lambda: bottle.request)
        self.inject('response', lambda: bottle.response)

        # DEPRECATED. Remove. ---AG
        self.inject('visid_to_dbid', lambda: self.visid_to_dbid)
        self.inject('dbid_to_visid', lambda: self.dbid_to_visid)

        # Also DEPRECATED.
        self.inject('label_hooks', lambda: [])

        # Load routes defined in entry points.
        for extroute in self.config.config.get('external_routes', []):
            mod, fun_name = extroute.split(':')
            logger.info('Loading external route: %s', extroute)
            fun = getattr(__import__(mod, fromlist=[fun_name]), fun_name)
            self.add_routes(fun())

        # This adds the `json=True` feature on routes, which always coerces
        # the output to JSON. Bottle, by default, only permits dictionaries
        # to be JSON, which is the correct behavior. (Because returning JSON
        # arrays is a hazard.)
        #
        # So we should fix the routes and then remove this. ---AG
        self.app.install(JsonPlugin())

        # Throw away the app and return it. Because this is elimination!
        app = self.app
        self.app = None
        if self.mount_prefix is not None:
            root = bottle.Bottle()
            root.mount(self.mount_prefix, app)
            return root
        else:
            return app
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号