瀏覽代碼

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 15 年之前
父節點
當前提交
04a8bbf46b
共有 1 個文件被更改,包括 4 次插入1 次删除
  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)
 
 # --------------------------------------------------------------------------