(self, stype)
Format SyntaxError exceptions (internal helper).
Format SyntaxError exceptions (internal helper).
Format SyntaxError exceptions ( internal helper ) .
def _format_syntax_error(self, stype):
        """Format SyntaxError exceptions (internal helper)."""
        # Show exactly where the problem was found.
        filename_suffix = ''
        if self.lineno is not None:
            yield '  File "{}", line {}\n'.format(
                self.filename or "<string>", self.lineno)
        elif self.filename is not None:
            filename_suffix = ' ({})'.format(self.filename)

        text = self.text
        if text is not None:
            # text  = "   foo\n"
            # rtext = "   foo"
            # ltext =    "foo"
            rtext = text.rstrip('\n')
            ltext = rtext.lstrip(' \n\f')
            spaces = len(rtext) - len(ltext)
            yield '    {}\n'.format(ltext)

            if self.offset is not None:
                offset = self.offset
                end_offset = self.end_offset if self.end_offset not in {None, 0} else offset
                if offset == end_offset or end_offset == -1:
                    end_offset = offset + 1

                # Convert 1-based column offset to 0-based index into stripped text
                colno = offset - 1 - spaces
                end_colno = end_offset - 1 - spaces
                if colno >= 0:
                    # non-space whitespace (likes tabs) must be kept for alignment
                    caretspace = ((c if c.isspace() else ' ') for c in ltext[:colno])
                    yield '    {}{}'.format("".join(caretspace), ('^' * (end_colno - colno) + "\n"))
        msg = self.msg or "<no detail available>"
        yield "{}: {}{}\n".format(stype, msg, filename_suffix)
def _format_syntax_error ( self , stype ) : # Show exactly where the problem was found. filename_suffix = '' if self . lineno is not None : yield '  File "{}", line {}\n' . format ( self . filename or "<string>" , self . lineno ) elif self . filename is not None : filename_suffix = ' ({})' . format ( self . filename ) text = self . text if text is not None : # text  = "   foo\n" # rtext = "   foo" # ltext =    "foo" rtext = text . rstrip ( '\n' ) ltext = rtext . lstrip ( ' \n\f' ) spaces = len ( rtext ) - len ( ltext ) yield '    {}\n' . format ( ltext ) if self . offset is not None : offset = self . offset end_offset = self . end_offset if self . end_offset not in { None , 0 } else offset if offset == end_offset or end_offset == - 1 : end_offset = offset + 1 # Convert 1-based column offset to 0-based index into stripped text colno = offset - 1 - spaces end_colno = end_offset - 1 - spaces if colno >= 0 : # non-space whitespace (likes tabs) must be kept for alignment caretspace = ( ( c if c . isspace ( ) else ' ' ) for c in ltext [ : colno ] ) yield '    {}{}' . format ( "" . join ( caretspace ) , ( '^' * ( end_colno - colno ) + "\n" ) ) msg = self . msg or "<no detail available>" yield "{}: {}{}\n" . format ( stype , msg , filename_suffix )