Return the one-line summary of a file object, if present
(file)
| 387 | return False |
| 388 | |
| 389 | def source_synopsis(file): |
| 390 | """Return the one-line summary of a file object, if present""" |
| 391 | |
| 392 | string = '' |
| 393 | try: |
| 394 | tokens = tokenize.generate_tokens(file.readline) |
| 395 | for tok_type, tok_string, _, _, _ in tokens: |
| 396 | if tok_type == tokenize.STRING: |
| 397 | string += tok_string |
| 398 | elif tok_type == tokenize.NEWLINE: |
| 399 | with warnings.catch_warnings(): |
| 400 | # Ignore the "invalid escape sequence" warning. |
| 401 | warnings.simplefilter("ignore", SyntaxWarning) |
| 402 | docstring = ast.literal_eval(string) |
| 403 | if not isinstance(docstring, str): |
| 404 | return None |
| 405 | return docstring.strip().split('\n')[0].strip() |
| 406 | elif tok_type == tokenize.OP and tok_string in ('(', ')'): |
| 407 | string += tok_string |
| 408 | elif tok_type not in (tokenize.COMMENT, tokenize.NL, tokenize.ENCODING): |
| 409 | return None |
| 410 | except (tokenize.TokenError, UnicodeDecodeError, SyntaxError): |
| 411 | return None |
| 412 | return None |
| 413 | |
| 414 | def synopsis(filename, cache={}): |
| 415 | """Get the one-line summary out of a module file.""" |
no test coverage detected