@export<EOL>def open_external_editor(filename=None, sql=None):
message = None<EOL>filename = filename.strip().split('<STR_LIT:U+0020>', <NUM_LIT:1>)[<NUM_LIT:0>] if filename else None<EOL>sql = sql or '<STR_LIT>'<EOL>MARKER = '<STR_LIT>'<EOL>query = click.edit(u'<STR_LIT>'.format(sql=sql, marker=MARKER),<EOL>filename=filename, extension='<STR_LIT>')<EOL>if filename:<EOL><INDENT>try:<EOL><INDENT>with open(filename, encoding='<STR_LIT:utf-8>') as f:<EOL><INDENT>query = f.read()<EOL><DEDENT><DEDENT>except IOError:<EOL><INDENT>message = '<STR_LIT>' % filename<EOL><DEDENT><DEDENT>if query is not None:<EOL><INDENT>query = query.split(MARKER, <NUM_LIT:1>)[<NUM_LIT:0>].rstrip('<STR_LIT:\n>')<EOL><DEDENT>else:<EOL><INDENT>query = sql<EOL><DEDENT>return (query, message)<EOL>
Open external editor, wait for the user to type in their query, return
    the query.
    :return: list with one tuple, query as first element.