summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorStanislav Laznicka <slaznick@redhat.com>2017-09-20 12:32:16 +0200
committerStanislav Laznicka <slaznick@redhat.com>2017-10-25 09:44:37 +0200
commit26d721e6eac1b44031fb1326bcadf4c033d6e627 (patch)
tree36b2106b729dafe941549158d916dbbb5ca3509a /ipalib
parentc9d710a446d10aad72795e15bf041b87102628c1 (diff)
downloadfreeipa-26d721e6eac1b44031fb1326bcadf4c033d6e627.tar.gz
freeipa-26d721e6eac1b44031fb1326bcadf4c033d6e627.tar.xz
freeipa-26d721e6eac1b44031fb1326bcadf4c033d6e627.zip
parameters: relax type checks
The type checks in ipalib.parameters were too strict. An object that inherits from a type should implement its public interface. This should allow us checking for types of objects whose class implementations are private to a module but they implement a certain public interface (which is typical for e.g. python-cryptography). https://pagure.io/freeipa/issue/7131
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/parameters.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 81586e2c9..fa0c813a4 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -848,8 +848,10 @@ class Param(ReadOnly):
"""
Convert a single scalar value.
"""
- if type(value) in self.allowed_types:
- return value
+ for t in self.allowed_types:
+ if isinstance(value, t):
+ return value
+
raise ConversionError(name=self.name, error=ugettext(self.type_error))
def validate(self, value, supplied=None):
@@ -879,7 +881,10 @@ class Param(ReadOnly):
self._validate_scalar(value)
def _validate_scalar(self, value, index=None):
- if type(value) not in self.allowed_types:
+ for t in self.allowed_types:
+ if isinstance(value, t):
+ break
+ else:
raise TypeError(
TYPE_ERROR % (self.name, self.type, value, type(value))
)