aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-08-09 22:53:38 -0400
committerJason R. Coombs <jaraco@jaraco.com>2013-08-09 22:53:38 -0400
commitb383fe311089ed6488916614acbf085521c12e48 (patch)
tree707db8849b101262e7ba6d3bac5e530d0f8178b4
parent4b432e0f50e9f5871a2f7375b406be7258bfa22c (diff)
downloadexternal_python_setuptools-b383fe311089ed6488916614acbf085521c12e48.tar.gz
external_python_setuptools-b383fe311089ed6488916614acbf085521c12e48.tar.bz2
external_python_setuptools-b383fe311089ed6488916614acbf085521c12e48.zip
Replaced overly-specific error messages with more general ones for improved cross-implementation compatibility. Fixes #50.
-rw-r--r--CHANGES.txt2
-rw-r--r--pkg_resources.py6
-rw-r--r--tests/api_tests.txt4
3 files changed, 10 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index d3c6f989..b9a53a0c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -11,6 +11,8 @@ CHANGES
`pkg_resources.invalid_marker`. Any clients depending on the specific
string representation of exceptions returned by that function may need to
be updated to account for this change.
+* Issue #50: SyntaxErrors generated by `pkg_resources.invalid_marker` are
+ normalized for cross-implementation consistency.
-----
0.9.8
diff --git a/pkg_resources.py b/pkg_resources.py
index 7c3bdccd..5514a099 100644
--- a/pkg_resources.py
+++ b/pkg_resources.py
@@ -1271,9 +1271,15 @@ def normalize_exception(exc):
"""
Given a SyntaxError from a marker evaluation, normalize the error message:
- Remove indications of filename and line number.
+ - Replace platform-specific error messages with standard error messages.
"""
+ subs = {
+ 'unexpected EOF while parsing': 'invalid syntax',
+ 'parenthesis is never closed': 'invalid syntax',
+ }
exc.filename = None
exc.lineno = None
+ exc.msg = subs.get(exc.msg, exc.msg)
return exc
diff --git a/tests/api_tests.txt b/tests/api_tests.txt
index 38b762d2..d34f2314 100644
--- a/tests/api_tests.txt
+++ b/tests/api_tests.txt
@@ -342,7 +342,7 @@ Environment Markers
Comparison or logical expression expected
>>> print(im("sys_platform=="))
- unexpected EOF while parsing
+ invalid syntax
>>> print(im("sys_platform=='win32'"))
False
@@ -354,7 +354,7 @@ Environment Markers
Comparison or logical expression expected
>>> print(im("(extra"))
- unexpected EOF while parsing
+ invalid syntax
>>> print(im("os.open('foo')=='y'"))
Language feature not supported in environment markers