[blivet:master 2/4] Use range instead of xrange in generateBackupPassphrase()
mulhern
amulhern at redhat.com
Tue Jul 8 13:55:57 UTC 2014
There is no real gain to using xrange in Python 2 and in Python 3 range is
a generator anyway.
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/devicelibs/crypto.py | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/blivet/devicelibs/crypto.py b/blivet/devicelibs/crypto.py
index 0f38ff9..b911e94 100644
--- a/blivet/devicelibs/crypto.py
+++ b/blivet/devicelibs/crypto.py
@@ -22,7 +22,6 @@
import random
from pycryptsetup import CryptSetup
-from six.moves import xrange
from ..errors import CryptoError
from ..size import Size
@@ -39,14 +38,12 @@ GENERATED_PASSPHRASE_CHARSET = ("0123456789"
GENERATED_PASSPHRASE_LENGTH = 20
def generateBackupPassphrase():
- raw = ""
- for i in xrange(GENERATED_PASSPHRASE_LENGTH):
- raw += random.choice(GENERATED_PASSPHRASE_CHARSET)
+ raw = [random.choice(GENERATED_PASSPHRASE_CHARSET) for _ in range(GENERATED_PASSPHRASE_LENGTH)]
- # Make the result easier to read
+ # Insert a '-' after every five char chunk for easier reading
parts = []
- for i in xrange(0, len(raw), 5):
- parts.append(raw[i : i + 5])
+ for i in range(0, GENERATED_PASSPHRASE_LENGTH, 5):
+ parts.append(''.join(raw[i : i + 5]))
return "-".join(parts)
yesDialog = lambda q: True
--
1.9.3
More information about the anaconda-patches
mailing list