Explorar o código

Provide necessary detail when failing to decode string literals

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42482 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements %!s(int64=15) %!d(string=hai) anos
pai
achega
04a8bbf46b
Modificáronse 1 ficheiros con 4 adicións e 1 borrados
  1. 4 1
      lib/python/ctypes/ctypesgencore/parser/pplexer.py

+ 4 - 1
lib/python/ctypes/ctypesgencore/parser/pplexer.py

@@ -57,7 +57,10 @@ class StringLiteral(str):
     def __new__(cls, value):
         assert value[0] == '"' and value[-1] == '"'
         # Unescaping probably not perfect but close enough.
-        value = value[1:-1].decode('string_escape')
+        try:
+            value = value[1:-1].decode('string_escape')
+        except ValueError, e:
+            raise ValueError("invalid \\x escape in %s" % value)
         return str.__new__(cls, value)
 
 # --------------------------------------------------------------------------