Rev 5012: (mbp) fix --profile-imports on python2.6 in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Sun Feb 7 10:51:33 GMT 2010


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

------------------------------------------------------------
revno: 5012 [merge]
revision-id: pqm at pqm.ubuntu.com-20100207105126-fgu710q48to6z77q
parent: pqm at pqm.ubuntu.com-20100206105435-3mmfhv9xg6267nyy
parent: mbp at sourcefrog.net-20091114115010-zf7ioqwdsipfew0s
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sun 2010-02-07 10:51:26 +0000
message:
  (mbp) fix --profile-imports on python2.6
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  profile_imports.py             profile_imports.py-20060618020306-k5uw80achysrokj9-1
=== modified file 'NEWS'
--- a/NEWS	2010-02-05 10:57:26 +0000
+++ b/NEWS	2010-02-07 10:51:26 +0000
@@ -687,6 +687,8 @@
 
 * Fix for shell completion and short options.  (Benoît PIERRE)
 
+* Fix ``bzr --profile-imports`` with Python 2.6.  (Martin Pool)
+
 * Hooks daughter classes should always call the base constructor.
   (Alexander Belchenko, Vincent Ladeuil, #389648) 
 

=== modified file 'profile_imports.py'
--- a/profile_imports.py	2009-03-23 14:59:43 +0000
+++ b/profile_imports.py	2009-11-14 11:50:10 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006 by Canonical Ltd
+# Copyright (C) 2006, 2009 by Canonical Ltd
 # Written by John Arbash Meinel <john at arbash-meinel.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -17,11 +17,17 @@
 
 """A custom importer and regex compiler which logs time spent."""
 
-import sre
 import sys
 import time
 
 
+if sys.version_info < (2, 5, 0):
+    import sre
+    re = sre
+else:
+    import re
+
+
 _parent_stack = []
 _total_stack = {}
 _info = {}
@@ -96,8 +102,9 @@
 
 _real_import = __import__
 
-def timed_import(name, globals, locals, fromlist):
+def timed_import(name, globals, locals, fromlist, level=None):
     """Wrap around standard importer to log import time"""
+    # level is only passed by python2.6
 
     scope_name = globals.get('__name__', None)
     if scope_name is None:
@@ -145,7 +152,8 @@
     return mod
 
 
-_real_compile = sre._compile
+_real_compile = re._compile
+
 
 def timed_compile(*args, **kwargs):
     """Log how long it takes to compile a regex"""
@@ -177,11 +185,11 @@
 def install():
     """Install the hooks for measuring import and regex compile time."""
     __builtins__['__import__'] = timed_import
-    sre._compile = timed_compile
+    re._compile = timed_compile
 
 
 def uninstall():
     """Remove the import and regex compile timing hooks."""
     __builtins__['__import__'] = _real_import
-    sre._compile = _real_compile
+    re._compile = _real_compile
 




More information about the bazaar-commits mailing list