<s> """<STR_LIT>""" <EOL> import io <EOL> import os <EOL> import sys <EOL> import textwrap <EOL> import pyflakes . api <EOL> import pyflakes . messages <EOL> import pyflakes . reporter <EOL> import autopep8 <EOL> def split_readme ( readme_path , before_key , after_key , options_key , end_key ) : <EOL> """<STR_LIT>""" <EOL> with open ( readme_path ) as readme_file : <EOL> readme = readme_file . read ( ) <EOL> top , rest = readme . split ( before_key ) <EOL> before , rest = rest . split ( after_key ) <EOL> _ , rest = rest . split ( options_key ) <EOL> _ , bottom = rest . split ( end_key ) <EOL> return ( top . rstrip ( '<STR_LIT:\n>' ) , <EOL> before . strip ( '<STR_LIT:\n>' ) , <EOL> end_key + '<STR_LIT>' + bottom . lstrip ( '<STR_LIT:\n>' ) ) <EOL> def indent_line ( line ) : <EOL> """<STR_LIT>""" <EOL> if line : <EOL> return <NUM_LIT:4> * '<STR_LIT:U+0020>' + line <EOL> else : <EOL> return line <EOL> def indent ( text ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:\n>' . join ( indent_line ( line ) for line in text . split ( '<STR_LIT:\n>' ) ) <EOL> def help_message ( ) : <EOL> """<STR_LIT>""" <EOL> parser = autopep8 . create_parser ( ) <EOL> string_io = io . StringIO ( ) <EOL> parser . print_help ( string_io ) <EOL> return string_io . getvalue ( ) . replace ( os . path . expanduser ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def check ( source ) : <EOL> """<STR_LIT>""" <EOL> compile ( source , '<STR_LIT>' , '<STR_LIT>' , dont_inherit = True ) <EOL> reporter = pyflakes . reporter . Reporter ( sys . stderr , sys . stderr ) <EOL> pyflakes . api . check ( source , filename = '<STR_LIT>' , reporter = reporter ) <EOL> def main ( ) : <EOL> readme_path = '<STR_LIT>' <EOL> before_key = '<STR_LIT>' <EOL> after_key = '<STR_LIT>' <EOL> options_key = '<STR_LIT>' <EOL> ( top , before , bottom ) = split_readme ( readme_path , <EOL> before_key = before_key , <EOL> after_key = after_key , <EOL> options_key = options_key , <EOL> end_key = '<STR_LIT>' ) <EOL> input_code = textwrap . dedent ( before ) <EOL> output_code = autopep8 . fix_code ( <EOL> input_code , <EOL> options = { '<STR_LIT>' : <NUM_LIT:2> } ) <EOL> check ( output_code ) <EOL> new_readme = '<STR_LIT>' . join ( [ <EOL> top , <EOL> before_key , before , <EOL> after_key , indent ( output_code ) . rstrip ( ) , <EOL> options_key , indent ( help_message ( ) ) , <EOL> bottom ] ) <EOL> with open ( readme_path , '<STR_LIT:w>' ) as output_file : <EOL> output_file . write ( new_readme ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
