At file:///home/pqm/archives/thelove/bzr/%2Btrunk/ ------------------------------------------------------------ revno: 5026 [merge] revision-id: [email protected] parent: [email protected] parent: [email protected] committer: Canonical.com Patch Queue Manager <[email protected]> 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)
-- bazaar-commits mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/bazaar-commits
