From b2cb2e3da13bc9303b1cd50fcbb6b93b16cd0ae7 Mon Sep 17 00:00:00 2001 From: Martin Kosek Date: Tue, 4 Sep 2012 15:49:26 +0200 Subject: Transfer long numbers over XMLRPC Numeric parameters in ipalib were limited by XMLRPC boundaries for integer (2^31-1) which is too low for some LDAP attributes like DNS SOA serial field. Transfer numbers which are not in XMLRPC boundary as a string and not as a number to workaround this limitation. Int parameter had to be updated to also accept Python's long type as valid int type. https://fedorahosted.org/freeipa/ticket/2568 --- ipalib/parameters.py | 12 ++++++------ ipalib/rpc.py | 7 +++++-- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'ipalib') diff --git a/ipalib/parameters.py b/ipalib/parameters.py index e839a0e7..13f04b45 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -1078,7 +1078,7 @@ class Number(Param): """ if type(value) is self.type: return value - if type(value) in (unicode, int, float): + if type(value) in (unicode, int, long, float): try: return self.type(value) except ValueError: @@ -1100,8 +1100,8 @@ class Int(Number): type_error = _('must be an integer') kwargs = Param.kwargs + ( - ('minvalue', int, int(MININT)), - ('maxvalue', int, int(MAXINT)), + ('minvalue', (int, long), int(MININT)), + ('maxvalue', (int, long), int(MAXINT)), ) def __init__(self, name, *rules, **kw): @@ -1148,7 +1148,7 @@ class Int(Number): Check min constraint. """ assert type(value) in (int, long) - if value < self.minvalue or value < MININT: + if value < self.minvalue: return _('must be at least %(minvalue)d') % dict( minvalue=self.minvalue, ) @@ -1158,7 +1158,7 @@ class Int(Number): Check max constraint. """ assert type(value) in (int, long) - if value > self.maxvalue or value > MAXINT: + if value > self.maxvalue: return _('can be at most %(maxvalue)d') % dict( maxvalue=self.maxvalue, ) @@ -1491,7 +1491,7 @@ class Str(Data): """ if type(value) is self.type: return value - if type(value) in (int, float, decimal.Decimal): + if type(value) in (int, long, float, decimal.Decimal): return self.type(value) if type(value) in (tuple, list): raise ConversionError(name=self.name, index=index, diff --git a/ipalib/rpc.py b/ipalib/rpc.py index d1764e3e..fc135f4f 100644 --- a/ipalib/rpc.py +++ b/ipalib/rpc.py @@ -37,7 +37,8 @@ import sys import os import errno import locale -from xmlrpclib import Binary, Fault, dumps, loads, ServerProxy, Transport, ProtocolError +from xmlrpclib import (Binary, Fault, dumps, loads, ServerProxy, Transport, + ProtocolError, MININT, MAXINT) import kerberos from dns import resolver, rdatatype from dns.exception import DNSException @@ -94,9 +95,11 @@ def xml_wrap(value): if type(value) is Decimal: # transfer Decimal as a string return unicode(value) + if isinstance(value, (int, long)) and (value < MININT or value > MAXINT): + return unicode(value) if isinstance(value, DN): return str(value) - assert type(value) in (unicode, int, float, bool, NoneType) + assert type(value) in (unicode, int, long, float, bool, NoneType) return value -- cgit