diff options
| author | Petr Viktorin <pviktori@redhat.com> | 2015-09-17 17:56:45 +0200 |
|---|---|---|
| committer | Jan Cholasta <jcholast@redhat.com> | 2015-10-07 10:27:20 +0200 |
| commit | e3c05fcb73c5a1081167d73278785bf18d652dab (patch) | |
| tree | 2e812fea2e20b5808371975da090a829dd5c66f3 /ipapython | |
| parent | 65e3b9edc66d7dfe885df143c16a59588af8192f (diff) | |
| download | freeipa-e3c05fcb73c5a1081167d73278785bf18d652dab.tar.gz freeipa-e3c05fcb73c5a1081167d73278785bf18d652dab.tar.xz freeipa-e3c05fcb73c5a1081167d73278785bf18d652dab.zip | |
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>
Diffstat (limited to 'ipapython')
| -rw-r--r-- | ipapython/ipautil.py | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index 960c9d5ea..b6fd11338 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -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) |
