/usr/share/pyshared/boto/dynamodb/item.py is in python-boto 2.2.2-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | # Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
class Item(dict):
"""
An item in Amazon DynamoDB.
:ivar hash_key: The HashKey of this item.
:ivar range_key: The RangeKey of this item or None if no RangeKey
is defined.
:ivar hash_key_name: The name of the HashKey associated with this item.
:ivar range_key_name: The name of the RangeKey associated with this item.
:ivar table: The Table this item belongs to.
"""
def __init__(self, table, hash_key=None, range_key=None, attrs=None):
self.table = table
self._hash_key_name = self.table.schema.hash_key_name
self._range_key_name = self.table.schema.range_key_name
if hash_key:
self[self._hash_key_name] = hash_key
if range_key:
self[self._range_key_name] = range_key
if attrs:
self.update(attrs)
self.consumed_units = 0
self._updates = {}
@property
def hash_key(self):
return self[self._hash_key_name]
@property
def range_key(self):
return self.get(self._range_key_name)
@property
def hash_key_name(self):
return self._hash_key_name
@property
def range_key_name(self):
return self._range_key_name
def add_attribute(self, attr_name, attr_value):
"""
Queue the addition of an attribute to an item in DynamoDB.
This will eventually result in an UpdateItem request being issued
with an update action of ADD when the save method is called.
:type attr_name: str
:param attr_name: Name of the attribute you want to alter.
:type attr_value: int|long|float|set
:param attr_value: Value which is to be added to the attribute.
"""
self._updates[attr_name] = ("ADD", attr_value)
def delete_attribute(self, attr_name, attr_value=None):
"""
Queue the deletion of an attribute from an item in DynamoDB.
This call will result in a UpdateItem request being issued
with update action of DELETE when the save method is called.
:type attr_name: str
:param attr_name: Name of the attribute you want to alter.
:type attr_value: set
:param attr_value: A set of values to be removed from the attribute.
This parameter is optional. If None, the whole attribute is
removed from the item.
"""
self._updates[attr_name] = ("DELETE", attr_value)
def put_attribute(self, attr_name, attr_value):
"""
Queue the putting of an attribute to an item in DynamoDB.
This call will result in an UpdateItem request being issued
with the update action of PUT when the save method is called.
:type attr_name: str
:param attr_name: Name of the attribute you want to alter.
:type attr_value: int|long|float|str|set
:param attr_value: New value of the attribute.
"""
self._updates[attr_name] = ("PUT", attr_value)
def save(self, expected_value=None, return_values=None):
"""
Commits pending updates to Amazon DynamoDB.
:type expected_value: dict
:param expected_value: A dictionary of name/value pairs that
you expect. This dictionary should have name/value pairs
where the name is the name of the attribute and the value is
either the value you are expecting or False if you expect
the attribute not to exist.
:type return_values: str
:param return_values: Controls the return of attribute name/value pairs
before they were updated. Possible values are: None, 'ALL_OLD',
'UPDATED_OLD', 'ALL_NEW' or 'UPDATED_NEW'. If 'ALL_OLD' is
specified and the item is overwritten, the content of the old item
is returned. If 'ALL_NEW' is specified, then all the attributes of
the new version of the item are returned. If 'UPDATED_NEW' is
specified, the new versions of only the updated attributes are
returned.
"""
return self.table.layer2.update_item(self, expected_value,
return_values)
def delete(self, expected_value=None, return_values=None):
"""
Delete the item from DynamoDB.
:type expected_value: dict
:param expected_value: A dictionary of name/value pairs that you expect.
This dictionary should have name/value pairs where the name
is the name of the attribute and the value is either the value
you are expecting or False if you expect the attribute not to
exist.
:type return_values: str
:param return_values: Controls the return of attribute
name-value pairs before then were changed. Possible
values are: None or 'ALL_OLD'. If 'ALL_OLD' is
specified and the item is overwritten, the content
of the old item is returned.
"""
return self.table.layer2.delete_item(self, expected_value,
return_values)
def put(self, expected_value=None, return_values=None):
"""
Store a new item or completely replace an existing item
in Amazon DynamoDB.
:type expected_value: dict
:param expected_value: A dictionary of name/value pairs that you expect.
This dictionary should have name/value pairs where the name
is the name of the attribute and the value is either the value
you are expecting or False if you expect the attribute not to
exist.
:type return_values: str
:param return_values: Controls the return of attribute
name-value pairs before then were changed. Possible
values are: None or 'ALL_OLD'. If 'ALL_OLD' is
specified and the item is overwritten, the content
of the old item is returned.
"""
return self.table.layer2.put_item(self, expected_value, return_values)
|