From 91dce52b197150d3c0d40c8000255bcae4bd9031 Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 10 Oct 2016 00:58:35 -0500 Subject: [PATCH] Fix text/binary fields for ETF, PermissionValue can use slots --- disco/types/base.py | 8 ++++++-- disco/types/permissions.py | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/disco/types/base.py b/disco/types/base.py index 6a0ca05..855ddfe 100644 --- a/disco/types/base.py +++ b/disco/types/base.py @@ -15,7 +15,7 @@ class ConversionError(Exception): def __init__(self, field, raw, e): super(ConversionError, self).__init__( 'Failed to convert `{}` (`{}`) to {}: {}'.format( - raw, field.src_name, field.typ, e)) + str(raw)[:144], field.src_name, field.typ, e)) class FieldType(object): @@ -125,13 +125,17 @@ def datetime(data): def text(obj): if six.PY2: - return unicode(obj) + if isinstance(obj, str): + return obj.decode('utf-8') + return obj else: return str(obj) def binary(obj): if six.PY2: + if isinstance(obj, str): + return obj.decode('utf-8') return unicode(obj) else: return bytes(obj) diff --git a/disco/types/permissions.py b/disco/types/permissions.py index ec1c39e..b66e6cc 100644 --- a/disco/types/permissions.py +++ b/disco/types/permissions.py @@ -31,6 +31,8 @@ Permissions = Enum( class PermissionValue(object): + __slots__ = ['value'] + def __init__(self, value=0): if isinstance(value, EnumAttr) or isinstance(value, PermissionValue): value = value.value