def mangle_signature(sig, max_chars=<NUM_LIT:30>):
s = re.sub(r"<STR_LIT>", r"<STR_LIT>", sig).strip()<EOL>s = re.sub(r"<STR_LIT>", "<STR_LIT>", s)<EOL>s = re.sub(r"<STR_LIT>", "<STR_LIT>", s)<EOL>s = re.sub(r"<STR_LIT>", "<STR_LIT>", s)<EOL>args = []<EOL>opts = []<EOL>opt_re = re.compile(r"<STR_LIT>")<EOL>while s:<EOL><INDENT>m = opt_re.search(s)<EOL>if not m:<EOL><INDENT>args = s.split('<STR_LIT:U+002CU+0020>')<EOL>break<EOL><DEDENT>opts.insert(<NUM_LIT:0>, m.group(<NUM_LIT:2>))<EOL>s = m.group(<NUM_LIT:1>)[:-<NUM_LIT:2>]<EOL><DEDENT>sig = limited_join("<STR_LIT:U+002CU+0020>", args, max_chars=max_chars-<NUM_LIT:2>)<EOL>if opts:<EOL><INDENT>if not sig:<EOL><INDENT>sig = "<STR_LIT>" % limited_join("<STR_LIT:U+002CU+0020>", opts, max_chars=max_chars-<NUM_LIT:4>)<EOL><DEDENT>elif len(sig) < max_chars - <NUM_LIT:4> - <NUM_LIT:2> - <NUM_LIT:3>:<EOL><INDENT>sig += "<STR_LIT>" % limited_join("<STR_LIT:U+002CU+0020>", opts,<EOL>max_chars=max_chars-len(sig)-<NUM_LIT:4>-<NUM_LIT:2>)<EOL><DEDENT><DEDENT>return "<STR_LIT>" % sig<EOL>
Reformat a function signature to a more compact form.