<s> import sublime <EOL> import sublime_plugin <EOL> import json <EOL> from os . path import dirname , realpath , join , splitext , basename <EOL> try : <EOL> from node_bridge import node_bridge <EOL> except : <EOL> from . node_bridge import node_bridge <EOL> sublime . Region . totuple = lambda self : ( self . a , self . b ) <EOL> sublime . Region . __iter__ = lambda self : self . totuple ( ) . __iter__ ( ) <EOL> BIN_PATH = join ( sublime . packages_path ( ) , dirname ( realpath ( __file__ ) ) , '<STR_LIT>' ) <EOL> def get_setting ( view , key ) : <EOL> settings = view . settings ( ) . get ( '<STR_LIT>' ) <EOL> if settings is None : <EOL> settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> return settings . get ( key ) <EOL> def is_css ( view ) : <EOL> return splitext ( basename ( view . settings ( ) . get ( '<STR_LIT>' ) ) ) [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> class AutoprefixerCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit ) : <EOL> if not self . has_selection ( ) : <EOL> region = sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) <EOL> originalBuffer = self . view . substr ( region ) <EOL> prefixed = self . prefix ( originalBuffer ) <EOL> if prefixed : <EOL> self . view . replace ( edit , region , prefixed ) <EOL> return <EOL> for region in self . view . sel ( ) : <EOL> if region . empty ( ) : <EOL> continue <EOL> originalBuffer = self . view . substr ( region ) <EOL> prefixed = self . prefix ( originalBuffer ) <EOL> if prefixed : <EOL> self . view . replace ( edit , region , prefixed ) <EOL> def prefix ( self , data ) : <EOL> try : <EOL> return node_bridge ( data , BIN_PATH , [ json . dumps ( { <EOL> '<STR_LIT>' : get_setting ( self . view , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : get_setting ( self . view , '<STR_LIT>' ) <EOL> } ) ] ) <EOL> except Exception as e : <EOL> sublime . error_message ( '<STR_LIT>' % e ) <EOL> def has_selection ( self ) : <EOL> for sel in self . view . sel ( ) : <EOL> start , end = sel <EOL> if start != end : <EOL> return True <EOL> return False <EOL> class AutoprefixerPreSaveCommand ( sublime_plugin . EventListener ) : <EOL> def on_pre_save ( self , view ) : <EOL> if get_setting ( view , '<STR_LIT>' ) is True and is_css ( view ) : <EOL> view . run_command ( '<STR_LIT>' ) </s>
