<s> import sublime , sublime_plugin <EOL> import os <EOL> from helper import getCkstylePath <EOL> class FixstyleCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit ) : <EOL> path = os . path . realpath ( self . view . file_name ( ) . decode ( '<STR_LIT:utf-8>' ) ) <EOL> if os . path . splitext ( path ) [ <NUM_LIT:1> ] != '<STR_LIT>' : <EOL> sublime . error_message ( '<STR_LIT>' ) <EOL> return <EOL> cmd = getCkstylePath ( ) + '<STR_LIT>' + path + '<STR_LIT:">' <EOL> returnValue = os . popen3 ( cmd ) <EOL> returnValue = returnValue [ <NUM_LIT:1> ] . read ( ) + returnValue [ <NUM_LIT:2> ] . read ( ) <EOL> if returnValue . find ( '<STR_LIT>' ) != - <NUM_LIT:1> : <EOL> sublime . error_message ( returnValue ) <EOL> else : <EOL> region = sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) <EOL> msg = self . getRealMsg ( returnValue ) <EOL> try : <EOL> self . view . replace ( edit , region , msg ) <EOL> except Exception : <EOL> sublime . error_message ( '<STR_LIT>' ) ; <EOL> self . view . end_edit ( edit ) <EOL> def getRealMsg ( self , msg ) : <EOL> for charset in [ '<STR_LIT:utf-8>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> try : <EOL> msg . decode ( charset ) <EOL> return msg . decode ( charset ) <EOL> except Exception : <EOL> pass <EOL> return msg </s>
