[PATCH 04/17] Warn about uses of the string module.
David Shea
dshea at redhat.com
Tue Sep 23 15:26:47 UTC 2014
The string module is about half-deprecated, so we need to be careful
about which parts of it we use. We don't use it too much, so warn about
any use and filter out the correct ones with pylint pragmas.
Remove the uses of string.split, since strings can do that themselves
nowadays and string.split is removed in python3, and string.letters,
since this is also removed in python3 and we actually meant
string.ascii_letters.
---
anaconda | 4 +---
pyanaconda/bootloader.py | 5 +++--
pyanaconda/constants.py | 3 ++-
pyanaconda/iutil.py | 3 ++-
pyanaconda/ui/gui/spokes/network.py | 5 +++--
pyanaconda/users.py | 5 +++--
scripts/instperf | 3 +--
tests/pylint/pylint-one.sh | 1 +
tests/pylint/runpylint.sh | 4 ++++
9 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/anaconda b/anaconda
index f16bce6..19441b4 100755
--- a/anaconda
+++ b/anaconda
@@ -690,7 +690,7 @@ def setupDisplay(anaconda, options, addons=None):
# Only consider vncconnect when vnc is a param
if options.vncconnect:
- cargs = string.split(options.vncconnect, ":")
+ cargs = options.vncconnect.split(":")
vncS.vncconnecthost = cargs[0]
if len(cargs) > 1 and len(cargs[1]) > 0:
if len(cargs[1]) > 0:
@@ -964,8 +964,6 @@ if __name__ == "__main__":
from pyanaconda import isys
- import string
-
from pyanaconda import iutil
iutil.ipmi_report(constants.IPMI_STARTED)
diff --git a/pyanaconda/bootloader.py b/pyanaconda/bootloader.py
index c31c0bf..9370c0a 100644
--- a/pyanaconda/bootloader.py
+++ b/pyanaconda/bootloader.py
@@ -1099,12 +1099,13 @@ class GRUB(BootLoader):
if not self.password:
raise BootLoaderError("cannot encrypt empty password")
- import string
+ # Used for ascii_letters and digits constants
+ import string # pylint: disable=deprecated-module
import crypt
import random
salt = "$6$"
salt_len = 16
- salt_chars = string.letters + string.digits + './'
+ salt_chars = string.ascii_letters + string.digits + './'
rand_gen = random.SystemRandom()
salt += "".join(rand_gen.choice(salt_chars) for i in range(salt_len))
diff --git a/pyanaconda/constants.py b/pyanaconda/constants.py
index e70ae1e..e76b7ee 100644
--- a/pyanaconda/constants.py
+++ b/pyanaconda/constants.py
@@ -19,7 +19,8 @@
# Author(s): Erik Troan <ewt at redhat.com>
#
-import string
+# Used for digits, ascii_letters, punctuation constants
+import string # pylint: disable=deprecated-module
from pyanaconda.i18n import N_
# Use -1 to indicate that the selinux configuration is unset
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index a849df8..a997366 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -27,7 +27,8 @@ import os.path
import errno
import subprocess
import unicodedata
-import string
+# Used for ascii_lowercase, ascii_uppercase constants
+import string # pylint: disable=deprecated-module
import tempfile
import types
import re
diff --git a/pyanaconda/ui/gui/spokes/network.py b/pyanaconda/ui/gui/spokes/network.py
index 50b613e..91b7276 100644
--- a/pyanaconda/ui/gui/spokes/network.py
+++ b/pyanaconda/ui/gui/spokes/network.py
@@ -49,7 +49,8 @@ from gi.repository import GLib, GObject, Pango, Gio, NetworkManager, NMClient
import dbus
import dbus.service
import subprocess
-import string
+# Used for ascii_letters and hexdigits constants
+import string # pylint: disable=deprecated-module
from uuid import uuid4
from dbus.mainloop.glib import DBusGMainLoop
@@ -1325,7 +1326,7 @@ class SecretAgent(dbus.service.Object):
if len(value) in (10, 26):
return all(c in string.hexdigits for c in value)
elif len(value) in (5, 13):
- return all(c in string.letters for c in value)
+ return all(c in string.ascii_letters for c in value)
else:
return False
elif secret['wep_key_type'] == NetworkManager.WepKeyType.PASSPHRASE:
diff --git a/pyanaconda/users.py b/pyanaconda/users.py
index 82cd2d3..b5b076b 100644
--- a/pyanaconda/users.py
+++ b/pyanaconda/users.py
@@ -20,7 +20,8 @@
#
import libuser
-import string
+# Used for ascii_letters and digits constants
+import string # pylint: disable=deprecated-module
import crypt
import random
import tempfile
@@ -115,7 +116,7 @@ def cryptPassword(password, algo=None):
saltstr = salts[algo]
for _i in range(saltlen):
- saltstr = saltstr + random.choice (string.letters +
+ saltstr = saltstr + random.choice (string.ascii_letters +
string.digits + './')
cryptpw = crypt.crypt (password, saltstr)
diff --git a/scripts/instperf b/scripts/instperf
index f0d53b2..daa91a7 100755
--- a/scripts/instperf
+++ b/scripts/instperf
@@ -1,7 +1,6 @@
#!/usr/bin/python
import logging
-from string import split
from subprocess import Popen, PIPE
import time
@@ -12,7 +11,7 @@ import time
def topProcesses():
output = Popen(["ps", "-eo", "comm,rss", "--sort", "-rss", "--no-headers"], stdout=PIPE).communicate()[0]
top5 = output.split("\n")[:5]
- return ",".join(map(lambda (a,b): a+":"+b, map(split, top5)))
+ return ",".join("%s:%s" % (proc[0], proc[1]) for proc in (s.split() for s in top5))
def logit():
buffers = 0
diff --git a/tests/pylint/pylint-one.sh b/tests/pylint/pylint-one.sh
index 8cf4248..5f6ac01 100755
--- a/tests/pylint/pylint-one.sh
+++ b/tests/pylint/pylint-one.sh
@@ -24,6 +24,7 @@ pylint_output="$(pylint \
gi.overrides.__path__[0:0] = (os.environ["ANACONDA_WIDGETS_OVERRIDES"].split(":") if "ANACONDA_WIDGETS_OVERRIDES" in os.environ else [])' \
$DISABLED_WARN_OPTIONS \
$DISABLED_ERR_OPTIONS \
+ $EXTRA_OPTIONS \
$NON_STRICT_OPTIONS "$@" 2>&1 | \
egrep -v -f "$FALSE_POSITIVES" \
)"
diff --git a/tests/pylint/runpylint.sh b/tests/pylint/runpylint.sh
index a76b4c1..c2a9393 100755
--- a/tests/pylint/runpylint.sh
+++ b/tests/pylint/runpylint.sh
@@ -77,6 +77,10 @@ export DISABLED_ERR_OPTIONS="--disable=E1103"
# I0013 - Ignoring entire file (i.e., pylint: skip-file)
export DISABLED_WARN_OPTIONS="--disable=W0110,W0123,W0141,W0142,W0511,W0603,W0613,W0614,I0011,I0012,I0013"
+# string is about half-deprecated, so add it to the list of deprecated modules
+# and handle the valid cases with pragma comments.
+export EXTRA_OPTIONS="--deprecated-modules=string,regsub,TERMIOS,Bastion,rexec"
+
usage () {
echo "usage: `basename $0` [--strict] [--help] [files...]"
exit $1
--
2.1.0
More information about the anaconda-patches
mailing list