File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010# XXX The functions getcodename() and getfuncname() are now obsolete
1111# XXX as code and function objects now have a name attribute --
1212# XXX co.co_name and f.func_name.
13+ # XXX getlineno() is now also obsolete because of the new attribute
14+ # XXX of code objects, co.co_firstlineno.
1315
1416# Extract the function or class name from a code object.
1517# This is a bit of a hack, since a code object doesn't contain
3436_namecache = {} # The cache
3537
3638def getcodename (co ):
39+ try :
40+ return co .co_name
41+ except AttributeError :
42+ pass
3743 key = `co` # arbitrary but uniquely identifying string
3844 if _namecache .has_key (key ): return _namecache [key ]
3945 filename = co .co_filename
@@ -55,11 +61,19 @@ def getcodename(co):
5561# Use the above routine to find a function's name.
5662
5763def getfuncname (func ):
64+ try :
65+ return func .func_name
66+ except AttributeError :
67+ pass
5868 return getcodename (func .func_code )
5969
6070# A part of the above code to extract just the line number from a code object.
6171
6272def getlineno (co ):
73+ try :
74+ return co .co_firstlineno
75+ except AttributeError :
76+ pass
6377 code = co .co_code
6478 if ord (code [0 ]) == SET_LINENO :
6579 return ord (code [1 ]) | ord (code [2 ]) << 8
Original file line number Diff line number Diff line change 1010# XXX The functions getcodename() and getfuncname() are now obsolete
1111# XXX as code and function objects now have a name attribute --
1212# XXX co.co_name and f.func_name.
13+ # XXX getlineno() is now also obsolete because of the new attribute
14+ # XXX of code objects, co.co_firstlineno.
1315
1416# Extract the function or class name from a code object.
1517# This is a bit of a hack, since a code object doesn't contain
3436_namecache = {} # The cache
3537
3638def getcodename (co ):
39+ try :
40+ return co .co_name
41+ except AttributeError :
42+ pass
3743 key = `co` # arbitrary but uniquely identifying string
3844 if _namecache .has_key (key ): return _namecache [key ]
3945 filename = co .co_filename
@@ -55,11 +61,19 @@ def getcodename(co):
5561# Use the above routine to find a function's name.
5662
5763def getfuncname (func ):
64+ try :
65+ return func .func_name
66+ except AttributeError :
67+ pass
5868 return getcodename (func .func_code )
5969
6070# A part of the above code to extract just the line number from a code object.
6171
6272def getlineno (co ):
73+ try :
74+ return co .co_firstlineno
75+ except AttributeError :
76+ pass
6377 code = co .co_code
6478 if ord (code [0 ]) == SET_LINENO :
6579 return ord (code [1 ]) | ord (code [2 ]) << 8
You can’t perform that action at this time.
0 commit comments