import string _url = 'http://www.zopezen.org/Source' _sample = ''' ''' 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 = ' [Source]' % 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, '') if h > 0: tb = tb[:h] return tb if __name__=='__main__': print parse_tb(_sample)