Browse Source

Fix text/binary fields for ETF, PermissionValue can use slots

pull/6/head
Andrei 9 years ago
parent
commit
91dce52b19
  1. 8
      disco/types/base.py
  2. 2
      disco/types/permissions.py

8
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)

2
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

Loading…
Cancel
Save