/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to profile_imports.py

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import time
22
22
 
23
23
 
24
 
import re
 
24
if sys.version_info < (2, 5, 0):
 
25
    import sre
 
26
    re = sre
 
27
else:
 
28
    import re
25
29
 
26
30
 
27
31
_parent_stack = []
100
104
 
101
105
_real_import = __import__
102
106
 
103
 
def timed_import(name, globals=None, locals=None, fromlist=None, level=-1):
 
107
def timed_import(name, globals=None, locals=None, fromlist=None, level=None):
104
108
    """Wrap around standard importer to log import time"""
105
109
    # normally there are 4, but if this is called as __import__ eg by
106
110
    # /usr/lib/python2.6/email/__init__.py then there may be only one
118
122
        if scope_name is None:
119
123
            scope_name = globals.keys()
120
124
        else:
121
 
            # Trim out paths before breezy
122
 
            loc = scope_name.find('breezy')
 
125
            # Trim out paths before bzrlib
 
126
            loc = scope_name.find('bzrlib')
123
127
            if loc != -1:
124
128
                scope_name = scope_name[loc:]
125
129
            # For stdlib, trim out early paths
150
154
    tstart = _timer()
151
155
    try:
152
156
        # Do the import
153
 
        return _real_import(name, globals, locals, fromlist, level=level)
 
157
        mod = _real_import(name, globals, locals, fromlist)
154
158
    finally:
155
159
        tload = _timer()-tstart
156
160
        stack_finish(this, tload)
157
161
 
158
 
 
159
 
def _repr_regexp(pattern, max_len=30):
160
 
    """Present regexp pattern for logging, truncating if over max_len."""
161
 
    if len(pattern) > max_len:
162
 
        return repr(pattern[:max_len-3]) + "..."
163
 
    return repr(pattern)
 
162
    return mod
164
163
 
165
164
 
166
165
_real_compile = re._compile
180
179
        frame = sys._getframe(5)
181
180
        frame_name = frame.f_globals.get('__name__', '<unknown>')
182
181
    frame_lineno = frame.f_lineno
183
 
    this = stack_add(extra+_repr_regexp(args[0]), frame_name, frame_lineno)
 
182
    this = stack_add(extra+repr(args[0]), frame_name, frame_lineno)
184
183
 
185
184
    tstart = _timer()
186
185
    try: