From 092dd8db1293599a4b7f0ab33ea43e8082ec554f Mon Sep 17 00:00:00 2001 From: Martin Kosek Date: Tue, 17 Jan 2012 11:19:00 +0100 Subject: Replace float with Decimal Having float type as a base type for floating point parameters in ipalib introduces several issues, e.g. problem with representation or value comparison. Python language provides a Decimal type which help overcome these issues. This patch replaces a float type and Float parameter with a decimal.Decimal type in Decimal parameter. A precision attribute was added to Decimal parameter that can be used to limit a number of decimal places in parameter representation. This approach fixes a problem with API.txt validation where comparison of float values may fail on different architectures due to float representation error. In order to safely transfer the parameter value over RPC it is being converted to string which is then converted back to decimal.Decimal number on a server side. https://fedorahosted.org/freeipa/ticket/2260 --- ipaserver/rpcserver.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ipaserver/rpcserver.py') diff --git a/ipaserver/rpcserver.py b/ipaserver/rpcserver.py index 26850db5..955c11b7 100644 --- a/ipaserver/rpcserver.py +++ b/ipaserver/rpcserver.py @@ -37,6 +37,7 @@ from ipapython.version import VERSION import base64 import os import string +from decimal import Decimal _not_found_template = """ 404 Not Found @@ -385,6 +386,8 @@ def json_encode_binary(val): return new_list elif isinstance(val, str): return {'__base64__' : base64.b64encode(val)} + elif isinstance(val, Decimal): + return {'__base64__' : base64.b64encode(str(val))} else: return val -- cgit