Parser for python source files



Remove any common leading whitespace from every line in text.

This can be used to make triple-quoted strings line up with the left edge of the display, while still presenting them in the source code in indented form.

Note that tabs and spaces are both treated as whitespace, but they are not equal: the lines ” hello” and “thello” are considered to have no common leading whitespace. (This behaviour is new in Python 2.5; older versions of this module incorrectly expanded tabs before searching for common leading whitespace.)


Separate filename content between docstring and the rest

Strongly inspired from ast.get_docstring.

  • docstring (str) – docstring of filename
  • rest (str) – filename content without the docstring

Return list with source file separated into code and text blocks.

Returns:blocks – List where each element is a tuple with the label (‘text’ or ‘code’), and content string of block.
Return type:list of (label, content)