python类get_app()的实例源码

i18n.py 文件源码 项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_translations(self, locale):
        """Returns a translation catalog for a locale.

        :param locale:
            A locale code.
        :returns:
            A ``babel.support.Translations`` instance, or
            ``gettext.NullTranslations`` if none was found.
        """
        trans = self.translations.get(locale)
        if not trans:
            locales = (locale, self.default_locale)
            trans = self.load_translations(self.translations_path, locales,
                                           self.domains)
            if not webapp2.get_app().debug:
                self.translations[locale] = trans

        return trans
i18n.py 文件源码 项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_store(factory=I18nStore, key=_store_registry_key, app=None):
    """Returns an instance of :class:`I18nStore` from the app registry.

    It'll try to get it from the current app registry, and if it is not
    registered it'll be instantiated and registered. A second call to this
    function will return the same instance.

    :param factory:
        The callable used to build and register the instance if it is not yet
        registered. The default is the class :class:`I18nStore` itself.
    :param key:
        The key used to store the instance in the registry. A default is used
        if it is not set.
    :param app:
        A :class:`webapp2.WSGIApplication` instance used to store the instance.
        The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    store = app.registry.get(key)
    if not store:
        store = app.registry[key] = factory(app)

    return store
jinja2.py 文件源码 项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def get_jinja2(factory=Jinja2, key=_registry_key, app=None):
    """Returns an instance of :class:`Jinja2` from the app registry.

    It'll try to get it from the current app registry, and if it is not
    registered it'll be instantiated and registered. A second call to this
    function will return the same instance.

    :param factory:
        The callable used to build and register the instance if it is not yet
        registered. The default is the class :class:`Jinja2` itself.
    :param key:
        The key used to store the instance in the registry. A default is used
        if it is not set.
    :param app:
        A :class:`webapp2.WSGIApplication` instance used to store the instance.
        The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    jinja2 = app.registry.get(key)
    if not jinja2:
        jinja2 = app.registry[key] = factory(app)

    return jinja2
mako.py 文件源码 项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_mako(factory=Mako, key=_registry_key, app=None):
    """Returns an instance of :class:`Mako` from the app registry.

    It'll try to get it from the current app registry, and if it is not
    registered it'll be instantiated and registered. A second call to this
    function will return the same instance.

    :param factory:
        The callable used to build and register the instance if it is not yet
        registered. The default is the class :class:`Mako` itself.
    :param key:
        The key used to store the instance in the registry. A default is used
        if it is not set.
    :param app:
        A :class:`webapp2.WSGIApplication` instance used to store the instance.
        The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    mako = app.registry.get(key)
    if not mako:
        mako = app.registry[key] = factory(app)

    return mako
i18n.py 文件源码 项目:blockhooks 作者: EthereumWebhooks 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_translations(self, locale):
        """Returns a translation catalog for a locale.

        :param locale:
            A locale code.
        :returns:
            A ``babel.support.Translations`` instance, or
            ``gettext.NullTranslations`` if none was found.
        """
        trans = self.translations.get(locale)
        if not trans:
            locales = (locale, self.default_locale)
            trans = self.load_translations(self.translations_path, locales,
                                           self.domains)
            if not webapp2.get_app().debug:
                self.translations[locale] = trans

        return trans
i18n.py 文件源码 项目:blockhooks 作者: EthereumWebhooks 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_store(factory=I18nStore, key=_store_registry_key, app=None):
    """Returns an instance of :class:`I18nStore` from the app registry.

    It'll try to get it from the current app registry, and if it is not
    registered it'll be instantiated and registered. A second call to this
    function will return the same instance.

    :param factory:
        The callable used to build and register the instance if it is not yet
        registered. The default is the class :class:`I18nStore` itself.
    :param key:
        The key used to store the instance in the registry. A default is used
        if it is not set.
    :param app:
        A :class:`webapp2.WSGIApplication` instance used to store the instance.
        The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    store = app.registry.get(key)
    if not store:
        store = app.registry[key] = factory(app)

    return store
jinja2.py 文件源码 项目:blockhooks 作者: EthereumWebhooks 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def get_jinja2(factory=Jinja2, key=_registry_key, app=None):
    """Returns an instance of :class:`Jinja2` from the app registry.

    It'll try to get it from the current app registry, and if it is not
    registered it'll be instantiated and registered. A second call to this
    function will return the same instance.

    :param factory:
        The callable used to build and register the instance if it is not yet
        registered. The default is the class :class:`Jinja2` itself.
    :param key:
        The key used to store the instance in the registry. A default is used
        if it is not set.
    :param app:
        A :class:`webapp2.WSGIApplication` instance used to store the instance.
        The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    jinja2 = app.registry.get(key)
    if not jinja2:
        jinja2 = app.registry[key] = factory(app)

    return jinja2
mako.py 文件源码 项目:blockhooks 作者: EthereumWebhooks 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_mako(factory=Mako, key=_registry_key, app=None):
    """Returns an instance of :class:`Mako` from the app registry.

    It'll try to get it from the current app registry, and if it is not
    registered it'll be instantiated and registered. A second call to this
    function will return the same instance.

    :param factory:
        The callable used to build and register the instance if it is not yet
        registered. The default is the class :class:`Mako` itself.
    :param key:
        The key used to store the instance in the registry. A default is used
        if it is not set.
    :param app:
        A :class:`webapp2.WSGIApplication` instance used to store the instance.
        The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    mako = app.registry.get(key)
    if not mako:
        mako = app.registry[key] = factory(app)

    return mako
idtokenauth.py 文件源码 项目:sndlatr 作者: Schibum 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def get_current_user():
    """  GAE compatibility method. """
    request = webapp2.get_request()
    app = webapp2.get_app()
    audience = app.config.get('idtoken_audience')
    if not audience:
        raise Exception('idtoken_audience not configured')
    token = request.headers.get('x-w69b-idtoken')
    return _user_from_token(token, audience)
zones.py 文件源码 项目:professional-services 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def registry(self):
        """Return the application registry, or a global cache."""
        if webapp2.get_app().registry:
            return webapp2.get_app().registry
        else:
            return AppCachedProperty.GLOBAL_CACHE
api.py 文件源码 项目:professional-services 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __get__(self, instance, instance_type):
        """Construct the API client."""
        if instance is None:
            return self

        thread_local = None
        try:
            app = webapp2.get_app()
            # Python Google API clients aren't threadsafe as they use httplib2
            # which isn't threadsafe.
            thread_local = app.registry.get(self)
            if thread_local is None:
                thread_local = threading.local()
                app.registry[self] = thread_local
        except AssertionError:
            # When not in a request context, use class thread local.
            thread_local = ThreadsafeClientLocal._class_thread_local

        cached_client = getattr(thread_local, 'api', None)
        if cached_client is None:
            credentials = client.GoogleCredentials.get_application_default()
            if credentials.create_scoped_required():
                credentials = credentials.create_scoped(
                    'https://www.googleapis.com/auth/cloud-platform')
            cached_client = discovery.build(
                self.service,
                self.version,
                http=credentials.authorize(self.http),
                cache_discovery=self.cache_discovery)
            thread_local.api = cached_client
        return cached_client
i18n.py 文件源码 项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def set_store(store, key=_store_registry_key, app=None):
    """Sets an instance of :class:`I18nStore` in the app registry.

    :param store:
        An instance of :class:`I18nStore`.
    :param key:
        The key used to retrieve the instance from the registry. A default
        is used if it is not set.
    :param request:
        A :class:`webapp2.WSGIApplication` instance used to retrieve the
        instance. The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    app.registry[key] = store
jinja2.py 文件源码 项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def set_jinja2(jinja2, key=_registry_key, app=None):
    """Sets an instance of :class:`Jinja2` in the app registry.

    :param store:
        An instance of :class:`Jinja2`.
    :param key:
        The key used to retrieve the instance from the registry. A default
        is used if it is not set.
    :param request:
        A :class:`webapp2.WSGIApplication` instance used to retrieve the
        instance. The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    app.registry[key] = jinja2
auth.py 文件源码 项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def set_store(store, key=_store_registry_key, app=None):
    """Sets an instance of :class:`AuthStore` in the app registry.

    :param store:
        An instance of :class:`AuthStore`.
    :param key:
        The key used to retrieve the instance from the registry. A default
        is used if it is not set.
    :param request:
        A :class:`webapp2.WSGIApplication` instance used to retrieve the
        instance. The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    app.registry[key] = store
mako.py 文件源码 项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def set_mako(mako, key=_registry_key, app=None):
    """Sets an instance of :class:`Mako` in the app registry.

    :param store:
        An instance of :class:`Mako`.
    :param key:
        The key used to retrieve the instance from the registry. A default
        is used if it is not set.
    :param request:
        A :class:`webapp2.WSGIApplication` instance used to retrieve the
        instance. The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    app.registry[key] = mako
i18n.py 文件源码 项目:blockhooks 作者: EthereumWebhooks 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def set_store(store, key=_store_registry_key, app=None):
    """Sets an instance of :class:`I18nStore` in the app registry.

    :param store:
        An instance of :class:`I18nStore`.
    :param key:
        The key used to retrieve the instance from the registry. A default
        is used if it is not set.
    :param request:
        A :class:`webapp2.WSGIApplication` instance used to retrieve the
        instance. The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    app.registry[key] = store
jinja2.py 文件源码 项目:blockhooks 作者: EthereumWebhooks 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def set_jinja2(jinja2, key=_registry_key, app=None):
    """Sets an instance of :class:`Jinja2` in the app registry.

    :param store:
        An instance of :class:`Jinja2`.
    :param key:
        The key used to retrieve the instance from the registry. A default
        is used if it is not set.
    :param request:
        A :class:`webapp2.WSGIApplication` instance used to retrieve the
        instance. The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    app.registry[key] = jinja2
auth.py 文件源码 项目:blockhooks 作者: EthereumWebhooks 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def set_store(store, key=_store_registry_key, app=None):
    """Sets an instance of :class:`AuthStore` in the app registry.

    :param store:
        An instance of :class:`AuthStore`.
    :param key:
        The key used to retrieve the instance from the registry. A default
        is used if it is not set.
    :param request:
        A :class:`webapp2.WSGIApplication` instance used to retrieve the
        instance. The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    app.registry[key] = store
mako.py 文件源码 项目:blockhooks 作者: EthereumWebhooks 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def set_mako(mako, key=_registry_key, app=None):
    """Sets an instance of :class:`Mako` in the app registry.

    :param store:
        An instance of :class:`Mako`.
    :param key:
        The key used to retrieve the instance from the registry. A default
        is used if it is not set.
    :param request:
        A :class:`webapp2.WSGIApplication` instance used to retrieve the
        instance. The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    app.registry[key] = mako
handlerbase.py 文件源码 项目:enkiWS 作者: juliettef 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def validate_password( self, password ):
        result = enki.libutil.ENKILIB_OK
        if password == '':
            result = self.ERROR_PASSWORD_BLANK
        elif len(password) < webapp2.get_app().config.get( 'enki' ).get( 'user' ).get( 'PASSWORD_LENGTH_MIN' ):
            result = self.ERROR_PASSWORD_TOO_SHORT
        return result


问题


面经


文章

微信
公众号

扫码关注公众号