[master 10/30] Addapt to string type changes (#1014220)
M4rtinK
installerbot-noreply at redhat.com
Mon Jun 1 14:04:27 UTC 2015
From: Martin Kolman <mkolman at redhat.com>
StringTypes is now str, UnicodeType is also str and StringType is bytes.
---
pyanaconda/anaconda_argparse.py | 3 +--
pyanaconda/anaconda_log.py | 3 +--
pyanaconda/flags.py | 3 +--
pyanaconda/iutil.py | 12 ++++++------
pyanaconda/nm.py | 2 +-
pyanaconda/ui/gui/spokes/keyboard.py | 2 +-
pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py | 2 +-
pyanaconda/ui/gui/utils.py | 2 +-
pyanaconda/ui/tui/__init__.py | 4 ++--
pyanaconda/ui/tui/hubs/__init__.py | 2 +-
pyanaconda/ui/tui/simpleline/base.py | 3 +--
pyanaconda/ui/tui/simpleline/widgets.py | 6 +++---
pyanaconda/ui/tui/spokes/__init__.py | 2 +-
pyanaconda/ui/tui/tuiobject.py | 2 +-
tests/pyanaconda_tests/iutil_test.py | 2 +-
tests/pylint/markup.py | 3 +--
16 files changed, 24 insertions(+), 29 deletions(-)
diff --git a/pyanaconda/anaconda_argparse.py b/pyanaconda/anaconda_argparse.py
index a70365f..03f88e4 100644
--- a/pyanaconda/anaconda_argparse.py
+++ b/pyanaconda/anaconda_argparse.py
@@ -28,7 +28,6 @@
import sys
import fcntl
import termios
-import types
import struct
from argparse import ArgumentParser, ArgumentError, HelpFormatter, Namespace
@@ -179,7 +178,7 @@ def parse_boot_cmdline(self, boot_cmdline):
:rtype: Namespace
"""
namespace = Namespace()
- if boot_cmdline is None or isinstance(boot_cmdline, types.StringType):
+ if boot_cmdline is None or isinstance(boot_cmdline, str):
bootargs = BootArgs(boot_cmdline)
else:
bootargs = boot_cmdline
diff --git a/pyanaconda/anaconda_log.py b/pyanaconda/anaconda_log.py
index 7012167..c11c563 100644
--- a/pyanaconda/anaconda_log.py
+++ b/pyanaconda/anaconda_log.py
@@ -26,7 +26,6 @@
from logging.handlers import SysLogHandler, SocketHandler, SYSLOG_UDP_PORT
import os
import sys
-import types
import warnings
from pyanaconda.flags import flags
@@ -170,7 +169,7 @@ def addFileHandler(self, dest, addToLogger, minLevel=DEFAULT_LEVEL,
fmtStr=ENTRY_FORMAT,
autoLevel=False):
try:
- if isinstance(dest, types.StringTypes):
+ if isinstance(dest, str):
logfileHandler = logging.FileHandler(dest)
else:
logfileHandler = logging.StreamHandler(dest)
diff --git a/pyanaconda/flags.py b/pyanaconda/flags.py
index c817234..81319dc 100644
--- a/pyanaconda/flags.py
+++ b/pyanaconda/flags.py
@@ -19,7 +19,6 @@
import selinux
import shlex
-import types
import glob
from pyanaconda.constants import SELINUX_DEFAULT, CMDLINE_APPEND
from collections import OrderedDict
@@ -114,7 +113,7 @@ def read(self, filenames):
filenames can contain *, ?, and character ranges expressed with []
"""
readfiles = []
- if isinstance(filenames, types.StringType):
+ if isinstance(filenames, str):
filenames = [filenames]
# Expand any filename globs
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index 1d50ab6..832f41a 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -955,10 +955,10 @@ def strip_accents(s):
and returns it with all the diacritics removed.
:param s: arbitrary string
- :type s: unicode
+ :type s: str
:return: s with diacritics removed
- :rtype: unicode
+ :rtype: str
"""
return ''.join((c for c in unicodedata.normalize('NFD', s)
@@ -1109,14 +1109,14 @@ def ensure_str(str_or_bytes, keep_none=True):
def _toASCII(s):
"""Convert a unicode string to ASCII"""
- if isinstance(s, types.UnicodeType):
+ if isinstance(s, str):
# Decompose the string using the NFK decomposition, which in addition
# to the canonical decomposition replaces characters based on
# compatibility equivalence (e.g., ROMAN NUMERAL ONE has its own code
# point but it's really just a capital I), so that we can keep as much
# of the ASCII part of the string as possible.
s = unicodedata.normalize('NFKD', s).encode('ascii', 'ignore').decode("ascii")
- elif type(s) != bytes:
+ elif not isinstance(s, bytes):
s = ''
return s
@@ -1153,9 +1153,9 @@ def upcase_first_letter(text):
lowercases all the others. string.title() capitalizes all words in the
string.
- :type text: either a str or unicode object
+ :type text: str
:return: the given text with the first letter upcased
- :rtype: str or unicode (depends on the input)
+ :rtype: str
"""
diff --git a/pyanaconda/nm.py b/pyanaconda/nm.py
index f0d0243..4266667 100644
--- a/pyanaconda/nm.py
+++ b/pyanaconda/nm.py
@@ -987,7 +987,7 @@ def _gvariant_settings(settings, updated_key1, updated_key2, value, default_type
# infer the new value type for string and boolean
if isinstance(value, types.BooleanType):
type_str = 'b'
- elif isinstance(value, types.StringType):
+ elif isinstance(value, str):
type_str = 's'
if type_str is not None:
diff --git a/pyanaconda/ui/gui/spokes/keyboard.py b/pyanaconda/ui/gui/spokes/keyboard.py
index fda111f..67af39d 100644
--- a/pyanaconda/ui/gui/spokes/keyboard.py
+++ b/pyanaconda/ui/gui/spokes/keyboard.py
@@ -79,7 +79,7 @@ def matches_entry(self, model, itr, user_data=None):
eng_value = self._xkl_wrapper.get_layout_variant_description(value, xlated=False)
xlated_value = self._xkl_wrapper.get_layout_variant_description(value)
translit_value = strip_accents(xlated_value).lower()
- entry_text = unicode(entry_text, "utf-8").lower()
+ entry_text = str(entry_text, "utf-8").lower()
return have_word_match(entry_text, eng_value) or have_word_match(entry_text, xlated_value) \
or have_word_match(entry_text, translit_value)
diff --git a/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py b/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py
index 1874647..ce6148d 100644
--- a/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py
+++ b/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py
@@ -86,7 +86,7 @@ def _matches_entry(self, model, itr, *args):
# Otherwise, filter the list showing only what is matched by the
# text entry. Either the English or native names can match.
lowered = entry.lower()
- translit = strip_accents(unicode(native, "utf-8")).lower()
+ translit = strip_accents(str(native, "utf-8")).lower()
if lowered in native.lower() or lowered in english.lower() or lowered in translit:
return True
else:
diff --git a/pyanaconda/ui/gui/utils.py b/pyanaconda/ui/gui/utils.py
index 7fcff75..f16ce08 100644
--- a/pyanaconda/ui/gui/utils.py
+++ b/pyanaconda/ui/gui/utils.py
@@ -422,7 +422,7 @@ def escape_markup(value):
This function converts the value to a string before passing markup_escape_text().
"""
- if isinstance(value, unicode):
+ if isinstance(value, str):
value = value.encode("utf-8")
return GLib.markup_escape_text(str(value))
diff --git a/pyanaconda/ui/tui/__init__.py b/pyanaconda/ui/tui/__init__.py
index e5ed6ac..660f365 100644
--- a/pyanaconda/ui/tui/__init__.py
+++ b/pyanaconda/ui/tui/__init__.py
@@ -75,7 +75,7 @@ def __init__(self, storage, payload, instclass,
:type instclass: instance of install class
:param productTitle: the name of the product
- :type productTitle: unicode string
+ :type productTitle: str
:param isFinal: Boolean that marks the release
as final (True) or development
@@ -86,7 +86,7 @@ def __init__(self, storage, payload, instclass,
dialog question. It should not
be translated to allow for change
of language.
- :type quitMessage: unicode string
+ :type quitMessage: str
"""
diff --git a/pyanaconda/ui/tui/hubs/__init__.py b/pyanaconda/ui/tui/hubs/__init__.py
index 87d1b38..8c5f16a 100644
--- a/pyanaconda/ui/tui/hubs/__init__.py
+++ b/pyanaconda/ui/tui/hubs/__init__.py
@@ -33,7 +33,7 @@ class TUIHub(TUIObject, common.Hub):
:type categories: list of strings
:param title: title for this Hub
- :type title: unicode
+ :type title: str
"""
diff --git a/pyanaconda/ui/tui/simpleline/base.py b/pyanaconda/ui/tui/simpleline/base.py
index 9fec160..28d753e 100644
--- a/pyanaconda/ui/tui/simpleline/base.py
+++ b/pyanaconda/ui/tui/simpleline/base.py
@@ -25,7 +25,6 @@
import queue
import getpass
import threading
-import types
import functools
import queue
from pyanaconda.threads import threadMgr, AnacondaThread
@@ -582,7 +581,7 @@ def show_all(self):
w.render(self.app.width)
if isinstance(w, Widget):
self._print_long_widget(w)
- elif type(w) == bytes:
+ elif isinstance(w, bytes):
print(w)
else:
# not a widget or string, just print its string representation
diff --git a/pyanaconda/ui/tui/simpleline/widgets.py b/pyanaconda/ui/tui/simpleline/widgets.py
index feb40ae..85959a3 100644
--- a/pyanaconda/ui/tui/simpleline/widgets.py
+++ b/pyanaconda/ui/tui/simpleline/widgets.py
@@ -32,7 +32,7 @@ class TextWidget(base.Widget):
def __init__(self, text):
"""
:param text: text to format
- :type text: unicode
+ :type text: str
"""
base.Widget.__init__(self)
@@ -135,10 +135,10 @@ def __init__(self, key="x", title=None, text=None, completed=None):
:type key: character
:param title: the title next to the [ ] box
- :type title: unicode
+ :type title: str
:param text: the description text to be shown on the second row in ()
- :type text: unicode
+ :type text: str
:param completed: is the checkbox ticked or not?
:type completed: True|False
diff --git a/pyanaconda/ui/tui/spokes/__init__.py b/pyanaconda/ui/tui/spokes/__init__.py
index 394c928..9bfd656 100644
--- a/pyanaconda/ui/tui/spokes/__init__.py
+++ b/pyanaconda/ui/tui/spokes/__init__.py
@@ -40,7 +40,7 @@ class TUISpoke(TUIObject, tui.Widget, Spoke):
as a summary box with title, description and completed checkbox.
:param title: title of this spoke
- :type title: unicode
+ :type title: str
:param category: category this spoke belongs to
:type category: string
diff --git a/pyanaconda/ui/tui/tuiobject.py b/pyanaconda/ui/tui/tuiobject.py
index 3d80b66..e9b39af 100644
--- a/pyanaconda/ui/tui/tuiobject.py
+++ b/pyanaconda/ui/tui/tuiobject.py
@@ -35,7 +35,7 @@ def __init__(self, app, message):
:type app: instance of App class
:param message: the message to show to the user
- :type message: unicode
+ :type message: str
"""
tui.UIScreen.__init__(self, app)
diff --git a/tests/pyanaconda_tests/iutil_test.py b/tests/pyanaconda_tests/iutil_test.py
index 95454f0..9d9778f 100644
--- a/tests/pyanaconda_tests/iutil_test.py
+++ b/tests/pyanaconda_tests/iutil_test.py
@@ -720,7 +720,7 @@ def have_word_match_test(self):
self.assertFalse(iutil.have_word_match(None, ""))
self.assertFalse(iutil.have_word_match(None, None))
- # Compare unicode and str and make sure nothing crashes
+ # Compare designated unicode and "standard" unicode string and make sure nothing crashes
self.assertTrue(iutil.have_word_match("fête", u"fête champêtre"))
self.assertTrue(iutil.have_word_match(u"fête", "fête champêtre"))
diff --git a/tests/pylint/markup.py b/tests/pylint/markup.py
index 3bb85dd..7a93880 100644
--- a/tests/pylint/markup.py
+++ b/tests/pylint/markup.py
@@ -25,7 +25,6 @@
from pylint.checkers.utils import check_messages
from pylint.interfaces import IAstroidChecker
-import types
import sys
import os
@@ -112,7 +111,7 @@ def __init__(self, linter=None):
@check_messages("invalid-markup", "invalid-markup-element", "unescaped-markup", "invalid-translated-markup", "invalid-translated-markup-element", "invalid-pango-translation", "unnecessary-markup")
def visit_const(self, node):
- if not isinstance(node.value, types.StringType) and not isinstance(node.value, types.UnicodeType):
+ if not isinstance(node.value, (bytes, str)):
return
if not is_markup(node.value):
--
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/ab15f1cd6ad1c8643fc45766c53b5e4c34f02cca
More information about the anaconda-patches
mailing list