fixed issue #1409, py2 vs py3
This commit is contained in:
+16
-6
@@ -54,17 +54,27 @@ REGEX_ALIAS_MATCH = re.compile('^(.*) AS (.*)$')
|
|||||||
def add_class(a, b):
|
def add_class(a, b):
|
||||||
return a + ' ' + b if a else b
|
return a + ' ' + b if a else b
|
||||||
|
|
||||||
|
def count_expected_args(f):
|
||||||
|
if hasattr(f,'func_code'):
|
||||||
|
# python 2
|
||||||
|
n = f.func_code.co_argcount - len(f.func_defaults or [])
|
||||||
|
if getattr(f, 'im_self', None):
|
||||||
|
n -= 1
|
||||||
|
elif hasattr(f, '__code__'):
|
||||||
|
# python 3
|
||||||
|
n = f.__code__.co_argcount - len(f.__defaults__ or [])
|
||||||
|
if getattr(f, '__self__', None):
|
||||||
|
n -= 1
|
||||||
|
else:
|
||||||
|
# doh!
|
||||||
|
n = 1
|
||||||
|
return n
|
||||||
|
|
||||||
def represent(field, value, record):
|
def represent(field, value, record):
|
||||||
f = field.represent
|
f = field.represent
|
||||||
if not callable(f):
|
if not callable(f):
|
||||||
return str(value)
|
return str(value)
|
||||||
if hasattr(f,'func_code'):
|
n = count_expected_args(f)
|
||||||
n = f.__code__.co_argcount - len(f.__defaults__ or [])
|
|
||||||
if getattr(f, 'im_self', None):
|
|
||||||
n -= 1
|
|
||||||
else:
|
|
||||||
n = 1
|
|
||||||
if n == 1:
|
if n == 1:
|
||||||
return f(value)
|
return f(value)
|
||||||
elif n == 2:
|
elif n == 2:
|
||||||
|
|||||||
Reference in New Issue
Block a user