mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Remove uses of the types module
In Python 3, the types module no longer provide alternate names for built-in types, e.g. `types.StringType` can just be spelled `str`. NoneType is also removed; it needs to be replaced with type(None) Reviewed-By: David Kupka <dkupka@redhat.com> Reviewed-By: Jan Cholasta <jcholast@redhat.com> Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
committed by
Jan Cholasta
parent
65e3b9edc6
commit
e3c05fcb73
@@ -29,7 +29,6 @@ of the process.
|
||||
For the per-request thread-local information, see `ipalib.request`.
|
||||
"""
|
||||
|
||||
from types import NoneType
|
||||
import os
|
||||
from os import path
|
||||
import sys
|
||||
@@ -259,7 +258,7 @@ class Env(object):
|
||||
value = int(value)
|
||||
elif key == 'basedn':
|
||||
value = DN(value)
|
||||
assert type(value) in (unicode, int, float, bool, NoneType, DN)
|
||||
assert type(value) in (unicode, int, float, bool, type(None), DN)
|
||||
object.__setattr__(self, key, value)
|
||||
self.__d[key] = value
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ Simple description of return values.
|
||||
"""
|
||||
|
||||
from inspect import getdoc
|
||||
from types import NoneType
|
||||
|
||||
import six
|
||||
|
||||
@@ -120,7 +119,7 @@ class PrimaryKey(Output):
|
||||
types = cmd.obj.primary_key.allowed_types
|
||||
else:
|
||||
types = (unicode,)
|
||||
types = types + (NoneType,)
|
||||
types = types + (type(None),)
|
||||
else:
|
||||
types = (unicode,)
|
||||
if not isinstance(value, types):
|
||||
@@ -157,7 +156,7 @@ class ListOfPrimaryKeys(Output):
|
||||
|
||||
result = Output('result', doc=_('All commands should at least have a result'))
|
||||
|
||||
summary = Output('summary', (unicode, NoneType),
|
||||
summary = Output('summary', (unicode, type(None)),
|
||||
_('User-friendly description of action performed')
|
||||
)
|
||||
|
||||
|
||||
@@ -104,7 +104,6 @@ import decimal
|
||||
import base64
|
||||
import datetime
|
||||
from six.moves.xmlrpc_client import MAXINT, MININT
|
||||
from types import NoneType
|
||||
import encodings.idna
|
||||
|
||||
import dns.name
|
||||
@@ -126,6 +125,7 @@ def _is_null(value):
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
|
||||
|
||||
class DefaultFrom(ReadOnly):
|
||||
"""
|
||||
Derive a default value from other supplied values.
|
||||
@@ -384,7 +384,7 @@ class Param(ReadOnly):
|
||||
# (direct) subclass must *always* override this class attribute.
|
||||
# If multiple types are permitted, set `type` to the canonical type and
|
||||
# `allowed_types` to a tuple of all allowed types.
|
||||
type = NoneType # Ouch, this wont be very useful in the real world!
|
||||
type = type(None) # Ouch, this wont be very useful in the real world!
|
||||
|
||||
# Subclasses should override this with something more specific:
|
||||
type_error = _('incorrect type')
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
from ipalib import api, errors, output, util
|
||||
from ipalib import Command, Str, Flag, Int, DeprecatedParam
|
||||
from types import NoneType
|
||||
from ipalib.cli import to_cli
|
||||
from ipalib import _, ngettext
|
||||
from ipapython.dn import DN
|
||||
@@ -250,10 +249,10 @@ class hbactest(Command):
|
||||
|
||||
has_output = (
|
||||
output.summary,
|
||||
output.Output('warning', (list, tuple, NoneType), _('Warning')),
|
||||
output.Output('matched', (list, tuple, NoneType), _('Matched rules')),
|
||||
output.Output('notmatched', (list, tuple, NoneType), _('Not matched rules')),
|
||||
output.Output('error', (list, tuple, NoneType), _('Non-existent or invalid rules')),
|
||||
output.Output('warning', (list, tuple, type(None)), _('Warning')),
|
||||
output.Output('matched', (list, tuple, type(None)), _('Matched rules')),
|
||||
output.Output('notmatched', (list, tuple, type(None)), _('Not matched rules')),
|
||||
output.Output('error', (list, tuple, type(None)), _('Non-existent or invalid rules')),
|
||||
output.Output('value', bool, _('Result of simulation'), ['no_display']),
|
||||
)
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ For documentation on the ``xmlrpclib`` module, see:
|
||||
Also see the `ipaserver.rpcserver` module.
|
||||
"""
|
||||
|
||||
from types import NoneType
|
||||
from decimal import Decimal
|
||||
import sys
|
||||
import datetime
|
||||
@@ -194,7 +193,7 @@ def xml_wrap(value, version):
|
||||
else:
|
||||
return unicode(value)
|
||||
|
||||
assert type(value) in (unicode, float, bool, NoneType) + six.integer_types
|
||||
assert type(value) in (unicode, float, bool, type(None)) + six.integer_types
|
||||
return value
|
||||
|
||||
|
||||
@@ -233,7 +232,7 @@ def xml_unwrap(value, encoding='UTF-8'):
|
||||
if isinstance(value, DateTime):
|
||||
# xmlprc DateTime is converted to string of %Y%m%dT%H:%M:%S format
|
||||
return datetime.datetime.strptime(str(value), "%Y%m%dT%H:%M:%S")
|
||||
assert type(value) in (unicode, int, float, bool, NoneType)
|
||||
assert type(value) in (unicode, int, float, bool, type(None))
|
||||
return value
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import re
|
||||
import decimal
|
||||
import dns
|
||||
import encodings
|
||||
from types import NoneType
|
||||
from weakref import WeakKeyDictionary
|
||||
|
||||
import netaddr
|
||||
@@ -55,7 +54,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, NoneType, six.integer_types)):
|
||||
if isinstance(obj, (bool, float, unicode, type(None), six.integer_types)):
|
||||
return obj
|
||||
if isinstance(obj, str):
|
||||
return obj.decode('utf-8')
|
||||
|
||||
@@ -29,7 +29,6 @@ import stat
|
||||
import shutil
|
||||
import socket
|
||||
import struct
|
||||
from types import *
|
||||
import re
|
||||
import datetime
|
||||
import netaddr
|
||||
@@ -426,18 +425,18 @@ def backup_file(fname):
|
||||
if file_exists(fname):
|
||||
os.rename(fname, fname + ".orig")
|
||||
|
||||
def _ensure_nonempty_string(string, message):
|
||||
if not isinstance(string, str) or not string:
|
||||
raise ValueError(message)
|
||||
|
||||
# uses gpg to compress and encrypt a file
|
||||
def encrypt_file(source, dest, password, workdir = None):
|
||||
if type(source) is not StringType or not len(source):
|
||||
raise ValueError('Missing Source File')
|
||||
_ensure_nonempty_string(source, 'Missing Source File')
|
||||
#stat it so that we get back an exception if it does no t exist
|
||||
os.stat(source)
|
||||
|
||||
if type(dest) is not StringType or not len(dest):
|
||||
raise ValueError('Missing Destination File')
|
||||
|
||||
if type(password) is not StringType or not len(password):
|
||||
raise ValueError('Missing Password')
|
||||
_ensure_nonempty_string(dest, 'Missing Destination File')
|
||||
_ensure_nonempty_string(password, 'Missing Password')
|
||||
|
||||
#create a tempdir so that we can clean up with easily
|
||||
tempdir = tempfile.mkdtemp('', 'ipa-', workdir)
|
||||
@@ -458,16 +457,12 @@ def encrypt_file(source, dest, password, workdir = None):
|
||||
|
||||
|
||||
def decrypt_file(source, dest, password, workdir = None):
|
||||
if type(source) is not StringType or not len(source):
|
||||
raise ValueError('Missing Source File')
|
||||
_ensure_nonempty_string(source, 'Missing Source File')
|
||||
#stat it so that we get back an exception if it does no t exist
|
||||
os.stat(source)
|
||||
|
||||
if type(dest) is not StringType or not len(dest):
|
||||
raise ValueError('Missing Destination File')
|
||||
|
||||
if type(password) is not StringType or not len(password):
|
||||
raise ValueError('Missing Password')
|
||||
_ensure_nonempty_string(dest, 'Missing Destination File')
|
||||
_ensure_nonempty_string(password, 'Missing Password')
|
||||
|
||||
#create a tempdir so that we can clean up with easily
|
||||
tempdir = tempfile.mkdtemp('', 'ipa-', workdir)
|
||||
|
||||
@@ -28,7 +28,6 @@ Test the `ipalib.parameters` module.
|
||||
import datetime
|
||||
import re
|
||||
import sys
|
||||
from types import NoneType
|
||||
from decimal import Decimal
|
||||
from inspect import isclass
|
||||
from six.moves.xmlrpc_client import MAXINT, MININT
|
||||
@@ -480,10 +479,10 @@ class test_Param(ClassChecker):
|
||||
|
||||
# Test with wrong (scalar) type:
|
||||
e = raises(TypeError, o.validate, (None, None, 42, None), 'cli')
|
||||
assert str(e) == TYPE_ERROR % ('my_param', NoneType, 42, int)
|
||||
assert str(e) == TYPE_ERROR % ('my_param', type(None), 42, int)
|
||||
o = self.cls('my_param')
|
||||
e = raises(TypeError, o.validate, 'Hello', 'cli')
|
||||
assert str(e) == TYPE_ERROR % ('my_param', NoneType, 'Hello', str)
|
||||
assert str(e) == TYPE_ERROR % ('my_param', type(None), 'Hello', str)
|
||||
|
||||
class Example(self.cls):
|
||||
type = int
|
||||
@@ -650,7 +649,7 @@ class test_Flag(ClassChecker):
|
||||
|
||||
# Test that TypeError is raise if default is not a bool:
|
||||
e = raises(TypeError, self.cls, 'my_flag', default=None)
|
||||
assert str(e) == TYPE_ERROR % ('default', bool, None, NoneType)
|
||||
assert str(e) == TYPE_ERROR % ('default', bool, None, type(None))
|
||||
|
||||
# Test with autofill=False, default=True
|
||||
o = self.cls('my_flag', autofill=False, default=True)
|
||||
@@ -685,7 +684,7 @@ class test_Data(ClassChecker):
|
||||
Test the `ipalib.parameters.Data.__init__` method.
|
||||
"""
|
||||
o = self.cls('my_data')
|
||||
assert o.type is NoneType
|
||||
assert o.type is type(None)
|
||||
assert o.password is False
|
||||
assert o.rules == tuple()
|
||||
assert o.class_rules == tuple()
|
||||
@@ -1231,7 +1230,7 @@ class test_Number(ClassChecker):
|
||||
Test the `ipalib.parameters.Number.__init__` method.
|
||||
"""
|
||||
o = self.cls('my_number')
|
||||
assert o.type is NoneType
|
||||
assert o.type is type(None)
|
||||
assert o.password is False
|
||||
assert o.rules == tuple()
|
||||
assert o.class_rules == tuple()
|
||||
|
||||
@@ -24,7 +24,6 @@ Test the `ipalib/plugins/hbactest.py` module.
|
||||
from ipatests.test_xmlrpc.xmlrpc_test import XMLRPC_test, assert_attr_equal
|
||||
from ipalib import api
|
||||
from ipalib import errors
|
||||
from types import NoneType
|
||||
from nose.tools import raises
|
||||
|
||||
# Test strategy:
|
||||
@@ -114,7 +113,7 @@ class test_hbactest(XMLRPC_test):
|
||||
rules=self.rule_names
|
||||
)
|
||||
assert ret['value'] == True
|
||||
assert type(ret['error']) == NoneType
|
||||
assert ret['error'] is None
|
||||
for i in [0,1,2,3]:
|
||||
assert self.rule_names[i] in ret['matched']
|
||||
|
||||
|
||||
3
setup.py
3
setup.py
@@ -27,7 +27,6 @@ from distutils.core import setup
|
||||
from distutils.command.install_data import install_data as _install_data
|
||||
from distutils.util import change_root, convert_path
|
||||
from distutils import log
|
||||
from types import StringType
|
||||
import ipalib
|
||||
import os
|
||||
|
||||
@@ -43,7 +42,7 @@ class install_data(_install_data):
|
||||
|
||||
# Now gzip them
|
||||
for f in self.data_files:
|
||||
if type(f) is StringType:
|
||||
if isinstance(f, str):
|
||||
# it's a simple file
|
||||
f = convert_path(f)
|
||||
cmd = '/bin/gzip %s/%s' % (self.install_dir, f)
|
||||
|
||||
Reference in New Issue
Block a user