def run(self, mod):
if not mod.body:<EOL><INDENT>return<EOL><DEDENT>aliases = [<EOL>ast.alias(six.moves.builtins.__name__, "<STR_LIT>"),<EOL>ast.alias("<STR_LIT>", "<STR_LIT>"),<EOL>]<EOL>doc = getattr(mod, "<STR_LIT>", None)<EOL>expect_docstring = doc is None<EOL>if doc is not None and self.is_rewrite_disabled(doc):<EOL><INDENT>return<EOL><DEDENT>pos = <NUM_LIT:0><EOL>lineno = <NUM_LIT:1><EOL>for item in mod.body:<EOL><INDENT>if (<EOL>expect_docstring<EOL>and isinstance(item, ast.Expr)<EOL>and isinstance(item.value, ast.Str)<EOL>):<EOL><INDENT>doc = item.value.s<EOL>if self.is_rewrite_disabled(doc):<EOL><INDENT>return<EOL><DEDENT>expect_docstring = False<EOL><DEDENT>elif (<EOL>not isinstance(item, ast.ImportFrom)<EOL>or item.level > <NUM_LIT:0><EOL>or item.module != "<STR_LIT>"<EOL>):<EOL><INDENT>lineno = item.lineno<EOL>break<EOL><DEDENT>pos += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>lineno = item.lineno<EOL><DEDENT>imports = [<EOL>ast.Import([alias], lineno=lineno, col_offset=<NUM_LIT:0>) for alias in aliases<EOL>]<EOL>mod.body[pos:pos] = imports<EOL>nodes = [mod]<EOL>while nodes:<EOL><INDENT>node = nodes.pop()<EOL>for name, field in ast.iter_fields(node):<EOL><INDENT>if isinstance(field, list):<EOL><INDENT>new = []<EOL>for i, child in enumerate(field):<EOL><INDENT>if isinstance(child, ast.Assert):<EOL><INDENT>new.extend(self.visit(child))<EOL><DEDENT>else:<EOL><INDENT>new.append(child)<EOL>if isinstance(child, ast.AST):<EOL><INDENT>nodes.append(child)<EOL><DEDENT><DEDENT><DEDENT>setattr(node, name, new)<EOL><DEDENT>elif (<EOL>isinstance(field, ast.AST)<EOL>and not isinstance(field, ast.expr)<EOL>):<EOL><INDENT>nodes.append(field)<EOL><DEDENT><DEDENT><DEDENT>
Find all assert statements in *mod* and rewrite them.