diff options
author | Tim Peters <tim.peters@gmail.com> | 2004-07-18 06:16:08 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2004-07-18 06:16:08 (GMT) |
commit | 182b5aca27d376b08a2904bed42b751496f932f3 (patch) | |
tree | df13115820dbc879c0fe2eae488c9f8c0215a7da /Lib/lib-old/codehack.py | |
parent | e6ddc8b20b493fef2e7cffb2e1351fe1d238857e (diff) | |
download | cpython-182b5aca27d376b08a2904bed42b751496f932f3.zip cpython-182b5aca27d376b08a2904bed42b751496f932f3.tar.gz cpython-182b5aca27d376b08a2904bed42b751496f932f3.tar.bz2 |
Whitespace normalization, via reindent.py.
Diffstat (limited to 'Lib/lib-old/codehack.py')
-rw-r--r-- | Lib/lib-old/codehack.py | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/Lib/lib-old/codehack.py b/Lib/lib-old/codehack.py index 248205b..0b5e3a1 100644 --- a/Lib/lib-old/codehack.py +++ b/Lib/lib-old/codehack.py @@ -36,46 +36,46 @@ identchars = string.ascii_letters + string.digits + '_' # Identifier characters _namecache = {} # The cache def getcodename(co): - try: - return co.co_name - except AttributeError: - pass - key = `co` # arbitrary but uniquely identifying string - if _namecache.has_key(key): return _namecache[key] - filename = co.co_filename - code = co.co_code - name = '' - if ord(code[0]) == SET_LINENO: - lineno = ord(code[1]) | ord(code[2]) << 8 - line = linecache.getline(filename, lineno) - words = line.split() - if len(words) >= 2 and words[0] in ('def', 'class'): - name = words[1] - for i in range(len(name)): - if name[i] not in identchars: - name = name[:i] - break - _namecache[key] = name - return name + try: + return co.co_name + except AttributeError: + pass + key = `co` # arbitrary but uniquely identifying string + if _namecache.has_key(key): return _namecache[key] + filename = co.co_filename + code = co.co_code + name = '' + if ord(code[0]) == SET_LINENO: + lineno = ord(code[1]) | ord(code[2]) << 8 + line = linecache.getline(filename, lineno) + words = line.split() + if len(words) >= 2 and words[0] in ('def', 'class'): + name = words[1] + for i in range(len(name)): + if name[i] not in identchars: + name = name[:i] + break + _namecache[key] = name + return name # Use the above routine to find a function's name. def getfuncname(func): - try: - return func.func_name - except AttributeError: - pass - return getcodename(func.func_code) + try: + return func.func_name + except AttributeError: + pass + return getcodename(func.func_code) # A part of the above code to extract just the line number from a code object. def getlineno(co): - try: - return co.co_firstlineno - except AttributeError: - pass - code = co.co_code - if ord(code[0]) == SET_LINENO: - return ord(code[1]) | ord(code[2]) << 8 - else: - return -1 + try: + return co.co_firstlineno + except AttributeError: + pass + code = co.co_code + if ord(code[0]) == SET_LINENO: + return ord(code[1]) | ord(code[2]) << 8 + else: + return -1 |