File contents
import string
_url = 'http://www.zopezen.org/Source'
_sample = '''
<!--
Traceback (innermost last):
File E:\Zope23\lib\python\ZPublisher\Publish.py, line 223, in publish_module
File E:\Zope23\lib\python\ZPublisher\Publish.py, line 187, in publish
File E:\Zope23\lib\python\Zope\__init__.py, line 221, in zpublisher_exception_hook
(Object: Traversable)
File E:\Zope23\lib\python\ZPublisher\Publish.py, line 171, in publish
File E:\Zope23\lib\python\ZPublisher\mapply.py, line 160, in mapply
(Object: search_html)
File E:\Zope23\lib\python\ZPublisher\Publish.py, line 112, in call_object
(Object: search_html)
File E:\Zope23\lib\python\OFS\DTMLMethod.py, line 189, in __call__
(Object: search_html)
File E:\Zope23\lib\python\DocumentTemplate\DT_String.py, line 538, in __call__
(Object: search_html)
File E:\Zope23\lib\python\Products\ZDebug\DTMLDebug.py, line 307, in debug_render_blocks
File E:\Zope23\lib\python\Products\ZDebug\DTMLDebug.py, line 228, in debugException
(Object: renderwob)
File E:\Zope23\lib\python\Products\ZDebug\DTMLDebug.py, line 305, in debug_render_blocks
File E:\Zope23\lib\python\DocumentTemplate\DT_In.py, line 649, in renderwob
(Object: catalog({'title':PrincipiaSearchSource,}))
File E:\Zope23\lib\python\DocumentTemplate\DT_Util.py, line 334, in eval
(Object: catalog({'title':PrincipiaSearchSource,}))
(Info: PrincipiaSearchSource)
File <string>, line 0, in ?
NameError: (see above)
-->
'''
def parse_tb(tb):
in_lines = string.split(tb, '\n')
out_lines = []
for line in in_lines:
if string.find(line, 'File') >= 0 and string.find(line, 'in ?') < 0:
out_lines.append(parse_line(line))
else:
out_lines.append(line)
tb = string.join(out_lines, '\n')
tb = nuke_html(tb)
return tb
def parse_line(line):
words = string.split(line, ' ')
url = parse_into_url(words[3][:-1], words[5][:-1])
html = ' [<a href="%s">Source</a>]' % url
line = line + html
return line
def parse_into_url(file, line_no):
url = string.replace(file, INSTANCE_HOME, _url)
url = string.replace(url, '\\', '/')
last = string.rindex(url, '/')
url = url[:last+1] + '~' + url[last+1:]
url = '%s#%s' % (url, line_no)
return url
def nuke_html(tb):
h = string.find(tb, '<HTML>')
if h > 0:
tb = tb[:h]
return tb
if __name__=='__main__':
print parse_tb(_sample)