def join_multiline_pairs(source, pair="<STR_LIT>"):
opener = pair[<NUM_LIT:0>]<EOL>closer = pair[<NUM_LIT:1>]<EOL>io_obj = io.StringIO(source)<EOL>out_tokens = []<EOL>open_count = <NUM_LIT:0><EOL>for tok in tokenize.generate_tokens(io_obj.readline):<EOL><INDENT>token_type = tok[<NUM_LIT:0>]<EOL>token_string = tok[<NUM_LIT:1>]<EOL>if token_type == tokenize.OP and token_string in pair:<EOL><INDENT>if token_string == opener:<EOL><INDENT>open_count += <NUM_LIT:1><EOL><DEDENT>elif token_string == closer:<EOL><INDENT>open_count -= <NUM_LIT:1><EOL><DEDENT>out_tokens.append(tok)<EOL><DEDENT>elif token_type in (tokenize.NL, tokenize.NEWLINE):<EOL><INDENT>if open_count == <NUM_LIT:0>:<EOL><INDENT>out_tokens.append(tok)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>out_tokens.append(tok)<EOL><DEDENT><DEDENT>return token_utils.untokenize(out_tokens)<EOL>
Finds and removes newlines in multiline matching pairs of characters in
*source*.

By default it joins parens () but it will join any two characters given via
the *pair* variable.

.. note::

    Doesn't remove extraneous whitespace that ends up between the pair.
    Use `reduce_operators()` for that.

Example::

    test = (
        "This is inside a multi-line pair of parentheses"
    )

Will become::

    test = (            "This is inside a multi-line pair of parentheses"        )