def replace_obfuscatables(module, tokens, obfunc, replace, name_generator, table=None):
<EOL>skip_line = False<EOL>skip_next = False<EOL>right_of_equal = False<EOL>inside_parens = <NUM_LIT:0><EOL>inside_function = False<EOL>indent = <NUM_LIT:0><EOL>function_indent = <NUM_LIT:0><EOL>replacement = next(name_generator)<EOL>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.NEWLINE:<EOL><INDENT>skip_line = False<EOL>right_of_equal = False<EOL>inside_parens = <NUM_LIT:0><EOL><DEDENT>elif token_type == tokenize.INDENT:<EOL><INDENT>indent += <NUM_LIT:1><EOL><DEDENT>elif token_type == tokenize.DEDENT:<EOL><INDENT>indent -= <NUM_LIT:1><EOL>if inside_function and function_indent == indent:<EOL><INDENT>function_indent = <NUM_LIT:0><EOL>inside_function = False<EOL><DEDENT><DEDENT>if token_string == "<STR_LIT>":<EOL><INDENT>function_indent = indent<EOL>function_name = tokens[index+<NUM_LIT:1>][<NUM_LIT:1>]<EOL>inside_function = function_name<EOL><DEDENT>result = obfunc(<EOL>tokens,<EOL>index,<EOL>replace,<EOL>replacement,<EOL>right_of_equal,<EOL>inside_parens,<EOL>inside_function<EOL>)<EOL>if result:<EOL><INDENT>if skip_next:<EOL><INDENT>skip_next = False<EOL><DEDENT>elif skip_line:<EOL><INDENT>pass<EOL><DEDENT>elif result == '<STR_LIT>':<EOL><INDENT>skip_line = True<EOL><DEDENT>elif result == '<STR_LIT>':<EOL><INDENT>skip_next = True<EOL><DEDENT>elif result == '<STR_LIT>':<EOL><INDENT>right_of_equal = False<EOL>inside_parens += <NUM_LIT:1><EOL><DEDENT>elif result == '<STR_LIT>':<EOL><INDENT>inside_parens -= <NUM_LIT:1><EOL><DEDENT>elif result == '<STR_LIT>':<EOL><INDENT>right_of_equal = False<EOL><DEDENT>elif result == '<STR_LIT>':<EOL><INDENT>if not inside_parens:<EOL><INDENT>right_of_equal = True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if table: <EOL><INDENT>combined_name = "<STR_LIT>" % (module, token_string)<EOL>try: <EOL><INDENT>tokens[index][<NUM_LIT:1>] = table[<NUM_LIT:0>][combined_name]<EOL><DEDENT>except KeyError: <EOL><INDENT>table[<NUM_LIT:0>].update({combined_name: result})<EOL>tokens[index][<NUM_LIT:1>] = result<EOL><DEDENT><DEDENT>else:<EOL><INDENT>tokens[index][<NUM_LIT:1>] = result<EOL><DEDENT><DEDENT><DEDENT><DEDENT>
Iterates over *tokens*, which must be an equivalent output to what
tokenize.generate_tokens() produces, replacing the given identifier name
(*replace*) by calling *obfunc* on each token with the following parameters:

    - **module:**       The name of the script we're currently obfuscating.
    - **tokens:**       The current list of all tokens.
    - **index:**        The current position.
    - **replace:**      The token string that we're replacing.
    - **replacement:**  A randomly generated, unique value that will be used to replace, *replace*.
    - **right_of_equal:**   A True or False value representing whether or not the token is to the right of an equal sign.  **Note:** This gets reset to False if a comma or open paren are encountered.
    - **inside_parens:**    An integer that is incremented whenever an open paren is encountered and decremented when a close paren is encountered.
    - **inside_function:**  If not False, the name of the function definition we're inside of (used in conjunction with *keyword_args* to determine if a safe replacement can be made).

*obfunc* is expected to return the token string if that token can be safely
obfuscated **or** one of the following optional values which will instruct
find_obfuscatables() how to proceed:

    - **'__open_paren__'**        Increment the inside_parens value
    - **'__close_paren__'**       Decrement the inside_parens value
    - **'__comma__'**             Reset the right_of_equal value to False
    - **'__right_of_equal__'**    Sets the right_of_equal value to True

**Note:** The right_of_equal and the inside_parens values are reset whenever a NEWLINE is encountered.

When obfuscating a list of files, *table* is used to keep track of which
obfuscatable identifiers are which inside each resulting file.  It must be
an empty dictionary that will be populated like so::

    {orig_name: obfuscated_name}

This *table* of "what is what" will be used to ensure that references from
one script/module that call another are kept in sync when they are replaced
with obfuscated values.