Exemple #1
0
 def _pretty_print ( self, text ):
     """ Attempts to pretty print a docstring specified by *text*.
     """
     lines = text.split( '\n', 1 )
     print lines[0].strip()
     if len( lines ) > 1:
         print trim_margin( lines[1] )
    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 ) )