- implement a general getfslineno helper in code/source.py with tests

- not exposed yey

--HG--
branch : trunk
This commit is contained in:
Samuele Pedroni
2009-05-12 12:36:43 +02:00
parent 9950fdc3eb
commit 1e5ece07e8
2 changed files with 40 additions and 0 deletions

View File

@@ -217,6 +217,26 @@ def compile_(source, filename=None, mode='exec', flags=
return co
def getfslineno(obj):
try:
code = py.code.Code(obj)
except TypeError:
# fallback to
fn = (py.std.inspect.getsourcefile(obj) or
py.std.inspect.getfile(obj))
fspath = fn and py.path.local(fn) or None
if fspath:
try:
_, lineno = findsource(obj)
except IOError:
lineno = None
else:
lineno = None
else:
fspath = code.path
lineno = code.firstlineno
return fspath, lineno
#
# helper functions
#