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
This commit is contained in:
Martin Kosek
2012-09-04 15:49:26 +02:00
parent 71f9008906
commit cfbea2a99e
2 changed files with 11 additions and 8 deletions

View File

@@ -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,

View File

@@ -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