当前位置: 首页>>代码示例>>Python>>正文


Python flask.has_app_context方法代码示例

本文整理汇总了Python中flask.has_app_context方法的典型用法代码示例。如果您正苦于以下问题:Python flask.has_app_context方法的具体用法?Python flask.has_app_context怎么用?Python flask.has_app_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask的用法示例。


在下文中一共展示了flask.has_app_context方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_statsd_client

# 需要导入模块: import flask [as 别名]
# 或者: from flask import has_app_context [as 别名]
def _get_statsd_client(*, prefix: str) -> StatsClient:
    """
    Object pool method that reuse already created StatsClient based on prefix
    :param prefix:
    :return:
    """
    if not has_app_context() or not current_app.config[config.IS_STATSD_ON]:
        return None
    else:
        if prefix not in __STATSD_POOL:
            with __STATSD_POOL_LOCK:
                if prefix not in __STATSD_POOL:
                    LOGGER.info('Instantiate StatsClient with prefix {}'.format(prefix))
                    statsd_client = StatsClient(prefix=prefix)
                    __STATSD_POOL[prefix] = statsd_client
                    return statsd_client

        if LOGGER.isEnabledFor(logging.DEBUG):
            LOGGER.debug('Reuse StatsClient with prefix {}'.format(prefix))
        return __STATSD_POOL[prefix] 
开发者ID:lyft,项目名称:amundsenmetadatalibrary,代码行数:22,代码来源:statsd_utilities.py

示例2: get_connection

# 需要导入模块: import flask [as 别名]
# 或者: from flask import has_app_context [as 别名]
def get_connection() -> database.Database:
    """在连接池中获得连接"""
    if not has_app_context():
        config = get_config()
        return MongoClient(**config.MONGODB).get_database(config.MONGODB_DB)
    return current_app.mongo.get_database(current_app.config['MONGODB_DB']) 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:8,代码来源:mongodb.py

示例3: logger

# 需要导入模块: import flask [as 别名]
# 或者: from flask import has_app_context [as 别名]
def logger() -> SupportsLogging:
    if has_app_context(): # type: ignore
        return current_app.logger # type: ignore
    return logging # type: ignore 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:6,代码来源:logger.py

示例4: sleep_task

# 需要导入模块: import flask [as 别名]
# 或者: from flask import has_app_context [as 别名]
def sleep_task(value):
    assert has_app_context() is True
    return sleep(value) 
开发者ID:cameronmaske,项目名称:celery-once,代码行数:5,代码来源:app.py

示例5: patch_task

# 需要导入模块: import flask [as 别名]
# 或者: from flask import has_app_context [as 别名]
def patch_task(self):
		TaskBase = self.Task
		_celery = self

		class ContextTask(TaskBase):
			abstract = True

			def __call__(self, *args, **kwargs):
				if flask.has_app_context():
					return TaskBase.__call__(self, *args, **kwargs)
				else:
					with _celery.app.app_context():
						return TaskBase.__call__(self, *args, **kwargs)

		self.Task = ContextTask 
开发者ID:minetest,项目名称:contentdb,代码行数:17,代码来源:__init__.py

示例6: display_distance

# 需要导入模块: import flask [as 别名]
# 或者: from flask import has_app_context [as 别名]
def display_distance(self):
        if has_app_context() and g.user.is_authenticated and g.user.units:
            units = g.user.units
        else:
            units = 'local'  # default

        if units == 'local':
            country_code = (getattr(g, 'country_code', None)
                            if has_app_context()
                            else None)
            units = country_units.get(country_code, 'km_and_metres')

        return utils.display_distance(units, self.dist) 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:15,代码来源:model.py

示例7: _build_user_from_record

# 需要导入模块: import flask [as 别名]
# 或者: from flask import has_app_context [as 别名]
def _build_user_from_record(record: dict, manager_name: str = '') -> UserEntity:
        """
        Builds user record from Cypher query result. Other than the one defined in amundsen_common.models.user.User,
        you could add more fields from User node into the User model by specifying keys in config.USER_OTHER_KEYS
        :param record:
        :param manager_name:
        :return:
        """
        other_key_values = {}
        if has_app_context() and current_app.config[config.USER_OTHER_KEYS]:
            for k in current_app.config[config.USER_OTHER_KEYS]:
                if k in record:
                    other_key_values[k] = record[k]

        return UserEntity(email=record['email'],
                          first_name=record.get('first_name'),
                          last_name=record.get('last_name'),
                          full_name=record.get('full_name'),
                          is_active=record.get('is_active', False),
                          github_username=record.get('github_username'),
                          team_name=record.get('team_name'),
                          slack_id=record.get('slack_id'),
                          employee_type=record.get('employee_type'),
                          role_name=record.get('role_name'),
                          manager_fullname=record.get('manager_fullname', manager_name),
                          other_key_values=other_key_values) 
开发者ID:lyft,项目名称:amundsenmetadatalibrary,代码行数:28,代码来源:neo4j_proxy.py

示例8: override_task_class

# 需要导入模块: import flask [as 别名]
# 或者: from flask import has_app_context [as 别名]
def override_task_class(self):
        BaseTask = self.Task
        _celery = self

        class ContextTask(BaseTask):
            abstract = True

            def __call__(self, *args, **kwargs):
                if flask.has_app_context():
                    return BaseTask.__call__(self, *args, **kwargs)
                else:
                    with _celery.app.app_context():
                        return BaseTask.__call__(self, *args, **kwargs)

        self.Task = ContextTask 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:17,代码来源:celery.py

示例9: check_free_space

# 需要导入模块: import flask [as 别名]
# 或者: from flask import has_app_context [as 别名]
def check_free_space(config=None):
    ''' Check how much disk space is free.
        E-mail admin if free space is low. '''

    if config is None:
        if not has_app_context():
            return
        config = current_app.config

    min_free_space = config.get('MIN_FREE_SPACE')

    if not min_free_space:  # not configured
        return

    free_space = utils.get_free_space(config)

    if free_space > min_free_space:
        return

    one_hour_ago = datetime.utcnow() - timedelta(hours=1)
    recent = model.SpaceWarning.most_recent()
    if recent and recent.timestamp > one_hour_ago:
        return  # already sent an alert within the last hour

    readable = humanize.naturalsize(free_space)
    subject = f'Low disk space: {readable} OSM/Wikidata matcher'

    print(f'low space warning: {readable}')

    body = f'''
Warning

The OSM/Wikidata matcher server is low on space.

There is currently {readable} available.
'''

    mail.send_mail(subject, body, config=config)

    alert = model.SpaceWarning(free_space=free_space)
    database.session.add(alert)
    database.session.commit() 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:44,代码来源:space_alert.py


注:本文中的flask.has_app_context方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。