1
0
forked from VimPlug/jedi
This commit is contained in:
David Halter
2013-02-06 13:00:23 +01:00
parent 8cf783f2c3
commit 69137a48f0
6 changed files with 26 additions and 19 deletions

View File

@@ -373,13 +373,15 @@ def source_to_unicode(source, encoding=None):
http://docs.python.org/2/reference/lexical_analysis.html#encoding-\
declarations
"""
byte_mark = '\xef\xbb\xbf' if is_py25 else literal_eval(r"b'\xef\xbb\xbf'")
byte_mark = '\xef\xbb\xbf' if is_py25 else \
literal_eval(r"b'\xef\xbb\xbf'")
if source.startswith(byte_mark):
# UTF-8 byte-order mark
return 'utf-8'
first_two_lines = re.match(r'(?:[^\n]*\n){0,2}', str(source)).group(0)
possible_encoding = re.search(r"coding[=:]\s*([-\w.]+)", first_two_lines)
possible_encoding = re.search(r"coding[=:]\s*([-\w.]+)",
first_two_lines)
if possible_encoding:
return possible_encoding.group(1)
else: