mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-10-12 08:24:52 -05:00
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
This commit is contained in:
1 parent
d906fa50c1
commit
092dd8db12
11 files changed
+159
-87
No files matched your search
+4
-2
@@ -20,6 +20,8 @@
|
||||
Encoding capabilities.
|
||||
"""
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
class EncoderSettings(object):
|
||||
"""
|
||||
Container for encoder settings.
|
||||
@@ -77,7 +79,7 @@ class Encoder(object):
|
||||
return self.encoder_settings.encode_postprocessor(
|
||||
var.encode(self.encoder_settings.encode_to)
|
||||
)
|
||||
elif isinstance(var, (bool, float, int, long)):
|
||||
elif isinstance(var, (bool, float, Decimal, int, long)):
|
||||
return self.encoder_settings.encode_postprocessor(
|
||||
str(var).encode(self.encoder_settings.encode_to)
|
||||
)
|
||||
@@ -131,7 +133,7 @@ class Encoder(object):
|
||||
return self.encoder_settings.decode_postprocessor(
|
||||
var.decode(self.encoder_settings.decode_from)
|
||||
)
|
||||
elif isinstance(var, (bool, float, int, long)):
|
||||
elif isinstance(var, (bool, float, Decimal, int, long)):
|
||||
return var
|
||||
elif isinstance(var, list):
|
||||
return [self.decode(m) for m in var]
|
||||
|
||||
Reference in new issue
Block a user