def get_code(self, max_lines=3, tabbed=False):
'''Gets lines of code from a file the generated this issue.
:param max_lines: Max lines of context to return
:param tabbed: Use tabbing in the output
:return: strings of code
'''
lines = []
max_lines = max(max_lines, 1)
lmin = max(1, self.lineno - max_lines // 2)
lmax = lmin + len(self.linerange) + max_lines - 1
tmplt = "%i\t%s" if tabbed else "%i %s"
for line in moves.xrange(lmin, lmax):
text = linecache.getline(self.fname, line)
if isinstance(text, bytes):
text = text.decode('utf-8', 'ignore')
if not len(text):
break
lines.append(tmplt % (line, text))
return ''.join(lines)
评论列表
文章目录