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


Python flask.current_app方法代码示例

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


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

示例1: __init__

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def __init__(self):
        super(CallbackModule, self).__init__()

        if not flask.current_app:
            ctx = app.app_context()
            ctx.push()

        self.taskresult = None
        self.task = None
        self.play = None
        self.playbook = None
        self.stats = None
        self.loop_items = []

        self.play_counter = itertools.count()
        self.task_counter = itertools.count()

        if cli:
            self._options = cli.options
        else:
            self._options = None 
开发者ID:dmsimard,项目名称:ara-archive,代码行数:23,代码来源:log_ara.py

示例2: list_available

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def list_available():
    '''
    List available migrations for udata and enabled plugins

    Each row is a tuple with following signature:

        (plugin, package, filename)
    '''
    migrations = []

    migrations.extend(_iter('udata', 'udata'))

    plugins = entrypoints.get_enabled('udata.models', current_app)
    for plugin, module in plugins.items():
        migrations.extend(_iter(plugin, module))
    return sorted(migrations, key=lambda m: m.filename) 
开发者ID:opendatateam,项目名称:udata,代码行数:18,代码来源:__init__.py

示例3: harvest

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def harvest(self, ident):
    log.info('Launching harvest job for source "%s"', ident)

    source = HarvestSource.get(ident)
    if source.deleted:
        return  # Ignore deleted sources
    Backend = backends.get(current_app, source.backend)
    backend = Backend(source)
    items = backend.perform_initialization()
    if items > 0:
        finalize = harvest_job_finalize.s(backend.job.id)
        items = [
            harvest_job_item.s(backend.job.id, item.remote_id)
            for item in backend.job.items
        ]
        chord(items)(finalize)
    elif items == 0:
        backend.finalize() 
开发者ID:opendatateam,项目名称:udata,代码行数:20,代码来源:tasks.py

示例4: create

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def create(force=False):
    """Create tables if the database has not been configured yet."""
    # Fail if there's an alembic version set
    engine = db.get_engine(flask.current_app)
    conn = engine.connect()
    context = MigrationContext.configure(conn)
    current_rev = context.get_current_revision()
    alembic_config = flask.current_app.extensions['migrate'].migrate.get_config(
            directory=migrate_path)
    script = ScriptDirectory.from_config(alembic_config)
    latest_rev = script.get_current_head()
    if current_rev == latest_rev and not force:
        print(u"You need to run 'evesrp -c config.py db migrate' to "
              u"migrate to the latest database schema.")
    else:
        db.create_all()
        if current_rev is None:
            stamp() 
开发者ID:paxswill,项目名称:evesrp,代码行数:20,代码来源:manage.py

示例5: init_multipart_upload

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def init_multipart_upload(key, expires_in=None):
        """
        Initilize multipart upload given key

        Args:
            key(str): object key

        Returns:
            uploadId(str)
        """
        try:
            bucket = flask.current_app.config["DATA_UPLOAD_BUCKET"]
        except KeyError:
            raise InternalError(
                "fence not configured with data upload bucket; can't create signed URL"
            )
        s3_url = "s3://{}/{}".format(bucket, key)
        return S3IndexedFileLocation(s3_url).init_multipart_upload(expires_in) 
开发者ID:uc-cdis,项目名称:fence,代码行数:20,代码来源:indexd.py

示例6: complete_multipart_upload

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def complete_multipart_upload(key, uploadId, parts, expires_in=None):
        """
        Complete multipart upload

        Args:
            key(str): object key or `GUID/filename`
            uploadId(str): upload id of the current upload
            parts(list(set)): List of part infos
                [{"Etag": "1234567", "PartNumber": 1}, {"Etag": "4321234", "PartNumber": 2}]

        Returns:
            None if success otherwise an exception
        """
        try:
            bucket = flask.current_app.config["DATA_UPLOAD_BUCKET"]
        except KeyError:
            raise InternalError(
                "fence not configured with data upload bucket; can't create signed URL"
            )
        s3_url = "s3://{}/{}".format(bucket, key)
        S3IndexedFileLocation(s3_url).complete_multipart_upload(
            uploadId, parts, expires_in
        ) 
开发者ID:uc-cdis,项目名称:fence,代码行数:25,代码来源:indexd.py

示例7: generate_aws_presigned_url_for_part

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def generate_aws_presigned_url_for_part(key, uploadId, partNumber, expires_in):
        """
        Generate presigned url for each part

        Args:
            key(str): object key of `guid/filename`
            uploadID(str): uploadId of the current upload.
            partNumber(int): the part number

        Returns:
            presigned_url(str)
        """
        try:
            bucket = flask.current_app.config["DATA_UPLOAD_BUCKET"]
        except KeyError:
            raise InternalError(
                "fence not configured with data upload bucket; can't create signed URL"
            )
        s3_url = "s3://{}/{}".format(bucket, key)
        return S3IndexedFileLocation(s3_url).generate_presigne_url_for_part_upload(
            uploadId, partNumber, expires_in
        ) 
开发者ID:uc-cdis,项目名称:fence,代码行数:24,代码来源:indexd.py

示例8: delete_files

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def delete_files(self, urls=None, delete_all=True):
        """
        Delete the data files stored at all the locations for this indexed file.

        If a list of URLs is specified, delete only files at those locations;
        otherwise, delete files at all locations.

        Args:
            urls (Optional[List[str]])

        Return:
            None
        """
        locations_to_delete = []
        if urls is None and delete_all:
            locations_to_delete = self.indexed_file_locations
        else:
            locations_to_delete = [
                location for location in locations_to_delete if location.url in urls
            ]
        for location in locations_to_delete:
            bucket = location.bucket_name()
            flask.current_app.boto.delete_data_file(bucket, self.file_id) 
开发者ID:uc-cdis,项目名称:fence,代码行数:25,代码来源:indexd.py

示例9: get_keys

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def get_keys():
    """
    Gets the encryption keys.

    This supports multiple keys to facilitate key rotation. The first
    key in the list is used to encrypt. Decryption is attempted with
    each key in succession.

    :return:
    """

    # when running lemur create_config, this code needs to work despite
    # the fact that there is not a current_app with a config at that point
    keys = current_app.config.get("LEMUR_ENCRYPTION_KEYS", [])

    # this function is expected to return a list of keys, but we want
    # to let people just specify a single key
    if not isinstance(keys, list):
        keys = [keys]

    # make sure there is no accidental whitespace
    keys = [key.strip() for key in keys]

    return keys 
开发者ID:Netflix,项目名称:lemur,代码行数:26,代码来源:utils.py

示例10: redis

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def redis(self, db=0):
        # The decode_responses flag here directs the client to convert the responses from Redis into Python strings
        # using the default encoding utf-8.  This is client specific.
        function = f"{__name__}.{sys._getframe().f_code.co_name}"
        try:
            red = redis.StrictRedis(host=self.host, port=self.port, db=self.db, encoding="utf-8", decode_responses=True)
            red.set("test", 0)
        except redis.ConnectionError:
            log_data = {
                "function": function,
                "message": "Redis Connection error",
                "host": self.host,
                "port": self.port
            }
            current_app.logger.error(log_data)
            sentry.captureException()
        return red 
开发者ID:Netflix,项目名称:lemur,代码行数:19,代码来源:redis.py

示例11: report_failed_task

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def report_failed_task(**kwargs):
    """
    Report a generic failure metric as tasks to our metrics broker every time a task fails.
    This metric can be used for alerting.
    https://docs.celeryproject.org/en/latest/userguide/signals.html#task-failure
    """
    with flask_app.app_context():
        log_data = {
            "function": f"{__name__}.{sys._getframe().f_code.co_name}",
            "Message": "Celery Task Failure",
        }

        # Add traceback if exception info is in the kwargs
        einfo = kwargs.get("einfo")
        if einfo:
            log_data["traceback"] = einfo.traceback

        error_tags = get_celery_request_tags(**kwargs)

        log_data.update(error_tags)
        current_app.logger.error(log_data)
        metrics.send("celery.failed_task", "TIMER", 1, metric_tags=error_tags) 
开发者ID:Netflix,项目名称:lemur,代码行数:24,代码来源:celery.py

示例12: enable_autorotate_for_certs_attached_to_endpoint

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def enable_autorotate_for_certs_attached_to_endpoint():
    """
    This celery task automatically enables autorotation for unexpired certificates that are
    attached to an endpoint but do not have autorotate enabled.
    :return:
    """
    function = f"{__name__}.{sys._getframe().f_code.co_name}"
    task_id = None
    if celery.current_task:
        task_id = celery.current_task.request.id

    log_data = {
        "function": function,
        "task_id": task_id,
        "message": "Enabling autorotate to eligible certificates",
    }
    current_app.logger.debug(log_data)

    cli_certificate.automatically_enable_autorotate()
    metrics.send(f"{function}.success", "counter", 1)
    return log_data 
开发者ID:Netflix,项目名称:lemur,代码行数:23,代码来源:celery.py

示例13: _get

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def _get(path, params=None):
    """
    Execute a GET request on the given URL (base_uri + path) and return response as JSON object

    :param path: Relative URL path
    :param params: additional parameters
    :return: json response
    """
    base_uri = current_app.config.get("ACME_POWERDNS_DOMAIN")
    verify_value = current_app.config.get("ACME_POWERDNS_VERIFY", True)
    resp = requests.get(
        f"{base_uri}{path}",
        headers=_generate_header(),
        params=params,
        verify=verify_value
    )
    resp.raise_for_status()
    return resp.json() 
开发者ID:Netflix,项目名称:lemur,代码行数:20,代码来源:powerdns.py

示例14: _patch

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def _patch(path, payload):
    """
    Execute a Patch request on the given URL (base_uri + path) with given payload

    :param path:
    :param payload:
    :return:
    """
    base_uri = current_app.config.get("ACME_POWERDNS_DOMAIN")
    verify_value = current_app.config.get("ACME_POWERDNS_VERIFY", True)
    resp = requests.patch(
        f"{base_uri}{path}",
        data=json.dumps(payload),
        headers=_generate_header(),
        verify=verify_value
    )
    resp.raise_for_status() 
开发者ID:Netflix,项目名称:lemur,代码行数:19,代码来源:powerdns.py

示例15: test_app_exists

# 需要导入模块: import flask [as 别名]
# 或者: from flask import current_app [as 别名]
def test_app_exists(self):
        self.assertFalse(current_app is None) 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:4,代码来源:test_basic_function.py


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