<s> """<STR_LIT>""" <EOL> import tempfile <EOL> import os <EOL> if False : <EOL> from org . python . pydev . editor import PyEdit <EOL> cmd = '<STR_LIT>' <EOL> editor = PyEdit <EOL> SCRIPT = '<STR_LIT>' <EOL> ACTIVATION_STRING = '<STR_LIT>' <EOL> WAIT_FOR_ENTER = False <EOL> class Autopep8Wrapper ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . document = editor . getDocument ( ) <EOL> self . filename = editor . getEditorFile ( ) . getName ( ) <EOL> def get_filename ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . filename <EOL> def get_document ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . document <EOL> def parse ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . document . getNumberOfLines ( ) : <EOL> print '<STR_LIT>' <EOL> return <EOL> else : <EOL> tmp_input_file = tempfile . mktemp ( ) <EOL> tmp_output_file = tempfile . mktemp ( ) <EOL> input_file = open ( tmp_input_file , '<STR_LIT:w>' ) <EOL> text = self . document . get ( ) <EOL> input_file . write ( self . document . get ( ) ) <EOL> input_file . flush ( ) <EOL> input_file . close ( ) <EOL> os . system ( SCRIPT + '<STR_LIT>' % ( tmp_input_file , <EOL> tmp_output_file ) ) <EOL> output_file = open ( tmp_output_file , '<STR_LIT:r>' ) <EOL> tidy_text = output_file . read ( ) <EOL> output_file . close ( ) <EOL> self . document . replace ( <NUM_LIT:0> , len ( text ) , tidy_text ) <EOL> if os . path . exists ( tmp_input_file ) : <EOL> os . remove ( tmp_input_file ) <EOL> if os . path . exists ( tmp_output_file ) : <EOL> os . remove ( tmp_output_file ) <EOL> print '<STR_LIT>' <EOL> if cmd == '<STR_LIT>' : <EOL> class Autopep8 ( Action ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> formatter = Autopep8Wrapper ( ) <EOL> formatter . parse ( ) <EOL> editor . addOfflineActionListener ( ACTIVATION_STRING , Autopep8 ( ) , <EOL> '<STR_LIT>' , <EOL> WAIT_FOR_ENTER ) </s>
