<s> import sublime <EOL> import os <EOL> import re <EOL> from . ml_settings import MlSettings <EOL> SETTINGS_FILE = "<STR_LIT>" <EOL> class MlUtils : <EOL> __module_import_regex__ = re . compile ( r"<STR_LIT>" , re . M | re . DOTALL ) <EOL> @ staticmethod <EOL> def log ( log_me ) : <EOL> if ( MlSettings . debug ( ) ) : <EOL> print ( "<STR_LIT>" % log_me ) <EOL> @ staticmethod <EOL> def load_resource ( name ) : <EOL> if hasattr ( sublime , '<STR_LIT>' ) : <EOL> return sublime . load_resource ( name ) <EOL> else : <EOL> with open ( os . path . join ( sublime . packages_path ( ) , name [ <NUM_LIT:9> : ] ) ) as f : <EOL> return f . read ( ) <EOL> @ staticmethod <EOL> def is_server_side_js ( view ) : <EOL> return view . score_selector ( view . sel ( ) [ <NUM_LIT:0> ] . a , '<STR_LIT>' ) > <NUM_LIT:0> <EOL> @ staticmethod <EOL> def get_namespace ( s ) : <EOL> ns_str = r"""<STR_LIT>""" <EOL> ns_re = re . compile ( ns_str ) <EOL> sans_comments = re . sub ( r"<STR_LIT>" , "<STR_LIT>" , s ) <EOL> match = ns_re . search ( sans_comments ) <EOL> print ( "<STR_LIT>" % str ( match ) ) <EOL> if ( match ) : <EOL> return ( match . group ( <NUM_LIT:2> ) , match . group ( <NUM_LIT:4> ) ) <EOL> else : <EOL> return ( None , None ) <EOL> @ staticmethod <EOL> def get_function_defs ( file_name , buffer , ns_prefix , show_private ) : <EOL> functions = [ ] <EOL> if ( show_private ) : <EOL> private_re = "<STR_LIT>" <EOL> else : <EOL> private_re = "<STR_LIT>" <EOL> function_str = r"""<STR_LIT>""" % private_re <EOL> function_re = re . compile ( function_str , re . S | re . M | re . X ) <EOL> for match in function_re . findall ( buffer , re . DOTALL | re . M | re . X ) : <EOL> if ns_prefix and ns_prefix != '<STR_LIT>' : <EOL> func = re . sub ( r"<STR_LIT>" , "<STR_LIT>" % ns_prefix , match [ <NUM_LIT:0> ] ) <EOL> else : <EOL> func = re . sub ( r"<STR_LIT>" , "<STR_LIT>" , match [ <NUM_LIT:0> ] ) <EOL> params = [ ] <EOL> pre_params = re . sub ( r"<STR_LIT>" , "<STR_LIT:$>" , match [ <NUM_LIT:1> ] ) <EOL> pre_params = re . sub ( r"<STR_LIT>" , "<STR_LIT>" , pre_params ) <EOL> if ( len ( pre_params ) > <NUM_LIT:0> ) : <EOL> params = re . split ( r"<STR_LIT:U+002C>" , pre_params ) <EOL> functions . append ( ( func , params ) ) <EOL> return functions <EOL> @ staticmethod <EOL> def get_imported_files ( file_name , buffer ) : <EOL> files = [ ] <EOL> search_paths = MlSettings ( ) . get_search_paths ( ) <EOL> if ( search_paths ) : <EOL> for match in MlUtils . __module_import_regex__ . findall ( buffer , re . DOTALL | re . M ) : <EOL> ns_prefix = match [ <NUM_LIT:2> ] <EOL> uri = match [ <NUM_LIT:3> ] <EOL> for search_path in search_paths : <EOL> if ( uri [ <NUM_LIT:0> ] == '<STR_LIT:/>' ) : <EOL> f = os . path . join ( search_path , uri [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> f = os . path . join ( os . path . dirname ( file_name ) , uri ) <EOL> if ( os . path . exists ( f ) ) : <EOL> files . append ( ( f , ns_prefix ) ) <EOL> return files </s>
