~ubuntu-branches/ubuntu/trusty/python-boto/trusty

« back to all changes in this revision

Viewing changes to boto/dynamodb/batch.py

  • Committer: Package Import Robot
  • Author(s): Eric Evans
  • Date: 2012-04-15 20:21:21 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120415202121-3fpf6q355s0xqpyu
Tags: 2.3.0-1
* New upstream release (Closes: #664478)
* Update debian/watch for Boto's move to Github.  Thanks Scott
  Moser. (Closes: #650480)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
 
2
# Copyright (c) 2012 Amazon.com, Inc. or its affiliates.  All Rights Reserved
 
3
#
 
4
# Permission is hereby granted, free of charge, to any person obtaining a
 
5
# copy of this software and associated documentation files (the
 
6
# "Software"), to deal in the Software without restriction, including
 
7
# without limitation the rights to use, copy, modify, merge, publish, dis-
 
8
# tribute, sublicense, and/or sell copies of the Software, and to permit
 
9
# persons to whom the Software is furnished to do so, subject to the fol-
 
10
# lowing conditions:
 
11
#
 
12
# The above copyright notice and this permission notice shall be included
 
13
# in all copies or substantial portions of the Software.
 
14
#
 
15
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
16
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
 
17
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
 
18
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
 
19
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
20
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
21
# IN THE SOFTWARE.
 
22
#
 
23
 
 
24
class Batch(object):
 
25
    """
 
26
    :ivar table: The Table object from which the item is retrieved.
 
27
 
 
28
    :ivar keys: A list of scalar or tuple values.  Each element in the
 
29
        list represents one Item to retrieve.  If the schema for the
 
30
        table has both a HashKey and a RangeKey, each element in the
 
31
        list should be a tuple consisting of (hash_key, range_key).  If
 
32
        the schema for the table contains only a HashKey, each element
 
33
        in the list should be a scalar value of the appropriate type
 
34
        for the table schema.
 
35
        
 
36
    :ivar attributes_to_get: A list of attribute names.
 
37
        If supplied, only the specified attribute names will
 
38
        be returned.  Otherwise, all attributes will be returned.
 
39
    """
 
40
 
 
41
    def __init__(self, table, keys, attributes_to_get=None):
 
42
        self.table = table
 
43
        self.keys = keys
 
44
        self.attributes_to_get = attributes_to_get
 
45
        
 
46
class BatchList(list):
 
47
    """
 
48
    A subclass of a list object that contains a collection of
 
49
    :class:`boto.dynamodb.batch.Batch` objects.
 
50
    """
 
51
 
 
52
    def __init__(self, layer2):
 
53
        list.__init__(self)
 
54
        self.layer2 = layer2
 
55
 
 
56
    def add_batch(self, table, keys, attributes_to_get=None):
 
57
        """
 
58
        Add a Batch to this BatchList.
 
59
        
 
60
        :type table: :class:`boto.dynamodb.table.Table`
 
61
        :param table: The Table object in which the items are contained.
 
62
 
 
63
        :type keys: list
 
64
        :param keys: A list of scalar or tuple values.  Each element in the
 
65
            list represents one Item to retrieve.  If the schema for the
 
66
            table has both a HashKey and a RangeKey, each element in the
 
67
            list should be a tuple consisting of (hash_key, range_key).  If
 
68
            the schema for the table contains only a HashKey, each element
 
69
            in the list should be a scalar value of the appropriate type
 
70
            for the table schema.
 
71
        
 
72
        :type attributes_to_get: list
 
73
        :param attributes_to_get: A list of attribute names.
 
74
            If supplied, only the specified attribute names will
 
75
            be returned.  Otherwise, all attributes will be returned.
 
76
        """
 
77
        self.append(Batch(table, keys, attributes_to_get))
 
78
 
 
79
    def submit(self):
 
80
        return self.layer2.batch_get_item(self)
 
81
 
 
82
        
 
83