當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。