def expand_mentions(text, embed_names=True):
if embed_names:<EOL><INDENT>mention_format = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>mention_format = "<STR_LIT>"<EOL><DEDENT>def handle_mention(match):<EOL><INDENT>source = get_source_by_name(match.group(<NUM_LIT:1>))<EOL>if source is None:<EOL><INDENT>return "<STR_LIT>".format(match.group(<NUM_LIT:1>))<EOL><DEDENT>return mention_format.format(<EOL>name=source.nick,<EOL>url=source.url)<EOL><DEDENT>return short_mention_re.sub(handle_mention, text)<EOL>
Searches the given text for mentions and expands them.

    For example:
    "@source.nick" will be expanded to "@<source.nick source.url>".