[rhmessaging-commits] rhmessaging commits: r3746 - in mgmt/trunk: wooly/python/wooly and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Wed Dec 16 11:52:51 EST 2009


Author: justi9
Date: 2009-12-16 11:52:51 -0500 (Wed, 16 Dec 2009)
New Revision: 3746

Modified:
   mgmt/trunk/basil/python/basil/model.py
   mgmt/trunk/wooly/python/wooly/bench.py
   mgmt/trunk/wooly/python/wooly/profile.py
   mgmt/trunk/wooly/python/wooly/util.py
Log:
defaultdict isn't available in python 2.4; create one as needed

Modified: mgmt/trunk/basil/python/basil/model.py
===================================================================
--- mgmt/trunk/basil/python/basil/model.py	2009-12-16 16:19:00 UTC (rev 3745)
+++ mgmt/trunk/basil/python/basil/model.py	2009-12-16 16:52:51 UTC (rev 3746)
@@ -1,7 +1,9 @@
-from collections import defaultdict, deque
+from collections import deque
 from qmf.console import *
 from threading import Lock
 
+from util import *
+
 class BasilModel(object):
     def __init__(self):
         super(BasilModel, self).__init__()

Modified: mgmt/trunk/wooly/python/wooly/bench.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/bench.py	2009-12-16 16:19:00 UTC (rev 3745)
+++ mgmt/trunk/wooly/python/wooly/bench.py	2009-12-16 16:52:51 UTC (rev 3746)
@@ -1,12 +1,7 @@
-import os
-import sys
-
-from collections import defaultdict
-from traceback import print_exc
-from time import time
 from xml.parsers.expat import ParserCreate
 
 from wooly import Session, ClientSession
+from util import *
 
 class BenchmarkHarness(object):
     def __init__(self, app):

Modified: mgmt/trunk/wooly/python/wooly/profile.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/profile.py	2009-12-16 16:19:00 UTC (rev 3745)
+++ mgmt/trunk/wooly/python/wooly/profile.py	2009-12-16 16:52:51 UTC (rev 3746)
@@ -1,8 +1,5 @@
-import sys
+from util import *
 
-from time import time
-from collections import defaultdict
-
 class PageProfile(object):
     def __init__(self, page):
         self.page = page
@@ -140,7 +137,7 @@
     def do(self, session):
         self.profile.current_calls.append(self)
 
-        self.start = time()
+        self.start = time.time()
 
         if self.widget.update_enabled:
             self.widget.page.enable_update(session, self.widget)
@@ -151,7 +148,7 @@
         args = self.widget.get_args(session)
         self.widget.do_process(session, *args)
 
-        self.end = time()
+        self.end = time.time()
 
         self.profile.current_calls.pop()
         self.profile.process_calls.append(self)
@@ -160,7 +157,7 @@
     def do(self, session):
         self.profile.current_calls.append(self)
 
-        self.start = time()
+        self.start = time.time()
 
         args = self.widget.get_args(session)
         result = self.widget.do_render(session, *args)
@@ -168,7 +165,7 @@
         if result is None:
             result = ""
 
-        self.end = time()
+        self.end = time.time()
 
         assert self.start < self.end
 

Modified: mgmt/trunk/wooly/python/wooly/util.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/util.py	2009-12-16 16:19:00 UTC (rev 3745)
+++ mgmt/trunk/wooly/python/wooly/util.py	2009-12-16 16:52:51 UTC (rev 3746)
@@ -1,8 +1,11 @@
 import logging
+import os
 import random
+import sys
+import time
 
 from datetime import datetime
-from time import clock
+from traceback import print_exc
 
 def unique_id():
     bits0 = random.getrandbits(32)
@@ -11,3 +14,21 @@
     bits3 = random.getrandbits(32)
 
     return "%08x-%08x-%08x-%08x" % (bits0, bits1, bits2, bits3)
+
+try:
+    from collections import defaultdict
+except ImportError:
+    class defaultdict(dict):
+        def __init__(self, default_factory=None):
+            super(dict, self).__init__()
+
+            self.default_factory = default_factory
+
+        def __getitem__(self, key):
+            try:
+                super(dict, self).__getitem__(key)
+            except KeyError:
+                if self.default_factory is None:
+                    raise
+                else:
+                    return self.default_factory()



More information about the rhmessaging-commits mailing list