compat: handle SyntaxError when importing simplejson
authorMartin Geisler <martin@geisler.net>
Sun, 25 May 2014 22:44:09 +0000 (00:44 +0200)
committerMartin Geisler <martin@geisler.net>
Sun, 25 May 2014 22:56:35 +0000 (00:56 +0200)
We officially support Python 2.6 to 3.3, but simplejson does not
support Python 3.1 or 3.2:

  https://github.com/simplejson/simplejson/issues/66

Importing simplejson on Python 3.2 results in a SyntaxError because
simplejson uses the u'...' syntax (the syntax was not supported in
Python 3.0 to 3.2).

Support for loading simplejson instead of the stdlib json module was
added by #710:

  https://github.com/kennethreitz/requests/pull/710

No mention was made of the lack of support for Python 3.2, but it was
mentioned that simplejson can be faster than the stdlib json module.

requests/compat.py

index bdf10d6a9f9c0c073f85ca3cbdbc6c12eca610cd..84d703b68e1be4d3c06c3f999bbd11ff8386531a 100644 (file)
@@ -75,7 +75,9 @@ is_solaris = ('solar==' in str(sys.platform).lower())   # Complete guess.
 
 try:
     import simplejson as json
-except ImportError:
+except (ImportError, SyntaxError):
+    # simplejson does not support Python 3.2, it thows a SyntaxError
+    # because of u'...' Unicode literals.
     import json
 
 # ---------