Module: check_mk
Branch: master
Commit: a72b03e2957a40852971e6d15587e43874bf6b6d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a72b03e2957a40…
Author: Óscar Nájera <on(a)mathias-kettner.de>
Date: Wed Nov 14 11:43:05 2018 +0100
Manual fix typecheck idioms cmk/gui
CMK-837
Change-Id: I9147be6dc19965dd0ec1c2a1ebbaa9d143f7f396
---
cmk/gui/bi.py | 13 ++++++++++---
cmk/gui/forms.py | 2 +-
cmk/gui/htmllib.py | 11 +++++++++--
cmk/gui/http.py | 9 ++++++++-
cmk/gui/metrics.py | 2 +-
cmk/gui/plugins/userdb/ldap_connector.py | 2 +-
cmk/gui/plugins/views/icons/__init__.py | 2 +-
cmk/gui/plugins/wato/active_checks.py | 2 +-
cmk/gui/userdb.py | 2 +-
cmk/gui/valuespec.py | 2 +-
cmk/gui/views.py | 2 +-
cmk/gui/wato/mkeventd.py | 9 ++++++++-
cmk/gui/watolib.py | 11 +++++++++--
13 files changed, 52 insertions(+), 17 deletions(-)
diff --git a/cmk/gui/bi.py b/cmk/gui/bi.py
index f0e0b74..23dd4fa 100644
--- a/cmk/gui/bi.py
+++ b/cmk/gui/bi.py
@@ -35,6 +35,13 @@ import multiprocessing
from contextlib import contextmanager
import traceback
+try:
+ # does not exist in Py3, but is super class of str & unicode in py2
+ basestring
+except NameError:
+ basestring = str # pylint: disable=redefined-builtin
+ unicode = str # pylint: disable=redefined-builtin
+
from cmk.regex import regex
import cmk
@@ -272,7 +279,7 @@ def aggregation_group_choices():
def log(*args):
for idx, arg in enumerate(args):
- if type(arg) not in [unicode, str]:
+ if isinstance(arg, basestring):
arg = pprint.pformat(arg)
compile_logger.debug('BI: %s%s' % (idx > 5 and "\n" or
"", arg))
@@ -1825,7 +1832,7 @@ def compile_aggregation_rule(aggr_type, rule, args, lvl):
# 2: (['waage'], '(.*)')
calllist = []
for n in node[1:-2]:
- if type(n) in [str, unicode, list, tuple]:
+ if isinstance(n, (basestring, list, tuple)):
n = subst_vars(n, arginfo)
calllist.append(n)
@@ -1930,7 +1937,7 @@ def subst_vars(pattern, arginfo):
return tuple([subst_vars(x, arginfo) for x in pattern])
for name, value in arginfo.iteritems():
- if type(pattern) in [str, unicode]:
+ if isinstance(pattern, basestring):
pattern = pattern.replace('$' + name + '$', value)
return pattern
diff --git a/cmk/gui/forms.py b/cmk/gui/forms.py
index bb3cd97..0e90193 100644
--- a/cmk/gui/forms.py
+++ b/cmk/gui/forms.py
@@ -25,7 +25,7 @@
# Boston, MA 02110-1301 USA.
try:
- # does not exist in Py3, but is supper class of str & unicode in py2
+ # does not exist in Py3, but is super class of str & unicode in py2
basestring
except NameError:
basestring = str # pylint: disable=redefined-builtin
diff --git a/cmk/gui/htmllib.py b/cmk/gui/htmllib.py
index a158f6f..f0ed02b 100644
--- a/cmk/gui/htmllib.py
+++ b/cmk/gui/htmllib.py
@@ -76,6 +76,13 @@ except ImportError:
# Default to python2
from cgi import escape as html_escape
+try:
+ # does not exist in Py3, but is super class of str & unicode in py2
+ basestring
+except NameError:
+ basestring = str # pylint: disable=redefined-builtin
+ unicode = str # pylint: disable=redefined-builtin
+
# Monkey patch in order to make the HTML class below json-serializable without changing
the default json calls.
def _default(self, obj):
@@ -377,7 +384,7 @@ class OutputFunnel(object):
if isinstance(text, HTML):
text = "%s" % text
- if type(text) not in [str, unicode]: # also possible: type Exception!
+ if not isinstance(text, basestring): # also possible: type Exception!
raise MKGeneralException(
_('Type Error: html.write accepts str and unicode input objects
only!'))
@@ -1332,7 +1339,7 @@ class html(HTMLGenerator):
if isinstance(ht, HTML):
ht = "%s" % ht
- if type(ht) not in [str, unicode]:
+ if not isinstance(ht, basestring):
return ht
while True:
diff --git a/cmk/gui/http.py b/cmk/gui/http.py
index 611ef5c..949d140 100644
--- a/cmk/gui/http.py
+++ b/cmk/gui/http.py
@@ -29,6 +29,13 @@ import re
import werkzeug.http
import cgi
+try:
+ # does not exist in Py3, but is super class of str & unicode in py2
+ basestring
+except NameError:
+ basestring = str # pylint: disable=redefined-builtin
+ unicode = str # pylint: disable=redefined-builtin
+
import cmk.gui.log as log
from cmk.gui.i18n import _
import cmk.gui.http_status
@@ -221,7 +228,7 @@ class Request(object):
if value is None:
self.del_var(varname)
- elif type(value) in [str, unicode]:
+ elif isinstance(value, basestring):
self.vars[varname] = value
else:
diff --git a/cmk/gui/metrics.py b/cmk/gui/metrics.py
index f9c09a0..d25c7ae 100644
--- a/cmk/gui/metrics.py
+++ b/cmk/gui/metrics.py
@@ -41,7 +41,7 @@ import json
import traceback
try:
- # does not exist in Py3, but is supper class of str & unicode in py2
+ # does not exist in Py3, but is super class of str & unicode in py2
basestring
except NameError:
basestring = str # pylint: disable=redefined-builtin
diff --git a/cmk/gui/plugins/userdb/ldap_connector.py
b/cmk/gui/plugins/userdb/ldap_connector.py
index 24608ba..14ac06e 100644
--- a/cmk/gui/plugins/userdb/ldap_connector.py
+++ b/cmk/gui/plugins/userdb/ldap_connector.py
@@ -55,7 +55,7 @@ import sys
import shutil
try:
- # does not exist in Py3, but is supper class of str & unicode in py2
+ # does not exist in Py3, but is super class of str & unicode in py2
basestring
except NameError:
basestring = str # pylint: disable=redefined-builtin
diff --git a/cmk/gui/plugins/views/icons/__init__.py
b/cmk/gui/plugins/views/icons/__init__.py
index 141f2f2..35e9864 100644
--- a/cmk/gui/plugins/views/icons/__init__.py
+++ b/cmk/gui/plugins/views/icons/__init__.py
@@ -27,7 +27,7 @@
import traceback
try:
- # does not exist in Py3, but is supper class of str & unicode in py2
+ # does not exist in Py3, but is super class of str & unicode in py2
basestring
except NameError:
basestring = str # pylint: disable=redefined-builtin
diff --git a/cmk/gui/plugins/wato/active_checks.py
b/cmk/gui/plugins/wato/active_checks.py
index 6b3110b..dc761ed 100644
--- a/cmk/gui/plugins/wato/active_checks.py
+++ b/cmk/gui/plugins/wato/active_checks.py
@@ -25,7 +25,7 @@
# Boston, MA 02110-1301 USA.
try:
- # does not exist in Py3, but is supper class of str & unicode in py2
+ # does not exist in Py3, but is super class of str & unicode in py2
basestring
except NameError:
basestring = str # pylint: disable=redefined-builtin
diff --git a/cmk/gui/userdb.py b/cmk/gui/userdb.py
index c23ae66..f3caee3 100644
--- a/cmk/gui/userdb.py
+++ b/cmk/gui/userdb.py
@@ -33,7 +33,7 @@ import copy
import pathlib2 as pathlib
try:
- # does not exist in Py3, but is supper class of str & unicode in py2
+ # does not exist in Py3, but is super class of str & unicode in py2
basestring
except NameError:
basestring = str # pylint: disable=redefined-builtin
diff --git a/cmk/gui/valuespec.py b/cmk/gui/valuespec.py
index 8529162..cabced6 100644
--- a/cmk/gui/valuespec.py
+++ b/cmk/gui/valuespec.py
@@ -49,7 +49,7 @@ import numbers
import ipaddress
try:
- # does not exist in Py3, but is supper class of str & unicode in py2
+ # does not exist in Py3, but is super class of str & unicode in py2
basestring
except NameError:
basestring = str # pylint: disable=redefined-builtin
diff --git a/cmk/gui/views.py b/cmk/gui/views.py
index 1045da1..e091d2f 100644
--- a/cmk/gui/views.py
+++ b/cmk/gui/views.py
@@ -1720,7 +1720,7 @@ def get_painter_title_for_choices(painter):
if painter["columns"] == ["site"]:
info_title = _("Site")
- if type(painter["title"]) in [types.FunctionType, types.MethodType]:
+ if isinstance(painter["title"], (types.FunctionType, types.MethodType)):
title = painter["title"]()
else:
title = painter["title"]
diff --git a/cmk/gui/wato/mkeventd.py b/cmk/gui/wato/mkeventd.py
index 0fcfddb..025c575 100644
--- a/cmk/gui/wato/mkeventd.py
+++ b/cmk/gui/wato/mkeventd.py
@@ -30,6 +30,13 @@ import time
import zipfile
import cStringIO
+try:
+ # does not exist in Py3, but is super class of str & unicode in py2
+ basestring
+except NameError:
+ basestring = str # pylint: disable=redefined-builtin
+ unicode = str # pylint: disable=redefined-builtin
+
import cmk.paths
import cmk.store as store
import cmk.render
@@ -2065,7 +2072,7 @@ class ModeEventConsoleEditRule(EventConsoleMode):
while num_repl > num_groups:
repl = "\\%d" % num_repl
for name, value in self._rule.items():
- if name.startswith("set_") and type(value) in [str, unicode]:
+ if name.startswith("set_") and isinstance(value, basestring):
if repl in value:
raise MKUserError(
"rule_p_" + name,
diff --git a/cmk/gui/watolib.py b/cmk/gui/watolib.py
index 077a464..8fbe5a1 100644
--- a/cmk/gui/watolib.py
+++ b/cmk/gui/watolib.py
@@ -64,6 +64,13 @@ import threading
from hashlib import sha256
from pathlib2 import Path
+try:
+ # does not exist in Py3, but is super class of str & unicode in py2
+ basestring
+except NameError:
+ basestring = str # pylint: disable=redefined-builtin
+ unicode = str # pylint: disable=redefined-builtin
+
import cmk.daemon as daemon
import cmk.paths
import cmk.defines
@@ -3950,7 +3957,7 @@ def register_configvar(group,
# New API is to hand over the class via domain argument. But not all calls have been
# migrated. Perform the translation here.
- if type(domain) in [str, unicode]:
+ if isinstance(domain, basestring):
domain = ConfigDomain.get_class(domain)
g_configvar_groups.setdefault(group, []).append((domain, varname, valuespec))
@@ -5968,7 +5975,7 @@ class ActivateChangesSite(multiprocessing.Process,
ActivateChanges):
# In case of an exception it returns a str/unicode message. Wrap the
# message in a list to be compatible to regular response
- if type(cmk_configuration_warnings) in [str, unicode]:
+ if isinstance(cmk_configuration_warnings, basestring):
cmk_configuration_warnings = [cmk_configuration_warnings]
return {"check_mk": cmk_configuration_warnings}