<s> import sys <EOL> import subprocess <EOL> import sublime <EOL> DEFAULT_OPEN_LINK_COMMANDS = dict ( <EOL> darwin = [ '<STR_LIT>' ] , <EOL> win32 = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:start>' ] , <EOL> linux = [ '<STR_LIT>' ] , <EOL> ) <EOL> class AbstractLinkResolver ( object ) : <EOL> def __init__ ( self , view ) : <EOL> self . view = view <EOL> self . settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> self . link_commands = self . settings . get ( <EOL> '<STR_LIT>' , DEFAULT_OPEN_LINK_COMMANDS ) <EOL> def extract ( self , content ) : <EOL> return content <EOL> def replace ( self , content ) : <EOL> return content <EOL> def resolve ( self , content ) : <EOL> match = self . extract ( content ) <EOL> if not match : <EOL> return None <EOL> return self . replace ( match ) <EOL> def get_link_command ( self ) : <EOL> platform = sys . platform <EOL> for key , val in self . link_commands . items ( ) : <EOL> if key in platform : <EOL> return val <EOL> return None <EOL> def execute ( self , content ) : <EOL> command = self . get_link_command ( ) <EOL> if not command : <EOL> sublime . error_message ( <EOL> '<STR_LIT>' ) <EOL> return None <EOL> if sys . version_info [ <NUM_LIT:0> ] < <NUM_LIT:3> : <EOL> content = content . encode ( sys . getfilesystemencoding ( ) ) <EOL> cmd = command + [ content ] <EOL> arg_list_wrapper = self . settings . get ( <EOL> "<STR_LIT>" , [ ] ) <EOL> if arg_list_wrapper : <EOL> cmd = arg_list_wrapper + [ '<STR_LIT:U+0020>' . join ( cmd ) ] <EOL> source_filename = '<STR_LIT>' + self . view . file_name ( ) + '<STR_LIT>' <EOL> cmd += [ source_filename ] <EOL> if sys . platform != '<STR_LIT:win32>' : <EOL> cmd += [ '<STR_LIT>' , source_filename , '<STR_LIT>' ] <EOL> print ( '<STR_LIT>' ) <EOL> print ( repr ( content ) , content ) <EOL> print ( cmd ) <EOL> sublime . status_message ( '<STR_LIT>' % cmd ) <EOL> if sys . platform != '<STR_LIT:win32>' : <EOL> process = subprocess . Popen ( <EOL> cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> else : <EOL> process = subprocess . Popen ( <EOL> cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE , shell = True ) <EOL> stdout , stderr = process . communicate ( ) <EOL> if stdout : <EOL> stdout = str ( stdout , sys . getfilesystemencoding ( ) ) <EOL> sublime . status_message ( stdout ) <EOL> if stderr : <EOL> stderr = str ( stderr , sys . getfilesystemencoding ( ) ) <EOL> sublime . error_message ( stderr ) <EOL> class AbstractRegexLinkResolver ( AbstractLinkResolver ) : <EOL> def __init__ ( self , view ) : <EOL> self . view = view <EOL> self . settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> self . link_commands = self . settings . get ( <EOL> '<STR_LIT>' , DEFAULT_OPEN_LINK_COMMANDS ) <EOL> self . regex = None <EOL> def extract ( self , content ) : <EOL> if self . regex is None : <EOL> return content <EOL> match = self . regex . match ( content ) <EOL> return match <EOL> def replace ( self , match ) : <EOL> return match . groups ( ) [ <NUM_LIT:1> ] </s>
