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


Python api.NO_VALUE属性代码示例

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


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

示例1: get_rses_to_hostname_mapping

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def get_rses_to_hostname_mapping():
    """
    Return a dictionaries mapping the RSEs to the hostname of the SE

    :returns: Dictionary with RSE_id as key and (hostname, rse_info) as value
    """

    result = REGION.get('rse_hostname_mapping')
    if result is NO_VALUE:
        result = {}
        all_rses = list_rses()
        for rse in all_rses:
            rse_protocol = get_rse_protocols(rse_id=rse['id'])
            for prot in rse_protocol['protocols']:
                if prot['domains']['wan']['delete'] == 1:
                    result[rse['id']] = (prot['hostname'], rse_protocol)
            if rse['id'] not in result:
                logging.warn('No default delete protocol for %s', rse['rse'])

        REGION.set('rse_hostname_mapping', result)
        return result

    return result 
开发者ID:rucio,项目名称:rucio,代码行数:25,代码来源:reaper2.py

示例2: get_max_deletion_threads_by_hostname

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def get_max_deletion_threads_by_hostname(hostname):
    """
    Internal method to check RSE usage and limits.

    :param hostname: the hostname of the SE

    :returns : The maximum deletion thread for the SE.
    """
    result = REGION.get('max_deletion_threads_%s' % hostname)
    if result is NO_VALUE:
        try:
            max_deletion_thread = get('reaper', 'max_deletion_threads_%s' % hostname)
        except ConfigNotFound:
            try:
                max_deletion_thread = get('reaper', 'nb_workers_by_hostname')
            except ConfigNotFound:
                max_deletion_thread = 5
        REGION.set('max_deletion_threads_%s' % hostname, max_deletion_thread)
        result = max_deletion_thread
    return result 
开发者ID:rucio,项目名称:rucio,代码行数:22,代码来源:reaper2.py

示例3: get_value

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def get_value(self, merge=True, createfunc=None, expiration_time=None,
                  ignore_expiration=False):
        dogpile_region, cache_key = self._get_cache_plus_key()

        assert not ignore_expiration or not createfunc, \
            "Can't ignore expiration and also provide createfunc"

        if ignore_expiration or not createfunc:
            cached_value = dogpile_region.get(
                cache_key, expiration_time=expiration_time,
                ignore_expiration=ignore_expiration)
        else:
            cached_value = dogpile_region.get_or_create(
                cache_key, createfunc, expiration_time=expiration_time)

        if cached_value is NO_VALUE:
            raise KeyError(cache_key)
        if merge:
            cached_value = self.merge_result(cached_value, load=False)

        return cached_value 
开发者ID:MrKiven,项目名称:ECache,代码行数:23,代码来源:flask_cache.py

示例4: test_multi_asdict_keys_missing

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def test_multi_asdict_keys_missing(self):
        reg = self._region()

        counter = itertools.count(1)

        @reg.cache_multi_on_arguments(asdict=True)
        def generate(*args):
            return dict(
                [
                    (arg, "%d %d" % (arg, next(counter)))
                    for arg in args
                    if arg != 10
                ]
            )

        eq_(generate(2, 8, 10), {2: "2 1", 8: "8 2"})
        eq_(generate(2, 9, 10), {2: "2 1", 9: "9 3"})

        assert reg.get(10) is NO_VALUE

        generate.invalidate(2)
        eq_(generate(2, 7, 10), {2: "2 4", 7: "7 5"})

        generate.set({7: 18, 10: 15})
        eq_(generate(2, 7, 10), {2: "2 4", 7: 18, 10: 15}) 
开发者ID:sqlalchemy,项目名称:dogpile.cache,代码行数:27,代码来源:test_decorator.py

示例5: test_expire

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def test_expire(self):
        reg = self._region(config_args={"expiration_time": 1})
        counter = itertools.count(1)

        def creator():
            return "some value %d" % next(counter)

        eq_(reg.get_or_create("some key", creator), "some value 1")
        time.sleep(2)
        is_(reg.get("some key"), NO_VALUE)
        eq_(reg.get("some key", ignore_expiration=True), "some value 1")
        eq_(
            reg.get_or_create("some key", creator, expiration_time=-1),
            "some value 1",
        )
        eq_(reg.get_or_create("some key", creator), "some value 2")
        eq_(reg.get("some key"), "some value 2") 
开发者ID:sqlalchemy,项目名称:dogpile.cache,代码行数:19,代码来源:test_region.py

示例6: test_expire_multi

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def test_expire_multi(self):
        reg = self._region(config_args={"expiration_time": 1})
        counter = itertools.count(1)

        def creator(*keys):
            return ["some value %s %d" % (key, next(counter)) for key in keys]

        eq_(
            reg.get_or_create_multi(["k3", "k2", "k5"], creator),
            ["some value k3 2", "some value k2 1", "some value k5 3"],
        )
        time.sleep(2)
        is_(reg.get("k2"), NO_VALUE)
        eq_(reg.get("k2", ignore_expiration=True), "some value k2 1")
        eq_(
            reg.get_or_create_multi(["k3", "k2"], creator, expiration_time=-1),
            ["some value k3 2", "some value k2 1"],
        )
        eq_(
            reg.get_or_create_multi(["k3", "k2"], creator),
            ["some value k3 5", "some value k2 4"],
        )
        eq_(reg.get("k2"), "some value k2 4") 
开发者ID:sqlalchemy,项目名称:dogpile.cache,代码行数:25,代码来源:test_region.py

示例7: get_rses_to_process

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def get_rses_to_process(rses, include_rses, exclude_rses):
    """
    Return the list of RSEs to process based on rses, include_rses and exclude_rses

    :param rses:               List of RSEs the reaper should work against. If empty, it considers all RSEs.
    :param exclude_rses:       RSE expression to exclude RSEs from the Reaper.
    :param include_rses:       RSE expression to include RSEs.

    :returns: A list of RSEs to process
    """
    result = REGION.get('rses_to_process')
    if result is not NO_VALUE:
        return result

    all_rses = list_rses()
    if rses:
        invalid = set(rses) - set([rse['rse'] for rse in all_rses])
        if invalid:
            msg = 'RSE{} {} cannot be found'.format('s' if len(invalid) > 1 else '',
                                                    ', '.join([repr(rse) for rse in invalid]))
            raise RSENotFound(msg)
        rses = [rse for rse in all_rses if rse['rse'] in rses]
    else:
        rses = all_rses

    if include_rses:
        included_rses = parse_expression(include_rses)
        rses = [rse for rse in rses if rse in included_rses]

    if exclude_rses:
        excluded_rses = parse_expression(exclude_rses)
        rses = [rse for rse in rses if rse not in excluded_rses]

    REGION.set('rses_to_process', rses)
    logging.info('Reaper: This instance will work on RSEs: %s', ', '.join([rse['rse'] for rse in rses]))
    return rses 
开发者ID:rucio,项目名称:rucio,代码行数:38,代码来源:reaper2.py

示例8: get_rse_id

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def get_rse_id(rse, session=None, include_deleted=True):
    """
    Get a RSE ID or raise if it does not exist.

    :param rse: the rse name.
    :param session: The database session in use.
    :param include_deleted: Flag to toggle finding rse's marked as deleted.

    :returns: The rse id.

    :raises RSENotFound: If referred RSE was not found in the database.
    """

    if include_deleted:
        cache_key = 'rse-id_{}'.format(rse).replace(' ', '.')
        result = REGION.get(cache_key)
        if result != NO_VALUE:
            return result

    try:
        query = session.query(models.RSE.id).filter_by(rse=rse)
        if not include_deleted:
            query = query.filter_by(deleted=False)
        result = query.one()[0]
    except sqlalchemy.orm.exc.NoResultFound:
        raise exception.RSENotFound('RSE \'%s\' cannot be found' % rse)

    if include_deleted:
        REGION.set(cache_key, result)
    return result 
开发者ID:rucio,项目名称:rucio,代码行数:32,代码来源:rse.py

示例9: get_rses_with_attribute_value

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def get_rses_with_attribute_value(key, value, lookup_key, session=None):
    """
    Return all RSEs with a certain attribute.

    :param key: The key for the attribute.
    :param value: The value for the attribute.
    :param lookup_key: The value of the this key will be returned.
    :param session: The database session in use.

    :returns: List of rse dictionaries with the rse_id and lookup_key/value pair
    """

    result = REGION.get('av-%s-%s-%s' % (key, value, lookup_key))
    if result is NO_VALUE:

        rse_list = []

        subquery = session.query(models.RSEAttrAssociation.rse_id)\
                          .filter(models.RSEAttrAssociation.key == key,
                                  models.RSEAttrAssociation.value == value)\
                          .subquery()

        query = session.query(models.RSEAttrAssociation.rse_id,
                              models.RSEAttrAssociation.key,
                              models.RSEAttrAssociation.value)\
                       .join(models.RSE, models.RSE.id == models.RSEAttrAssociation.rse_id)\
                       .join(subquery, models.RSEAttrAssociation.rse_id == subquery.c.rse_id)\
                       .filter(models.RSE.deleted == false(),
                               models.RSEAttrAssociation.key == lookup_key)

        for row in query:
            rse_list.append({'rse_id': row[0],
                             'key': row[1],
                             'value': row[2]})

        REGION.set('av-%s-%s-%s' % (key, value, lookup_key), rse_list)
        return rse_list

    return result 
开发者ID:rucio,项目名称:rucio,代码行数:41,代码来源:rse.py

示例10: get_rse_attribute

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def get_rse_attribute(key, rse_id=None, value=None, use_cache=True, session=None):
    """
    Retrieve RSE attribute value.

    :param rse_id: The RSE id.
    :param key: The key for the attribute.
    :param value: Optionally, the desired value for the attribute.
    :param use_cache: Boolean to use memcached.
    :param session: The database session in use.

    :returns: A list with RSE attribute values for a Key.
    """

    result = NO_VALUE
    if use_cache:
        result = REGION.get('%s-%s-%s' % (key, rse_id, value))
    if result is NO_VALUE:

        rse_attrs = []
        if rse_id:
            query = session.query(models.RSEAttrAssociation.value).filter_by(rse_id=rse_id, key=key).distinct()
            if value:
                query = session.query(models.RSEAttrAssociation.value).filter_by(rse_id=rse_id, key=key, value=value).distinct()
        else:
            query = session.query(models.RSEAttrAssociation.value).filter_by(key=key).distinct()
            if value:
                query = session.query(models.RSEAttrAssociation.value).filter_by(key=key, value=value).distinct()
        for attr_value in query:
            rse_attrs.append(attr_value[0])
        REGION.set('%s-%s-%s' % (key, rse_id, value), rse_attrs)
        return rse_attrs

    return result 
开发者ID:rucio,项目名称:rucio,代码行数:35,代码来源:rse.py

示例11: get_evaluation_backlog

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def get_evaluation_backlog(session=None):
    """
    Counts the number of entries in the rule evaluation backlog.
    (Number of files to be evaluated)

    :returns:     Tuple (Count, Datetime of oldest entry)
    """

    result = REGION.get('rule_evaluation_backlog', expiration_time=600)
    if result is NO_VALUE:
        result = session.query(func.count(models.UpdatedDID.created_at), func.min(models.UpdatedDID.created_at)).one()
        REGION.set('rule_evaluation_backlog', result)
    return result 
开发者ID:rucio,项目名称:rucio,代码行数:15,代码来源:rule.py

示例12: validate_auth_token

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def validate_auth_token(token, session=None):
    """
    Validate an authentication token.

    :param token: Authentication token as a variable-length string.

    :returns: dictionary { account: <account name>,
                           identity: <identity>,
                           lifetime: <token lifetime>,
                           audience: <audience>,
                           authz_scope: <authz_scope> }
              if successful, None otherwise.
    """
    if not token:
        return None

    # Be gentle with bash variables, there can be whitespace
    token = token.strip()

    # Check if token ca be found in cache region
    value = TOKENREGION.get(token)
    if value is NO_VALUE:  # no cached entry found
        value = query_token(token, session=session)
        if not value:
            # identify JWT access token and validte
            # & save it in Rucio if scope and audience are correct
            if len(token.split(".")) == 3:
                value = validate_jwt(token, session=session)
                if not value:
                    return None
            else:
                return None
        # save token in the cache
        TOKENREGION.set(token, value)
    if value.get('lifetime', datetime.datetime(1970, 1, 1)) < datetime.datetime.utcnow():  # check if expired
        TOKENREGION.delete(token)
        return None
    return value 
开发者ID:rucio,项目名称:rucio,代码行数:40,代码来源:authentication.py

示例13: filter

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def filter(self, order_by='asc', offset=None, limit=None, **kwargs):
        query_kwargs = {}
        if kwargs:
            if len(kwargs) > 1:
                raise TypeError(
                    'filter accept only one attribute for filtering')
            key, value = kwargs.items()[0]
            if key not in self._columns():
                raise TypeError(
                    '%s does not have an attribute %s' % (self, key))
            query_kwargs[key] = value

        cache_key = self._cache_key(**kwargs)
        pks = self.regions[self.label].get(cache_key)

        if pks is NO_VALUE:
            pks = [
                o.id for o in self.model.query.filter_by(
                    **kwargs).with_entities(getattr(self.model, self.pk))]

        if order_by == 'desc':
            pks.reverse()

        if offset is not None:
            pks = pks[pks:]

        if limit is not None:
            pks = pks[:limit]

        keys = [self._cache_key(pk) for pk in pks]
        for pos, obj in enumerate(self.regions[self.label].get_multi(keys)):
            if obj is NO_VALUE:
                yield self.get(pks[pos])
            else:
                yield obj[0] 
开发者ID:MrKiven,项目名称:ECache,代码行数:37,代码来源:flask_cache.py

示例14: test_get

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def test_get(self):
        reg = self._region()

        eq_(reg.get("some key"), NO_VALUE) 
开发者ID:sqlalchemy,项目名称:dogpile.cache,代码行数:6,代码来源:test_null_backend.py

示例15: test_set

# 需要导入模块: from dogpile.cache import api [as 别名]
# 或者: from dogpile.cache.api import NO_VALUE [as 别名]
def test_set(self):
        reg = self._region()
        reg.set("some key", "some value")
        eq_(reg.get("some key"), NO_VALUE) 
开发者ID:sqlalchemy,项目名称:dogpile.cache,代码行数:6,代码来源:test_null_backend.py


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