Rev 5026: (mbp) profile_imports handles single-argument __import__ in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Feb 11 03:19:21 GMT 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5026 [merge]
revision-id: pqm at pqm.ubuntu.com-20100211031913-hu2gowhvmu10djr8
parent: pqm at pqm.ubuntu.com-20100211021642-eitum30b2e09oalf
parent: mbp at canoncial.com-20100207164517-9i4s0c407fcz2f5o
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2010-02-11 03:19:13 +0000
message:
  (mbp) profile_imports handles single-argument __import__
modified:
  profile_imports.py             profile_imports.py-20060618020306-k5uw80achysrokj9-1
=== modified file 'profile_imports.py'
--- a/profile_imports.py	2010-02-10 17:52:08 +0000
+++ b/profile_imports.py	2010-02-11 03:19:13 +0000
@@ -102,24 +102,32 @@
 
 _real_import = __import__
 
-def timed_import(name, globals, locals, fromlist, level=None):
+def timed_import(name, globals=None, locals=None, fromlist=None, level=None):
     """Wrap around standard importer to log import time"""
+    # normally there are 4, but if this is called as __import__ eg by
+    # /usr/lib/python2.6/email/__init__.py then there may be only one
+    # parameter
     # level is only passed by python2.6
 
-    scope_name = globals.get('__name__', None)
-    if scope_name is None:
-        scope_name = globals.get('__file__', None)
-    if scope_name is None:
-        scope_name = globals.keys()
+    if globals is None:
+        # can't determine the scope name afaics; we could peek up the stack to
+        # see where this is being called from, but it should be a rare case.
+        scope_name = None
     else:
-        # Trim out paths before bzrlib
-        loc = scope_name.find('bzrlib')
-        if loc != -1:
-            scope_name = scope_name[loc:]
-        # For stdlib, trim out early paths
-        loc = scope_name.find('python2.4')
-        if loc != -1:
-            scope_name = scope_name[loc:]
+        scope_name = globals.get('__name__', None)
+        if scope_name is None:
+            scope_name = globals.get('__file__', None)
+        if scope_name is None:
+            scope_name = globals.keys()
+        else:
+            # Trim out paths before bzrlib
+            loc = scope_name.find('bzrlib')
+            if loc != -1:
+                scope_name = scope_name[loc:]
+            # For stdlib, trim out early paths
+            loc = scope_name.find('python2.4')
+            if loc != -1:
+                scope_name = scope_name[loc:]
 
     # Figure out the frame that is doing the importing
     frame = sys._getframe(1)




More information about the bazaar-commits mailing list