def _source_info_for ( self, file_name, cur_line, frame ): """ Returns the color code and optional tag reference for the source code for the file name and stack frame specified by *file_name* and *frame*, and where execution is currently on *cur_line*. """ start, lines = self.shell.source_for_frame( frame ) if start is None: return ( color_tag_for( 'B' ), '' ) context = self.shell.context if context < 50: begin = max( 0, cur_line - start - context ) + 1 end = min( len( lines ), cur_line - start + context + 1 ) + 1 lines = source_context( lines, begin, end ) start += (begin - 1) lines = python_colorize( trim_margin( lines ), frame.f_locals, self.tags ) format = '%%0%dd' % len( str( start + len( lines ) - 1 ) ) source = '\n'.join( [ '%s \x008%s|\x00E %s' % ( LinePrefix[ (start + i) == cur_line ], format % (start + i), line ) for i, line in enumerate( lines ) ] ) tag = len( self.tags ) self.tags.append( ContentTag( content = '%s\n%s%s' % ( Separator, source, Separator) ) ) return ( color_tag_for( 'B', tag ), tag_ref_for( tag ) )
def str ( self, item ): """ Returns the string value of *item*. """ return python_colorize( self.item_contents )