Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Changes to convert dynamoDb number type to a python decimal type, to pre... #890

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+7 −13
Split
View
@@ -26,7 +26,8 @@
from boto.dynamodb.schema import Schema
from boto.dynamodb.item import Item
from boto.dynamodb.batch import BatchList, BatchWriteList
-from boto.dynamodb.types import get_dynamodb_type, dynamize_value, convert_num
+from boto.dynamodb.types import get_dynamodb_type, dynamize_value
+from decimal import Decimal
def item_object_hook(dct):
@@ -40,11 +41,11 @@ def item_object_hook(dct):
if 'S' in dct:
return dct['S']
if 'N' in dct:
- return convert_num(dct['N'])
+ return Decimal(dct['N'])
if 'SS' in dct:
return set(dct['SS'])
if 'NS' in dct:
- return set(map(convert_num, dct['NS']))
+ return set(map(Decimal, dct['NS']))
return dct
def table_generator(tgen):
View
@@ -24,25 +24,18 @@
Some utility functions to deal with mapping Amazon DynamoDB types to
Python types and vice-versa.
"""
+from decimal import Decimal
-
+#120717 elee, add Decimal to the list of types recognized as a number.
def is_num(n):
- types = (int, long, float, bool)
+ types = (int, long, float, bool, Decimal)
return isinstance(n, types) or n in types
def is_str(n):
return isinstance(n, basestring) or (isinstance(n, type) and issubclass(n, basestring))
-def convert_num(s):
- if '.' in s:
- n = float(s)
- else:
- n = int(s)
- return n
-
-
def get_dynamodb_type(val):
"""
Take a scalar Python value and return a string representing