def trailing_whitespace(physical_line):
    """
    JCR: Trailing whitespace is superfluous.
    FBM: Except when it occurs as part of a blank line (i.e. the line is
         nothing but whitespace). According to Python docs[1] a line with only
         whitespace is considered a blank line, and is to be ignored. However,
         matching a blank line to its indentation level avoids mistakenly
         terminating a multi-line statement (e.g. class declaration) when
         pasting code into the standard Python interpreter.

         [1] http://docs.python.org/reference/lexical_analysis.html#blank-lines

    The warning returned varies on whether the line itself is blank, for easier
    filtering for those who want to indent their blank lines.

    >>> trailing_whitespace('SELECT 1   ')
    (8, 'W291 trailing whitespace')
    >>> trailing_whitespace('   ')
    (0, 'W293 blank line contains whitespace')
    >>> trailing_whitespace('SELECT 1')
    >>> trailing_whitespace('')
    """
    physical_line = physical_line.rstrip('\n')
    physical_line = physical_line.rstrip('\r')
    physical_line = physical_line.rstrip('\x0c')
    stripped = physical_line.rstrip()
    if physical_line != stripped:
        if stripped:
            return len(stripped), 'W291 trailing whitespace'
        else:
            return 0, 'W293 blank line contains whitespace'
