def extract_docstring(filename):
lines = file(filename).readlines()<EOL>start_row = <NUM_LIT:0><EOL>if lines[<NUM_LIT:0>].startswith('<STR_LIT>'):<EOL><INDENT>lines.pop(<NUM_LIT:0>)<EOL>start_row = <NUM_LIT:1><EOL><DEDENT>docstring = '<STR_LIT>'<EOL>first_par = '<STR_LIT>'<EOL>tokens = tokenize.generate_tokens(iter(lines).next)<EOL>for tok_type, tok_content, _, (erow, _), _ in tokens:<EOL><INDENT>tok_type = token.tok_name[tok_type]<EOL>if tok_type in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>elif tok_type == '<STR_LIT>':<EOL><INDENT>docstring = eval(tok_content)<EOL>paragraphs = '<STR_LIT:\n>'.join(line.rstrip()<EOL>for line in docstring.split('<STR_LIT:\n>')).split('<STR_LIT>')<EOL>if len(paragraphs) > <NUM_LIT:0>:<EOL><INDENT>first_par = paragraphs[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>break<EOL><DEDENT>end_row = erow + <NUM_LIT:1> + start_row<EOL>if lines and lines[end_row - <NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>end_row += <NUM_LIT:1><EOL><DEDENT>return docstring, first_par, end_row<EOL>
Extract a module-level docstring, if any