summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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