def check(codeString, filename):
<EOL>try:<EOL><INDENT>tree = compile(codeString, filename, "<STR_LIT>", ast.PyCF_ONLY_AST)<EOL><DEDENT>except SyntaxError as value:<EOL><INDENT>msg = value.args[<NUM_LIT:0>]<EOL>(lineno, offset, text) = value.lineno, value.offset, value.text<EOL>if text is None:<EOL><INDENT>sys.stderr.write("<STR_LIT>" % (filename, ))<EOL><DEDENT>else:<EOL><INDENT>line = text.splitlines()[-<NUM_LIT:1>]<EOL>if offset is not None:<EOL><INDENT>offset = offset - (len(text) - len(line))<EOL><DEDENT>sys.stderr.write('<STR_LIT>' % (filename, lineno, msg))<EOL>sys.stderr.write(line + '<STR_LIT:\n>')<EOL>if offset is not None:<EOL><INDENT>sys.stderr.write("<STR_LIT:U+0020>" * offset + "<STR_LIT>")<EOL><DEDENT><DEDENT>return <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>w = checker.Checker(tree, filename)<EOL>lines = codeString.split('<STR_LIT:\n>')<EOL>messages = [message for message in w.messages<EOL>if lines[message.lineno - <NUM_LIT:1>].find('<STR_LIT>') < <NUM_LIT:0>]<EOL>messages.sort(lambda a, b: cmp(a.lineno, b.lineno))<EOL>false_positives = <NUM_LIT:0><EOL>for warning in messages:<EOL><INDENT>if not (re.match('<STR_LIT>', str(warning))<EOL>and isinstance(warning, (UnusedImport, ImportStarUsed))):<EOL><INDENT>print(warning)<EOL><DEDENT>else:<EOL><INDENT>false_positives += <NUM_LIT:1><EOL><DEDENT><DEDENT>return len(messages) - false_positives<EOL><DEDENT>
Check the Python source given by C{codeString} for flakes.

@param codeString: The Python source to check.
@type codeString: C{str}

@param filename: The name of the file the source came from, used to report
    errors.
@type filename: C{str}

@return: The number of warnings emitted.
@rtype: C{int}