1. Curtis Maloney
  2. gnocchi-ajax

Commits

funkybob  committed e29cbed

Fixed encoding of Decimals

  • Participants
  • Parent commits ad741bf
  • Branches default

Comments (0)

Files changed (1)

File gnocchi/ajax/serialiser.py

View file
     '''
     def encode(self, obj):
 
-        #Define these two inline for minor speed gains
-        def _encode_float(obj):
-            if obj != obj:
-                return 'NaN'
-            elif obj == INFINITY:
-                return 'Infinity'
-            elif obj == -INFINITY:
-                return '-Infinity'
-            else:
-                return repr(obj)
-
         def _encode(obj):
             FIRST_SEP = ['']
             NEXT_SEP = ','
             elif obj is False:
                 yield 'false'
             elif isinstance(obj, (int, long)):
-                yield str(obj)
+                yield unicode(obj)
             elif isinstance(obj, float):
-                yield _encode_float(obj)
+                if obj != obj:
+                    yield 'NaN'
+                elif obj == INFINITY:
+                    yield 'Infinity'
+                elif obj == -INFINITY:
+                    yield '-Infinity'
+                else:
+                    yield unicode(obj)
             elif isinstance(obj, Decimal):
-                yield _encode_float(float(obj))
+                yield unicode(Decimal)
             elif isinstance(obj, datetime.datetime):
                 yield '"'+obj.replace(microsecond=0).isoformat(' ')+'"'
             elif isinstance(obj, datetime.date):