diff --git a/disco/types/base.py b/disco/types/base.py index 3bea43a..0bce0c8 100644 --- a/disco/types/base.py +++ b/disco/types/base.py @@ -22,21 +22,27 @@ class ConversionError(Exception): 'Failed to convert `{}` (`{}`) to {}: {}'.format( str(raw)[:144], field.src_name, field.deserializer, e)) + if six.PY3: + self.__cause__ = e + class Field(object): - def __init__(self, value_type, alias=None, default=None): + def __init__(self, value_type, alias=None, default=None, test=0): self.src_name = alias self.dst_name = None + self.test = test - if not hasattr(self, 'default'): + if default is not None: self.default = default + elif not hasattr(self, 'default'): + self.default = None self.deserializer = None if value_type: self.deserializer = self.type_to_deserializer(value_type) - if isinstance(self.deserializer, Field): + if isinstance(self.deserializer, Field) and self.default is None: self.default = self.deserializer.default @property @@ -58,8 +64,13 @@ class Field(object): try: return self.deserializer(raw, client) except Exception as e: - exc_info = sys.exc_info() - raise ConversionError(self, raw, e), exc_info[1], exc_info[2] + err = ConversionError(self, raw, e) + + if six.PY2: + exc_info = sys.exc_info() + raise ConversionError, err, exc_info[2] + else: + raise err @staticmethod def type_to_deserializer(typ): @@ -132,6 +143,8 @@ def snowflake(data): def enum(typ): def _f(data): + if isinstance(data, str): + data = data.lower() return typ.get(data) if data is not None else None return _f diff --git a/requirements.txt b/requirements.txt index 9a1e8fd..a41d421 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ gevent==1.1.2 -holster==1.0.8 +holster==1.0.9 inflection==0.3.1 requests==2.11.1 six==1.10.0