def obfuscate_global_import_methods(module, tokens, name_generator, table=None):
global_imports = analyze.enumerate_global_imports(tokens)<EOL>local_imports = analyze.enumerate_local_modules(tokens, os.getcwd())<EOL>module_methods = analyze.enumerate_import_methods(tokens)<EOL>if table:<EOL><INDENT>replacement_dict = {}<EOL>for module_method in module_methods:<EOL><INDENT>if module_method in table[<NUM_LIT:0>].keys():<EOL><INDENT>replacement_dict.update({module_method: table[<NUM_LIT:0>][module_method]})<EOL><DEDENT>else:<EOL><INDENT>replacement_dict.update({module_method: next(name_generator)})<EOL><DEDENT><DEDENT>table[<NUM_LIT:0>].update(replacement_dict)<EOL><DEDENT>else:<EOL><INDENT>method_map = [next(name_generator) for i in module_methods]<EOL>replacement_dict = dict(zip(module_methods, method_map))<EOL><DEDENT>import_line = False<EOL>for module_method in module_methods:<EOL><INDENT>for index, tok in enumerate(tokens):<EOL><INDENT>token_type = tok[<NUM_LIT:0>]<EOL>token_string = tok[<NUM_LIT:1>]<EOL>if token_type != tokenize.NAME:<EOL><INDENT>continue <EOL><DEDENT>tokens[index+<NUM_LIT:1>][<NUM_LIT:1>]<EOL>if token_string == module_method.split('<STR_LIT:.>')[<NUM_LIT:0>]:<EOL><INDENT>if tokens[index+<NUM_LIT:1>][<NUM_LIT:1>] == '<STR_LIT:.>':<EOL><INDENT>if tokens[index+<NUM_LIT:2>][<NUM_LIT:1>] == module_method.split('<STR_LIT:.>')[<NUM_LIT:1>]:<EOL><INDENT>if table: <EOL><INDENT>tokens[index][<NUM_LIT:1>] = table[<NUM_LIT:0>][module_method]<EOL>tokens[index+<NUM_LIT:1>][<NUM_LIT:1>] = "<STR_LIT>"<EOL>tokens[index+<NUM_LIT:2>][<NUM_LIT:1>] = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>tokens[index][<NUM_LIT:1>] = replacement_dict[module_method]<EOL>tokens[index+<NUM_LIT:1>][<NUM_LIT:1>] = "<STR_LIT>"<EOL>tokens[index+<NUM_LIT:2>][<NUM_LIT:1>] = "<STR_LIT>"<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>for module_method, replacement in replacement_dict.items():<EOL><INDENT>indents = []<EOL>index = <NUM_LIT:0><EOL>for tok in tokens[:]:<EOL><INDENT>token_type = tok[<NUM_LIT:0>]<EOL>token_string = tok[<NUM_LIT:1>]<EOL>if token_type == tokenize.NEWLINE:<EOL><INDENT>import_line = False<EOL><DEDENT>elif token_type == tokenize.INDENT:<EOL><INDENT>indents.append(tok)<EOL><DEDENT>elif token_type == tokenize.DEDENT:<EOL><INDENT>indents.pop()<EOL><DEDENT>elif token_string == "<STR_LIT>":<EOL><INDENT>import_line = True<EOL><DEDENT>elif import_line:<EOL><INDENT>if token_string == module_method.split('<STR_LIT:.>')[<NUM_LIT:0>]:<EOL><INDENT>imported_module = "<STR_LIT:.>".join(module_method.split('<STR_LIT:.>')[:-<NUM_LIT:1>])<EOL>if table and imported_module in local_imports:<EOL><INDENT>line = "<STR_LIT>" % ( <EOL>replacement_dict[module_method],<EOL>imported_module,<EOL>replacement_dict[module_method]<EOL>)<EOL><DEDENT>else:<EOL><INDENT>line = "<STR_LIT>" % ( <EOL>replacement_dict[module_method], module_method)<EOL><DEDENT>for indent in indents: <EOL><INDENT>line = "<STR_LIT>" % (indent[<NUM_LIT:1>], line)<EOL>index += <NUM_LIT:1><EOL><DEDENT>insert_in_next_line(tokens, index, line)<EOL>index += <NUM_LIT:6> <EOL><DEDENT><DEDENT>index += <NUM_LIT:1><EOL><DEDENT><DEDENT>
Replaces the used methods of globally-imported modules with obfuscated
equivalents.  Updates *tokens* in-place.

*module* must be the name of the module we're currently obfuscating

If *table* is provided, replacements for import methods will be attempted
to be looked up there before generating a new unique name.