[Checkins] SVN: zc.async/trunk/src/zc/async/monitor Fix a catch-all trap.

Zvezdan Petkovic zvezdan at zope.com
Mon Oct 13 17:46:30 EDT 2008


Log message for revision 92177:
  Fix a catch-all trap.
  
  The last elif was effectively elif True: because of the first line.
  The tuple always resolved to True and wanted to be isinstance() really.
  Added a test that exercises that part of the code.
  
  

Changed:
  U   zc.async/trunk/src/zc/async/monitor.py
  U   zc.async/trunk/src/zc/async/monitordb.txt

-=-
Modified: zc.async/trunk/src/zc/async/monitor.py
===================================================================
--- zc.async/trunk/src/zc/async/monitor.py	2008-10-13 21:31:16 UTC (rev 92176)
+++ zc.async/trunk/src/zc/async/monitor.py	2008-10-13 21:46:29 UTC (rev 92177)
@@ -58,11 +58,14 @@
             return tuple(obj)
         # isinstance and providedBy are *not* redundant
         # it's a performance optimization
-        elif ((types.FunctionType, types.BuiltinFunctionType) or
-              isinstance(obj, persistent.Persistent) or
+        elif (isinstance(obj, (types.FunctionType, types.BuiltinFunctionType,
+                               persistent.Persistent)) or
               persistent.interfaces.IPersistent.providedBy(obj)):
             return zc.async.utils.custom_repr(obj)
-        return simplejson.JSONEncoder.default(self, obj)
+        try:
+            return simplejson.JSONEncoder.default(self, obj)
+        except TypeError:
+            return zc.async.utils.custom_repr(obj)
 
 encoder = Encoder(sort_keys=True, indent=4)
 

Modified: zc.async/trunk/src/zc/async/monitordb.txt
===================================================================
--- zc.async/trunk/src/zc/async/monitordb.txt	2008-10-13 21:31:16 UTC (rev 92176)
+++ zc.async/trunk/src/zc/async/monitordb.txt	2008-10-13 21:46:29 UTC (rev 92177)
@@ -1364,6 +1364,9 @@
     ] 
     -> CLOSE
 
+
+We are going to test an edge case at the end. [#encoder_edge_case]_
+
 [#tearDown]_
 
 .. [#setUp] See the discussion in other documentation to explain this code.
@@ -1433,3 +1436,106 @@
     >>> for thread in threads:
     ...     thread.join(3)
     ...
+
+.. [#encoder_edge_case]
+    >>> import zc.async.agent
+    >>> import zc.async.utils
+    >>> class Stub(object):
+    ...     def __call__(self, j):
+    ...         return (zc.async.utils.custom_repr(j.callable) ==
+    ...                 'zc.async.doctest_test.active_pause2')
+    ...     def __repr__(self):
+    ...         return "I'm stubby"
+    >>> agent = zc.async.agent.Agent(filter=Stub())
+    >>> queue.dispatchers[alt_dispatcher.UUID]['filtered'] = agent
+    >>> transaction.commit()
+    >>> ignore = reactor.time_flies(1)
+    >>> connection.test_input('asyncdb status\n')
+    {
+        "": {
+            "dispatchers": {
+                "282b5a6c-5a84-11dd-a9af-0017f2c49bdd": {
+                    "agents": {
+                        "filtered": {
+                            "filter": "I'm stubby", 
+                            "len": 0, 
+                            "size": 3
+                        }
+                    }, 
+                    "dead": false, 
+                    "last ping": "2006-08-10T15:44:38.000211Z", 
+                    "ping death interval": {
+                        "minutes": 1
+                    }, 
+                    "ping interval": {
+                        "seconds": 30.0
+                    }, 
+                    "since ping": {
+                        "seconds": 17.0
+                    }
+                }, 
+                "d10f43dc-ffdf-11dc-abd4-0017f2c49bdd": {
+                    "agents": {
+                        "main": {
+                            "filter": null, 
+                            "len": 1, 
+                            "size": 3
+                        }
+                    }, 
+                    "dead": false, 
+                    "last ping": "2006-08-10T15:44:52.000211Z", 
+                    "ping death interval": {
+                        "minutes": 1
+                    }, 
+                    "ping interval": {
+                        "seconds": 30.0
+                    }, 
+                    "since ping": {
+                        "seconds": 3.0
+                    }
+                }
+            }, 
+            "len": 0
+        }, 
+        "alt": {
+            "dispatchers": {
+                "282b5a6c-5a84-11dd-a9af-0017f2c49bdd": {
+                    "agents": {
+                        "main": {
+                            "filter": null, 
+                            "len": 0, 
+                            "size": 3
+                        }
+                    }, 
+                    "dead": false, 
+                    "last ping": "2006-08-10T15:44:43.000211Z", 
+                    "ping death interval": {
+                        "minutes": 1
+                    }, 
+                    "ping interval": {
+                        "seconds": 30.0
+                    }, 
+                    "since ping": {
+                        "seconds": 12.0
+                    }
+                }, 
+                "d10f43dc-ffdf-11dc-abd4-0017f2c49bdd": {
+                    "agents": {}, 
+                    "dead": false, 
+                    "last ping": "2006-08-10T15:44:42.000211Z", 
+                    "ping death interval": {
+                        "minutes": 1
+                    }, 
+                    "ping interval": {
+                        "seconds": 30.0
+                    }, 
+                    "since ping": {
+                        "seconds": 13.0
+                    }
+                }
+            }, 
+            "len": 0
+        }
+    } 
+    -> CLOSE
+



More information about the Checkins mailing list