@classmethod<EOL><INDENT>def update_item(cls, hash_key, range_key=None, attributes_to_set=None, attributes_to_add=None):<DEDENT>
primary_key = cls._encode_key(hash_key, range_key)<EOL>value_names = {}<EOL>encoded_values = {}<EOL>dynamizer = Dynamizer()<EOL>set_expression = '<STR_LIT>'<EOL>if attributes_to_set:<EOL><INDENT>for i, key in enumerate(attributes_to_set.keys()):<EOL><INDENT>value_name = '<STR_LIT>'.format(i)<EOL>value_names[key] = value_name<EOL>encoded_values[value_name] = dynamizer.encode(attributes_to_set[key])<EOL><DEDENT>set_expression = '<STR_LIT>'.format(<EOL>'<STR_LIT:U+002CU+0020>'.join(<EOL>'<STR_LIT>'.format(key=key, value_name=value_names[key]) for key in attributes_to_set<EOL>)<EOL>)<EOL><DEDENT>add_expression = '<STR_LIT>'<EOL>if attributes_to_add:<EOL><INDENT>for i, key in enumerate(attributes_to_add.keys()):<EOL><INDENT>value_name = '<STR_LIT>'.format(i)<EOL>value_names[key] = value_name<EOL>encoded_values[value_name] = dynamizer.encode(attributes_to_add[key])<EOL><DEDENT>add_expression = '<STR_LIT>'.format(<EOL>'<STR_LIT:U+002CU+0020>'.join(<EOL>'<STR_LIT>'.format(key=key, value_name=value_names[key]) for key in attributes_to_add<EOL>)<EOL>)<EOL><DEDENT>update_expression = '<STR_LIT:U+0020>'.join([set_expression, add_expression])<EOL>cls._get_connection().update_item(<EOL>cls.get_table_name(),<EOL>primary_key,<EOL>update_expression=update_expression, expression_attribute_values=encoded_values)<EOL>
Update item attributes. Currently SET and ADD actions are supported.