Added the calledby() function to utils (copied from threaded branch)
This commit is contained in:
parent
5af3617d4e
commit
621a2f73e9
1 changed files with 18 additions and 0 deletions
|
|
@ -1212,3 +1212,21 @@ def strip_control_sequences(string):
|
||||||
if not _STRIP_ANSI:
|
if not _STRIP_ANSI:
|
||||||
from evennia.utils.ansi import strip_raw_ansi as _STRIP_ANSI
|
from evennia.utils.ansi import strip_raw_ansi as _STRIP_ANSI
|
||||||
return _RE_CONTROL_CHAR.sub('', _STRIP_ANSI(string))
|
return _RE_CONTROL_CHAR.sub('', _STRIP_ANSI(string))
|
||||||
|
|
||||||
|
def calledby(callerdepth=1):
|
||||||
|
"""
|
||||||
|
Only to be used for debug purposes.
|
||||||
|
Insert this debug function in another function; it will print
|
||||||
|
which function called it. With callerdepth > 1, it will print the
|
||||||
|
caller of the caller etc.
|
||||||
|
"""
|
||||||
|
import inspect, os
|
||||||
|
stack = inspect.stack()
|
||||||
|
# we must step one extra level back in stack since we don't want
|
||||||
|
# to include the call of this function itself.
|
||||||
|
callerdepth = min(max(2, callerdepth + 1), len(stack)-1)
|
||||||
|
frame = inspect.stack()[callerdepth]
|
||||||
|
path = os.path.sep.join(frame[1].rsplit(os.path.sep, 2)[-2:])
|
||||||
|
return "[called by '%s': %s:%s %s]" % (frame[3], path, frame[2], frame[4])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue