def escape_header(val):
if val is None:<EOL><INDENT>return None<EOL><DEDENT>try:<EOL><INDENT>return quote(val, encoding="<STR_LIT:ascii>", safe="<STR_LIT>")<EOL><DEDENT>except ValueError:<EOL><INDENT>return "<STR_LIT>" + quote(val, encoding="<STR_LIT:utf-8>", safe="<STR_LIT>")<EOL><DEDENT>
Escapes a value so that it can be used in a mime header