當前位置: 首頁>>代碼示例>>Python>>正文


Python conditions.Attr方法代碼示例

本文整理匯總了Python中boto3.dynamodb.conditions.Attr方法的典型用法代碼示例。如果您正苦於以下問題:Python conditions.Attr方法的具體用法?Python conditions.Attr怎麽用?Python conditions.Attr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在boto3.dynamodb.conditions的用法示例。


在下文中一共展示了conditions.Attr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parse_filters

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def parse_filters(self, filters, doc_class):
        index_name = None
        filter_expression_list = []
        query_params = {}
        for idx, filter in enumerate(filters):
            prop_name, prop_value = filter.split(':')[3:5]
            if idx == 0:
                prop = doc_class()._base_properties[prop_name]
                index_name = prop.kwargs.get(self.index_field_name, None) or \
                             self.default_index_name.format(prop_name)
                query_params['KeyConditionExpression'] = Key(prop_name).eq(prop_value)
            else:
                filter_expression_list.append(Attr(prop_name).eq(prop_value))
        if len(filter_expression_list) > 1:
            query_params['FilterExpression'] = And(*filter_expression_list)
        elif len(filter_expression_list) == 1:
            query_params['FilterExpression'] = filter_expression_list[0]
        if index_name != '_id':
            query_params['IndexName'] = index_name
        return query_params 
開發者ID:capless,項目名稱:kev,代碼行數:22,代碼來源:db.py

示例2: get_task_items_for_job

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def get_task_items_for_job(self, task_group):

        job_tasks = []

        args = {
            "Select": "ALL_ATTRIBUTES",
            "ProjectionExpression": handlers.TASK_TR_ID,
            "ConsistentRead": True,
            "FilterExpression": Attr(handlers.TASK_TR_GROUP).eq(task_group)
        }

        while True:
            resp = self._action_table.scan_with_retries(**args)

            for item in resp.get("Items", []):
                job_tasks.append(item)
            if "LastEvaluatedKey" in resp:
                args["ExclusiveStartKey"] = resp["LastEvaluatedKey"]
            else:
                break

        return job_tasks 
開發者ID:awslabs,項目名稱:aws-ops-automator,代碼行數:24,代碼來源:task_tracking_table.py

示例3: write_lock_item

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def write_lock_item(self, lockname, caller, waitms):
        expire_ts = timestamp_millis() + waitms
        ttl = expire_ts + self.ttl_minutes*60
        logger.debug("Write_item: lockname=" + lockname + ", caller=" +
                     caller + ", Expire time is " + str(expire_ts))
        try:
            self.get_table().put_item(
                Item={
                    'lockname': lockname,
                    'expire_ts': expire_ts,
                    'holder': caller,
                    'ttl': ttl
                },
                # TODO: adding Attr("holder").eq(caller) should make it re-entrant
                ConditionExpression=Attr("holder").eq(NO_HOLDER) | Attr('lockname').not_exists()
            )
        except botocore.exceptions.ClientError as e:
            if e.response['Error']['Code'] == 'ConditionalCheckFailedException':
                logger.info("Write_item: lockname=" + lockname +
                             ", caller=" + caller + ", lock is being held")
                return False
        logger.debug("Write_item: lockname=" + lockname +
                     ", caller=" + caller + ", lock is acquired")
        return True 
開發者ID:chiradeep,項目名稱:dyndb-mutex,代碼行數:26,代碼來源:dyndbmutex.py

示例4: clear_lock_item

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def clear_lock_item(self, lockname, caller):
        try:
            self.get_table().put_item(
                Item={
                    'lockname': lockname,
                    'expire_ts': 0,
                    'holder': NO_HOLDER
                },
                ConditionExpression=Attr("holder").eq(caller) | Attr('lockname').not_exists()
            )
        except botocore.exceptions.ClientError as e:
            if e.response['Error']['Code'] == 'ConditionalCheckFailedException':
                logger.warning("clear_lock_item: lockname=" + lockname + ", caller=" + caller +
                             " release failed")
                return False
        logger.debug("clear_lock_item: lockname=" + lockname + ", caller=" + caller + " release succeeded")
        return True 
開發者ID:chiradeep,項目名稱:dyndb-mutex,代碼行數:19,代碼來源:dyndbmutex.py

示例5: prune_expired

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def prune_expired(self, lockname, caller):
        now = timestamp_millis()
        logger.debug("Prune: lockname=" + lockname + ", caller=" + caller +
                     ", Time now is %s" + str(now))
        try:
            self.get_table().put_item(
                Item={
                    'lockname': lockname,
                    'expire_ts': 0,
                    'holder': NO_HOLDER
                },
                ConditionExpression=Attr("expire_ts").lt(now) | Attr('lockname').not_exists()
            )
        except botocore.exceptions.ClientError as e:
            if e.response['Error']['Code'] == 'ConditionalCheckFailedException':
                logger.info("Prune: lockname=" + lockname + ", caller=" + caller +
                             " Prune failed")
                return False
        logger.debug("Prune: lockname=" + lockname + ", caller=" + caller + " Prune succeeded")
        return True 
開發者ID:chiradeep,項目名稱:dyndb-mutex,代碼行數:22,代碼來源:dyndbmutex.py

示例6: update_limit_value

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def update_limit_value(limit_type):
    service, limit_name = limit_type.split(NAME_SEPARATOR)
    checker = get_aws_limit_checker()
    limits = checker.get_limits(use_ta=settings.PREMIUM_ACCOUNT)
    default_limit = limits[service][limit_name].default_limit

    dynamodb = get_boto_resource('dynamodb')
    tickets_table = get_tickets_table()

    tickets = tickets_table.scan(
        FilterExpression=Attr('limit_type').eq(limit_type)
    )['Items']
    if tickets:
        max_value = max(ticket['limit_value'] for ticket in tickets)
    else:
        max_value = 0

    max_value = max([max_value, default_limit])
    update_dynamodb_limit_value(limit_type, max_value) 
開發者ID:Yipit,項目名稱:awslimits,代碼行數:21,代碼來源:support.py

示例7: get_recently_sent_alerts

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def get_recently_sent_alerts(limits):
    table = create_or_get_table(
        table_name=SENT_ALERTS_TABLE_NAME,
        attribute_definitions=[
            {
                'AttributeName': 'limit_name',
                'AttributeType': 'S',
            },
        ],
        key_schema=[
            {
                'AttributeName': 'limit_name',
                'KeyType': 'HASH'
            },
        ],
    )

    three_days_ago_ts = Decimal((datetime.utcnow() - timedelta(days=3)).strftime('%s'))
    alerts = table.scan(
        FilterExpression=Attr('alert_sent').gt(three_days_ago_ts)
    )['Items']
    return [alert['limit_name'] for alert in alerts] 
開發者ID:Yipit,項目名稱:awslimits,代碼行數:24,代碼來源:support.py

示例8: get_all_items

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def get_all_items(self, table_name, filter_expr=None):
        """ Get all items from table.

        :type table_name: str
        :type filter_expr: Attr
        :return list(if items exist)
        """
        table = self.get_table_by_name(table_name)
        response = self.scan(table=table, filter_expr=filter_expr)
        do_continue = response.get('LastEvaluatedKey')
        items = []
        if 'Items' in response:
            items.extend(response['Items'])
        while do_continue:
            response = self.scan(table=table, token=do_continue,
                                 filter_expr=filter_expr)
            do_continue = response.get('LastEvaluatedKey')
            if 'Items' in response:
                items.extend(response['Items'])
        return items 
開發者ID:epam,項目名稱:aws-syndicate,代碼行數:22,代碼來源:dynamo_connection.py

示例9: get_items_with_attribute_value

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def get_items_with_attribute_value(self, table_name, attr_name,
                                       attr_value):
        """ Get all items from table, which have specified attribute with
        specified value.

        :type table_name: str
        :type attr_name: str
        :param attr_value: attr value in table
        :return: list(if items exist)
        """
        table = self.get_table_by_name(table_name)
        result = []
        response = self.scan(table=table,
                             filter_expr=Attr(attr_name).eq(attr_value))
        do_continue = response.get('LastEvaluatedKey')
        if 'Items' in response:
            result.extend(response['Items'])
        while do_continue:
            response = self.scan(table=table, token=do_continue,
                                 filter_expr=Attr(attr_name).eq(attr_value))
            do_continue = response.get('LastEvaluatedKey')
            if 'Items' in response:
                result.extend(response['Items'])
        return result 
開發者ID:epam,項目名稱:aws-syndicate,代碼行數:26,代碼來源:dynamo_connection.py

示例10: list_workflows_by_operator

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def list_workflows_by_operator(OperatorName):
    """ List all workflow defintions that contain an operator

    Returns:
        A list of workflow definitions.

    Raises:
        200: All workflows returned sucessfully.
        500: Internal server error
    """

    table = DYNAMO_RESOURCE.Table(WORKFLOW_TABLE_NAME)

    response = table.scan(
        FilterExpression=Attr("Operations").contains(OperatorName),
        ConsistentRead=True
    )
    workflows = response['Items']
    while 'LastEvaluatedKey' in response:
        response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
        workflows.extend(response['Items'])

    return workflows 
開發者ID:awslabs,項目名稱:aws-media-insights-engine,代碼行數:25,代碼來源:app.py

示例11: list_workflows_by_stage

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def list_workflows_by_stage(StageName):
    """ List all workflow defintions that contain a stage

    Returns:
        A list of workflow definitions.

    Raises:
        200: All workflows returned sucessfully.
        500: Internal server error
    """

    table = DYNAMO_RESOURCE.Table(WORKFLOW_TABLE_NAME)

    response = table.scan(
        FilterExpression=Attr("Stages."+StageName).exists(),
        ConsistentRead=True
    )
    workflows = response['Items']
    while 'LastEvaluatedKey' in response:
        response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
        workflows.extend(response['Items'])

    return workflows 
開發者ID:awslabs,項目名稱:aws-media-insights-engine,代碼行數:25,代碼來源:app.py

示例12: list_media_files

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def list_media_files(self, startswith=None, media_type=None, label=None):
        scan_params = {}
        filter_expression = None
        if startswith is not None:
            filter_expression = self._add_to_filter_expression(
                filter_expression, Attr('name').begins_with(startswith)
            )
        if media_type is not None:
            filter_expression = self._add_to_filter_expression(
                filter_expression, Attr('type').eq(media_type)
            )
        if label is not None:
            filter_expression = self._add_to_filter_expression(
                filter_expression, Attr('labels').contains(label)
            )
        if filter_expression:
            scan_params['FilterExpression'] = filter_expression
        response = self._table.scan(**scan_params)
        return response['Items'] 
開發者ID:aws-samples,項目名稱:chalice-workshop,代碼行數:21,代碼來源:db.py

示例13: claim_shard

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def claim_shard(self, shard_id):
        """
        Atomically update the shard in DynamoDB

        :param shard_id:
        :return: bool
        """
        shard_election_logger.info("Claiming shard %s" % shard_id)
        try:
            control_record = self.control_table.get_item(Key={'shard_id': shard_id})['Item']
        except KeyError:
            raise NoItemsReturned()
        control_record['worker_id'] = self.worker_id
        control_record['heartbeat'] = 0
        try:
            self.control_table.put_item(Item=control_record,
                                        ConditionExpression=Attr('shard_id').eq(shard_id) & Attr('checkpoint').eq(control_record['checkpoint'])
                                        # ensure that the record was not changed between the get and put.
                                        )
        except self.dynamodb_client.exceptions.ConditionalCheckFailedException:  # Someone else edited the record
            shard_election_logger.debug("Failed to claim %s to %s" % (shard_id, self.worker_id))
            return False
        return True 
開發者ID:plecto,項目名稱:motorway,代碼行數:25,代碼來源:ramps.py

示例14: putSecret

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def putSecret(name, secret, version="", kms_key="alias/credstash",
              region=None, table="credential-store", context=None,
              digest=DEFAULT_DIGEST, comment="", kms=None, dynamodb=None, 
              kms_region=None, **kwargs):
    '''
    put a secret called `name` into the secret-store,
    protected by the key kms_key
    '''
    if not context:
        context = {}

    if dynamodb is None or kms is None:
        session = get_session(**kwargs)
        if dynamodb is None:
            dynamodb = session.resource('dynamodb', region_name=region)
        if kms is None:
            kms = session.client('kms', region_name=kms_region or region)

    key_service = KeyService(kms, kms_key, context)
    sealed = seal_aes_ctr_legacy(
        key_service,
        secret,
        digest_method=digest,
    )

    secrets = dynamodb.Table(table)

    data = {
        'name': name,
        'version': paddedInt(version),
    }
    if comment:
        data['comment'] = comment
    data.update(sealed)

    return secrets.put_item(Item=data, ConditionExpression=Attr('name').not_exists()) 
開發者ID:fugue,項目名稱:credstash,代碼行數:38,代碼來源:credstash.py

示例15: get_pending_tickets

# 需要導入模塊: from boto3.dynamodb import conditions [as 別名]
# 或者: from boto3.dynamodb.conditions import Attr [as 別名]
def get_pending_tickets():
    table = get_tickets_table()
    cases = table.scan(
        FilterExpression=Attr('limit_type').eq('unknown') & Attr('body').ne('N/A')
    )['Items']
    cases = sorted(cases, key=lambda case: case['display_id'], reverse=True)
    return cases 
開發者ID:Yipit,項目名稱:awslimits,代碼行數:9,代碼來源:support.py


注:本文中的boto3.dynamodb.conditions.Attr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。