def source_encoding(source):
<EOL>assert sys.version_info < (<NUM_LIT:3>, <NUM_LIT:0>)<EOL>cookie_re = re.compile(r"<STR_LIT>")<EOL>readline = iter(source.splitlines(True)).next<EOL>def _get_normal_name(orig_enc):<EOL><INDENT>"""<STR_LIT>"""<EOL>enc = orig_enc[:<NUM_LIT:12>].lower().replace("<STR_LIT:_>", "<STR_LIT:->")<EOL>if re.match(r"<STR_LIT>", enc):<EOL><INDENT>return "<STR_LIT:utf-8>"<EOL><DEDENT>if re.match(r"<STR_LIT>", enc):<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>return orig_enc<EOL><DEDENT>if sys.version_info <= (<NUM_LIT:2>, <NUM_LIT:4>):<EOL><INDENT>default = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>default = '<STR_LIT:ascii>'<EOL><DEDENT>bom_found = False<EOL>encoding = None<EOL>def read_or_stop():<EOL><INDENT>"""<STR_LIT>"""<EOL>try:<EOL><INDENT>return readline()<EOL><DEDENT>except StopIteration:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT><DEDENT>def find_cookie(line):<EOL><INDENT>"""<STR_LIT>"""<EOL>try:<EOL><INDENT>line_string = line.decode('<STR_LIT:ascii>')<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>return None<EOL><DEDENT>matches = cookie_re.findall(line_string)<EOL>if not matches:<EOL><INDENT>return None<EOL><DEDENT>encoding = _get_normal_name(matches[<NUM_LIT:0>])<EOL>try:<EOL><INDENT>codec = codecs.lookup(encoding)<EOL><DEDENT>except LookupError:<EOL><INDENT>raise SyntaxError("<STR_LIT>" + encoding)<EOL><DEDENT>if bom_found:<EOL><INDENT>codec_name = getattr(codec, '<STR_LIT:name>', encoding)<EOL>if codec_name != '<STR_LIT:utf-8>':<EOL><INDENT>raise SyntaxError('<STR_LIT>')<EOL><DEDENT>encoding += '<STR_LIT>'<EOL><DEDENT>return encoding<EOL><DEDENT>first = read_or_stop()<EOL>if first.startswith(codecs.BOM_UTF8):<EOL><INDENT>bom_found = True<EOL>first = first[<NUM_LIT:3>:]<EOL>default = '<STR_LIT>'<EOL><DEDENT>if not first:<EOL><INDENT>return default<EOL><DEDENT>encoding = find_cookie(first)<EOL>if encoding:<EOL><INDENT>return encoding<EOL><DEDENT>second = read_or_stop()<EOL>if not second:<EOL><INDENT>return default<EOL><DEDENT>encoding = find_cookie(second)<EOL>if encoding:<EOL><INDENT>return encoding<EOL><DEDENT>return default<EOL>
Determine the encoding for `source` (a string), according to PEP 263.

    Returns a string, the name of the encoding.