From 18d264e34bba18c578380f847136a394a4c86e88 Mon Sep 17 00:00:00 2001
From: Tomas Kopecek <tkopecek@redhat.com>
Date: Jul 30 2018 09:04:50 +0000
Subject: Fix isinstance with lists


Fixes: https://pagure.io/koji/issue/1011

---

diff --git a/builder/kojid b/builder/kojid
index 7ff9c49..06c14e7 100755
--- a/builder/kojid
+++ b/builder/kojid
@@ -5661,7 +5661,7 @@ class WaitrepoTask(BaseTaskHandler):
 
         if isinstance(newer_than, six.string_types) and newer_than.lower() == "now":
             newer_than = start
-        if not isinstance(newer_than, to_list(six.integer_types) + [type(None), float]):
+        if not isinstance(newer_than, tuple(to_list(six.integer_types) + [type(None), float])):
             raise koji.GenericError("Invalid value for newer_than: %s" % newer_than)
 
         if newer_than and nvrs:
diff --git a/hub/kojihub.py b/hub/kojihub.py
index 22dd484..022e9d5 100644
--- a/hub/kojihub.py
+++ b/hub/kojihub.py
@@ -66,6 +66,9 @@ from koji.util import to_list
 from six.moves import range
 logger = logging.getLogger('koji.hub')
 
+
+NUMERIC_TYPES = tuple(list(six.integer_types) + [float])
+
 def log_error(msg):
     logger.error(msg)
 
@@ -1183,7 +1186,7 @@ def readTaggedBuilds(tag, event=None, inherit=False, latest=False, package=None,
     # build - id pkg_id version release epoch
     # tag_listing - id build_id tag_id
 
-    if not isinstance(latest, list(six.integer_types) + [float]):
+    if not isinstance(latest, NUMERIC_TYPES):
         latest = bool(latest)
 
     taglist = [tag]
@@ -3864,7 +3867,7 @@ def list_rpms(buildID=None, buildrootID=None, imageID=None, componentBuildrootID
         joins.append('standard_buildroot ON rpminfo.buildroot_id = standard_buildroot.buildroot_id')
         clauses.append('standard_buildroot.host_id = %(hostID)i')
     if arches != None:
-        if isinstance(arches, list) or isinstance(arches, tuple):
+        if isinstance(arches, (list, tuple)):
             clauses.append('rpminfo.arch IN %(arches)s')
         elif isinstance(arches, str):
             clauses.append('rpminfo.arch = %(arches)s')
@@ -4734,7 +4737,7 @@ def query_buildroots(hostID=None, tagID=None, state=None, rpmID=None, archiveID=
 
     clauses = []
     if buildrootID != None:
-        if isinstance(buildrootID, list) or isinstance(buildrootID, tuple):
+        if isinstance(buildrootID, (list, tuple)):
             clauses.append('buildroot.id IN %(buildrootID)s')
         else:
             clauses.append('buildroot.id = %(buildrootID)i')
@@ -4743,7 +4746,7 @@ def query_buildroots(hostID=None, tagID=None, state=None, rpmID=None, archiveID=
     if tagID != None:
         clauses.append('tag.id = %(tagID)i')
     if state != None:
-        if isinstance(state, list) or isinstance(state, tuple):
+        if isinstance(state, (list, tuple)):
             clauses.append('standard_buildroot.state IN %(state)s')
         else:
             clauses.append('standard_buildroot.state = %(state)i')
@@ -8934,7 +8937,7 @@ class RootExports(object):
         values = {}
         q = """SELECT id, EXTRACT(EPOCH FROM time) FROM events"""
         if before is not None:
-            if not isinstance(before, list(six.integer_types) + [float]):
+            if not isinstance(before, NUMERIC_TYPES):
                 raise koji.GenericError('invalid type for before: %s' % type(before))
             # use the repr() conversion because it retains more precision than the
             # string conversion
@@ -10461,7 +10464,7 @@ class RootExports(object):
     def getTaskInfo(self, task_id, request=False):
         """Get information about a task"""
         single = True
-        if isinstance(task_id, list) or isinstance(task_id, tuple):
+        if isinstance(task_id, (list, tuple)):
             single = False
         else:
             task_id = [task_id]
@@ -10757,7 +10760,7 @@ class RootExports(object):
                 raise koji.GenericError('arches option cannot be empty')
             # include the regex constraints below so we can match 'ppc' without
             # matching 'ppc64'
-            if not (isinstance(arches, list) or isinstance(arches, tuple)):
+            if not isinstance(arches, (list, tuple)):
                 arches = [arches]
             archClause = [r"""arches ~ E'\\m%s\\M'""" % arch for arch in arches]
             clauses.append('(' + ' OR '.join(archClause) + ')')
@@ -10897,7 +10900,7 @@ class RootExports(object):
                 ts = time.mktime(time.strptime(str(ts), '%Y%m%dT%H:%M:%S'))
             except ValueError:
                 raise koji.GenericError("Invalid time: %s" % ts)
-        elif not isinstance(ts, list(six.integer_types) + [float]):
+        elif not isinstance(ts, NUMERIC_TYPES):
             raise koji.GenericError("Invalid type for timestamp")
         koji.plugin.run_callbacks('preBuildStateChange', attribute='completion_ts', old=buildinfo['completion_ts'], new=ts, info=buildinfo)
         buildid = buildinfo['id']
@@ -10915,7 +10918,7 @@ class RootExports(object):
         result = getattr(self, methodName)(*args, **kw)
         if result == None:
             return 0
-        elif isinstance(result, list) or isinstance(result, tuple) or isinstance(result, dict):
+        elif isinstance(result, (list, tuple, dict)):
             return len(result)
         else:
             return 1
diff --git a/koji/__init__.py b/koji/__init__.py
index e6d24a3..ac01f2b 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -130,7 +130,7 @@ class Enum(dict):
         super(Enum, self).__init__([(value, n) for n, value in enumerate(self._order)])
 
     def __getitem__(self, key):
-        if isinstance(key, int) or isinstance(key, slice):
+        if isinstance(key, (int, slice)):
             return self._order.__getitem__(key)
         else:
             return super(Enum, self).__getitem__(key)
diff --git a/koji/util.py b/koji/util.py
index a0d033c..fcc48c0 100644
--- a/koji/util.py
+++ b/koji/util.py
@@ -496,7 +496,7 @@ def filedigestAlgo(hdr):
     return digest_algo.lower()
 
 def parseStatus(rv, prefix):
-    if isinstance(prefix, list) or isinstance(prefix, tuple):
+    if isinstance(prefix, (list, tuple)):
         prefix = ' '.join(prefix)
     if os.WIFSIGNALED(rv):
         return '%s was killed by signal %i' % (prefix, os.WTERMSIG(rv))

