bring dynamodb2 update expression handling closer to spec

This commit is contained in:
Peter Gorniak 2016-11-25 21:07:24 -08:00
parent c3c6eaf281
commit 5a7c711a74

View File

@ -3,6 +3,7 @@ from collections import defaultdict
import datetime
import decimal
import json
import re
from moto.compat import OrderedDict
from moto.core import BaseBackend
@ -110,15 +111,10 @@ class Item(object):
}
def update(self, update_expression, expression_attribute_names, expression_attribute_values):
ACTION_VALUES = ['SET', 'set', 'REMOVE', 'remove']
action = None
for value in update_expression.split():
if value in ACTION_VALUES:
# An action
action = value
continue
else:
parts = [p for p in re.split(r'\b(SET|REMOVE|ADD|DELETE)\b', update_expression) if p]
for action, valstr in zip(parts[:-1:1], parts[1::1]):
values = valstr.split(',')
for value in values:
# A Real value
value = value.lstrip(":").rstrip(",")
for k, v in expression_attribute_names.items():
@ -127,6 +123,8 @@ class Item(object):
self.attrs.pop(value, None)
elif action == 'SET' or action == 'set':
key, value = value.split("=")
key = key.strip()
value = value.strip()
if value in expression_attribute_values:
self.attrs[key] = DynamoType(expression_attribute_values[value])
else: