fix lltrace to consider __call__ and pure functions decoration tls-sprint
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 18 Feb 2009 01:45:09 +0100
branchtls-sprint
changeset 752 c0506c4a1e6c
parent 751 ec16f43107d3
child 753 17d38f000bea
fix lltrace to consider __call__ and pure functions decoration
selectors.py
--- a/selectors.py	Wed Feb 18 01:42:11 2009 +0100
+++ b/selectors.py	Wed Feb 18 01:45:09 2009 +0100
@@ -67,12 +67,19 @@
     if CubicWebConfiguration.mode == 'installed':
         return selector
     def traced(cls, *args, **kwargs):
-        selname = cls.__class__.__name__
-        oid = args[0].id
+        # /!\ lltrace decorates pure function or __call__ method, this
+        #     means argument order may be different
+        if isinstance(cls, Selector):
+            selname = cls.__class__.__name__
+            vobj = args[0]
+        else:
+            selname = selector.__name__
+            vobj = cls
+        oid = vobj.id
         ret = selector(cls, *args, **kwargs)
         if TRACED_OIDS == 'all' or oid in TRACED_OIDS:
             #SELECTOR_LOGGER.warning('selector %s returned %s for %s', selname, ret, cls)
-            print 'selector %s returned %s for %s' % (selname, ret, args[0])
+            print 'selector %s returned %s for %s' % (selname, ret, vobj)
         return ret
     traced.__name__ = selector.__name__
     return traced