From c9c054e72bc3ed60731d3d48780e209292195974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Tue, 5 Aug 2014 18:30:20 +0100 Subject: [PATCH] refactored backward compatibility on formstyles to use try except instead of inspecting arguments, should make the new style faster as it never raises the exception --- gluon/sqlhtml.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index cb85158d..fc84e7c6 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -35,7 +35,6 @@ import re import cStringIO from gluon.globals import current from gluon.http import redirect -from gluon.utils import get_callable_argspec try: import gluon.settings as settings @@ -1288,9 +1287,13 @@ class SQLFORM(FORM): raise RuntimeError('formstyle not found') if callable(formstyle): - # backward compatibility, 4 argument function is the old style - args, varargs, keywords, defaults = get_callable_argspec(formstyle) - if defaults and len(args) - len(defaults) == 4 or len(args) == 4: + try: + table = formstyle(self, xfields) + for id, a, b, c in xfields: + self.field_parent[id] = getattr(b, 'parent', None) \ + if isinstance(b, XmlComponent) else None + except TypeError: + # backward compatibility, 4 argument function is the old style table = TABLE() for id, a, b, c in xfields: newrows = formstyle(id, a, b, c) @@ -1300,11 +1303,6 @@ class SQLFORM(FORM): newrows = [newrows] for newrow in newrows: table.append(newrow) - else: - table = formstyle(self, xfields) - for id, a, b, c in xfields: - self.field_parent[id] = getattr(b, 'parent', None) \ - if isinstance(b, XmlComponent) else None else: raise RuntimeError('formstyle not supported') return table