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


Python Effect.on方法代码示例

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


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

示例1: concretize_service_request

# 需要导入模块: from effect import Effect [as 别名]
# 或者: from effect.Effect import on [as 别名]
def concretize_service_request(
        authenticator, log, service_configs, throttler,
        tenant_id,
        service_request):
    """
    Translate a high-level :obj:`ServiceRequest` into a low-level :obj:`Effect`
    of :obj:`pure_http.Request`. This doesn't directly conform to the Intent
    performer interface, but it's intended to be used by a performer.

    :param ICachingAuthenticator authenticator: the caching authenticator
    :param BoundLog log: info about requests will be logged to this.
    :param dict service_configs: As returned by
        :func:`otter.constants.get_service_configs`.
    :param callable throttler: A function of ServiceType, HTTP method ->
        Deferred bracketer or None, used to throttle requests. See
        :obj:`_Throttle`.
    :param tenant_id: tenant ID.
    """
    auth_eff = Effect(Authenticate(authenticator, tenant_id, log))
    invalidate_eff = Effect(InvalidateToken(authenticator, tenant_id))
    if service_request.log is not None:
        log = service_request.log

    service_config = service_configs[service_request.service_type]
    region = service_config['region']
    service_name = service_config['name']

    def got_auth((token, catalog)):
        request_ = add_headers(otter_headers(token), request)
        request_ = add_effect_on_response(
            invalidate_eff, service_request.reauth_codes, request_)
        request_ = add_json_request_data(request_)
        if 'url' in service_config:
            request_ = add_bind_root(service_config['url'], request_)
        else:
            request_ = add_bind_service(
                catalog, service_name, region, log, request_)
        request_ = add_error_handling(
            service_request.success_pred, request_)
        if service_request.json_response:
            request_ = add_json_response(request_)

        return request_(
            service_request.method,
            service_request.url,
            headers=service_request.headers,
            data=service_request.data,
            params=service_request.params,
            log=log)

    eff = auth_eff.on(got_auth)
    bracket = throttler(service_request.service_type,
                        service_request.method.lower(),
                        tenant_id)
    if bracket is not None:
        return Effect(_Throttle(bracket=bracket, effect=eff))
    else:
        return eff
开发者ID:dragorosson,项目名称:otter,代码行数:60,代码来源:__init__.py

示例2: as_effect

# 需要导入模块: from effect import Effect [as 别名]
# 或者: from effect.Effect import on [as 别名]
    def as_effect(self):
        """Produce a :obj:`Effect` to create a stack."""
        eff = Effect(Func(uuid4))

        def got_uuid(uuid):
            stack_config = append_stack_uuid(self.stack_config, uuid)
            return create_stack(thaw(stack_config)).on(
                _success_reporter('Waiting for stack to create'))

        return eff.on(got_uuid)
开发者ID:meker12,项目名称:otter,代码行数:12,代码来源:steps.py

示例3: get_org_repos

# 需要导入模块: from effect import Effect [as 别名]
# 或者: from effect.Effect import on [as 别名]
def get_org_repos(name):
    """
    Fetch the repos that belong to an organization.

    :return: An Effect resulting in a list of strings naming the repositories.
    """
    req = Effect(
        HTTPRequest("get",
                    "https://api.github.com/orgs/{0}/repos".format(name)))
    return req.on(success=lambda x: [repo['name'] for repo in json.loads(x)])
开发者ID:python-effect,项目名称:effect-examples,代码行数:12,代码来源:core.py

示例4: get_last_info

# 需要导入模块: from effect import Effect [as 别名]
# 或者: from effect.Effect import on [as 别名]
def get_last_info(fname):
    eff = Effect(ReadFileLines(fname)).on(
        lambda lines: (int(lines[0]),
                       datetime.utcfromtimestamp(float(lines[1]))))

    def log_and_return(e):
        _eff = err(e, "error reading previous number of tenants")
        return _eff.on(lambda _: (None, None))

    return eff.on(error=log_and_return)
开发者ID:glyph,项目名称:otter,代码行数:12,代码来源:metrics.py

示例5: main_effect

# 需要导入模块: from effect import Effect [as 别名]
# 或者: from effect.Effect import on [as 别名]
def main_effect():
    """
    Request a username from the keyboard, and look up all repos in all of
    that user's organizations.

    :return: an Effect resulting in a list of repositories.
    """
    intent = ReadLine("Enter Github Username> ")
    read_eff = Effect(intent)
    org_repos_eff = read_eff.on(success=get_orgs_repos)
    return org_repos_eff
开发者ID:python-effect,项目名称:effect-examples,代码行数:13,代码来源:core.py

示例6: get_orgs

# 需要导入模块: from effect import Effect [as 别名]
# 或者: from effect.Effect import on [as 别名]
def get_orgs(name):
    """
    Fetch the organizations a user belongs to.

    :return: An Effect resulting in a list of strings naming the user's
    organizations.
    """
    req = Effect(
        HTTPRequest("get",
                    "https://api.github.com/users/{0}/orgs".format(name)))
    return req.on(success=lambda x: [org['login'] for org in json.loads(x)])
开发者ID:python-effect,项目名称:effect-examples,代码行数:13,代码来源:core.py

示例7: get_all_metrics_effects

# 需要导入模块: from effect import Effect [as 别名]
# 或者: from effect.Effect import on [as 别名]
def get_all_metrics_effects(tenanted_groups, log, _print=False):
    """
    Gather server data for and produce metrics for all groups
    across all tenants in a region

    :param dict tenanted_groups: Scaling groups grouped with tenantId
    :param bool _print: Should the function print while processing?

    :return: ``list`` of :obj:`Effect` of (``list`` of :obj:`GroupMetrics`)
             or None
    """
    effs = []
    for tenant_id, groups in tenanted_groups.iteritems():
        eff = get_all_scaling_group_servers()
        eff = Effect(TenantScope(eff, tenant_id))
        eff = eff.on(partial(get_tenant_metrics, tenant_id, groups,
                             _print=_print))
        eff = eff.on(list)
        eff = eff.on(
            error=lambda exc_info: log.err(exc_info_to_failure(exc_info)))
        effs.append(eff)
    return effs
开发者ID:dragorosson,项目名称:otter,代码行数:24,代码来源:metrics.py

示例8: update_last_info

# 需要导入模块: from effect import Effect [as 别名]
# 或者: from effect.Effect import on [as 别名]
def update_last_info(fname, tenants_len, time):
    eff = Effect(
        WriteFileLines(
            fname, [tenants_len, datetime_to_epoch(time)]))
    return eff.on(error=lambda e: err(e, "error updating number of tenants"))
开发者ID:glyph,项目名称:otter,代码行数:7,代码来源:metrics.py


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