mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-19 02:46:01 +08:00
Get escaping issues working in all versions.
This commit is contained in:
@@ -541,9 +541,16 @@ class ErrorFinder(Normalizer):
|
|||||||
is_bytes = True
|
is_bytes = True
|
||||||
if 'u' in string_prefix:
|
if 'u' in string_prefix:
|
||||||
is_bytes = False
|
is_bytes = False
|
||||||
func = codecs.escape_decode if is_bytes else codecs.unicode_escape_decode
|
|
||||||
|
payload = leaf._get_payload()
|
||||||
|
if is_bytes:
|
||||||
|
payload = payload.encode('utf-8')
|
||||||
|
func = codecs.escape_decode
|
||||||
|
else:
|
||||||
|
func = codecs.unicode_escape_decode
|
||||||
|
|
||||||
try:
|
try:
|
||||||
func(leaf._get_payload())
|
func(payload)
|
||||||
except UnicodeDecodeError as e:
|
except UnicodeDecodeError as e:
|
||||||
self._add_syntax_error('(unicode error) ' + str(e), leaf)
|
self._add_syntax_error('(unicode error) ' + str(e), leaf)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
|||||||
@@ -306,6 +306,11 @@ def _get_actual_exception(code):
|
|||||||
except (SyntaxError, IndentationError) as e:
|
except (SyntaxError, IndentationError) as e:
|
||||||
wanted = e.__class__.__name__ + ': ' + e.msg
|
wanted = e.__class__.__name__ + ': ' + e.msg
|
||||||
line_nr = e.lineno
|
line_nr = e.lineno
|
||||||
|
except ValueError as e:
|
||||||
|
# The ValueError comes from byte literals in Python 2 like '\x'
|
||||||
|
# that are oddly enough not SyntaxErrors.
|
||||||
|
wanted = 'SyntaxError: (value error) ' + str(e)
|
||||||
|
line_nr = None
|
||||||
else:
|
else:
|
||||||
assert False, "The piece of code should raise an exception."
|
assert False, "The piece of code should raise an exception."
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user