diff --git a/ipalib/messages.py b/ipalib/messages.py index 5113f3ea4..8567134ac 100644 --- a/ipalib/messages.py +++ b/ipalib/messages.py @@ -50,7 +50,7 @@ def add_message(version, result, message): def process_message_arguments(obj, format=None, message=None, **kw): for key, value in kw.items(): - if not isinstance(value, six.integer_types): + if not isinstance(value, int): try: kw[key] = unicode(value) except UnicodeError: diff --git a/ipalib/parameters.py b/ipalib/parameters.py index 46b77c679..22419723f 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -132,7 +132,7 @@ from ipapython.dnsutil import DNSName def _is_null(value): if value: return False - elif isinstance(value, six.integer_types + (float, decimal.Decimal)): + elif isinstance(value, (int, float, decimal.Decimal)): # 0 is not NULL return False else: @@ -597,7 +597,7 @@ class Param(ReadOnly): value = self.__kw[key] if callable(value) and hasattr(value, '__name__'): value = value.__name__ - elif isinstance(value, six.integer_types): + elif isinstance(value, int): value = str(value) elif isinstance(value, (tuple, set, frozenset)): value = apirepr(list(value)) @@ -1072,7 +1072,7 @@ class Number(Param): """ if type(value) in self.allowed_types: return value - if type(value) in (unicode, float) + six.integer_types: + if type(value) in (unicode, float, int): try: return self.type(value) except ValueError: @@ -1089,12 +1089,12 @@ class Int(Number): """ type = int - allowed_types = six.integer_types + allowed_types = (int,) type_error = _('must be an integer') kwargs = Param.kwargs + ( - ('minvalue', six.integer_types, int(MININT)), - ('maxvalue', six.integer_types, int(MAXINT)), + ('minvalue', int, int(MININT)), + ('maxvalue', int, int(MAXINT)), ) @staticmethod @@ -1138,7 +1138,7 @@ class Int(Number): """ Check min constraint. """ - assert type(value) in six.integer_types + assert isinstance(value, int) if value < self.minvalue: return _('must be at least %(minvalue)d') % dict( minvalue=self.minvalue, @@ -1150,7 +1150,7 @@ class Int(Number): """ Check max constraint. """ - assert type(value) in six.integer_types + assert isinstance(value, int) if value > self.maxvalue: return _('can be at most %(maxvalue)d') % dict( maxvalue=self.maxvalue, @@ -1563,7 +1563,7 @@ class Str(Data): """ if type(value) in self.allowed_types: return value - if type(value) in (float, decimal.Decimal) + six.integer_types: + if type(value) in (int, float, decimal.Decimal): return self.type(value) if type(value) in (tuple, list): raise ConversionError(name=self.name, @@ -1721,7 +1721,7 @@ class IntEnum(Enum): """ type = int - allowed_types = six.integer_types + allowed_types = (int,) type_error = Int.type_error def _convert_scalar(self, value, index=None): diff --git a/ipalib/rpc.py b/ipalib/rpc.py index 685b021e6..410509f50 100644 --- a/ipalib/rpc.py +++ b/ipalib/rpc.py @@ -171,7 +171,7 @@ def xml_wrap(value, version): if type(value) is Decimal: # transfer Decimal as a string return unicode(value) - if isinstance(value, six.integer_types) and (value < MININT or value > MAXINT): + if isinstance(value, int) and (value < MININT or value > MAXINT): return unicode(value) if isinstance(value, DN): return str(value) @@ -200,7 +200,7 @@ def xml_wrap(value, version): return base64.b64encode( value.public_bytes(x509_Encoding.DER)).decode('ascii') - assert type(value) in (unicode, float, bool, type(None)) + six.integer_types + assert type(value) in (unicode, float, int, bool, type(None)) return value @@ -320,6 +320,7 @@ class _JSONPrimer(dict): self.update({ unicode: _identity, bool: _identity, + int: _identity, type(None): _identity, float: _identity, Decimal: unicode, @@ -334,9 +335,6 @@ class _JSONPrimer(dict): crypto_x509.Certificate: self._enc_certificate, crypto_x509.CertificateSigningRequest: self._enc_certificate, }) - # int, long - for t in six.integer_types: - self[t] = _identity def __missing__(self, typ): # walk MRO to find best match diff --git a/ipalib/util.py b/ipalib/util.py index d52fef614..837ae6276 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -86,7 +86,7 @@ def json_serialize(obj): return [json_serialize(o) for o in obj] if isinstance(obj, dict): return {k: json_serialize(v) for (k, v) in obj.items()} - if isinstance(obj, (bool, float, unicode, type(None), six.integer_types)): + if isinstance(obj, (int, bool, float, unicode, type(None))): return obj if isinstance(obj, str): return obj.decode('utf-8') diff --git a/ipapython/cookie.py b/ipapython/cookie.py index 746facc11..0219c0bf0 100644 --- a/ipapython/cookie.py +++ b/ipapython/cookie.py @@ -22,7 +22,6 @@ import datetime import email.utils from calendar import timegm -import six # pylint: disable=import-error from six.moves.urllib.parse import urlparse # pylint: enable=import-error @@ -392,7 +391,7 @@ class Cookie: self._timestamp = None elif isinstance(value, datetime.datetime): self._timestamp = value - elif isinstance(value, (six.integer_types, float)): + elif isinstance(value, (int, float)): self._timestamp = datetime.datetime.utcfromtimestamp(value) elif isinstance(value, str): self._timestamp = Cookie.parse_datetime(value) @@ -418,7 +417,7 @@ class Cookie: self._expires = None elif isinstance(value, datetime.datetime): self._expires = value - elif isinstance(value, (six.integer_types, float)): + elif isinstance(value, (int, float)): self._expires = datetime.datetime.utcfromtimestamp(value) elif isinstance(value, str): self._expires = Cookie.parse_datetime(value) diff --git a/ipapython/dn.py b/ipapython/dn.py index 45aa4458b..1fca45232 100644 --- a/ipapython/dn.py +++ b/ipapython/dn.py @@ -860,7 +860,7 @@ class RDN: return len(self._avas) def __getitem__(self, key): - if isinstance(key, six.integer_types): + if isinstance(key, int): return self._get_ava(self._avas[key]) if isinstance(key, slice): return [self._get_ava(ava) for ava in self._avas[key]] @@ -1178,7 +1178,7 @@ class DN: return len(self.rdns) def __getitem__(self, key): - if isinstance(key, six.integer_types): + if isinstance(key, int): return self._get_rdn(self.rdns[key]) if isinstance(key, slice): cls = self.__class__ diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py index e1c7151da..a35c94c27 100644 --- a/ipapython/ipaldap.py +++ b/ipapython/ipaldap.py @@ -909,8 +909,7 @@ class LDAPClient: return b'TRUE' else: return b'FALSE' - elif isinstance(val, (unicode, six.integer_types, Decimal, DN, - Principal)): + elif isinstance(val, (unicode, int, Decimal, DN, Principal)): return six.text_type(val).encode('utf-8') elif isinstance(val, DNSName): return val.to_text().encode('ascii') diff --git a/ipatests/test_ipalib/test_parameters.py b/ipatests/test_ipalib/test_parameters.py index efe18562e..9bc8b9372 100644 --- a/ipatests/test_ipalib/test_parameters.py +++ b/ipatests/test_ipalib/test_parameters.py @@ -1243,7 +1243,7 @@ class test_Int(ClassChecker): # Test with no kwargs: o = self.cls('my_number') assert o.type == int - assert o.allowed_types == six.integer_types + assert o.allowed_types == (int,) assert isinstance(o, parameters.Int) assert o.minvalue == int(MININT) assert o.maxvalue == int(MAXINT)