Fixes issue #85. Also moves all json imports to go through oauth2client.anyjson. Reviewed in http://codereview.appspot.com/5531064/.
diff --git a/oauth2client/anyjson.py b/oauth2client/anyjson.py
new file mode 100644
index 0000000..ae21c33
--- /dev/null
+++ b/oauth2client/anyjson.py
@@ -0,0 +1,32 @@
+# Copyright (C) 2010 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Utility module to import a JSON module
+
+Hides all the messy details of exactly where
+we get a simplejson module from.
+"""
+
+__author__ = 'jcgregorio@google.com (Joe Gregorio)'
+
+
+try: # pragma: no cover
+ # Should work for Python2.6 and higher.
+ import json as simplejson
+except ImportError: # pragma: no cover
+ try:
+ import simplejson
+ except ImportError:
+ # Try to import from django, should work on App Engine
+ from django.utils import simplejson
diff --git a/oauth2client/appengine.py b/oauth2client/appengine.py
index 723de8a..e4169e9 100644
--- a/oauth2client/appengine.py
+++ b/oauth2client/appengine.py
@@ -25,18 +25,9 @@
import pickle
import time
-try: # pragma: no cover
- import simplejson
-except ImportError: # pragma: no cover
- try:
- # Try to import from django, should work on App Engine
- from django.utils import simplejson
- except ImportError:
- # Should work for Python2.6 and higher.
- import json as simplejson
-
import clientsecrets
+from anyjson import simplejson
from client import AccessTokenRefreshError
from client import AssertionCredentials
from client import Credentials
diff --git a/oauth2client/client.py b/oauth2client/client.py
index 07df411..46d6cff 100644
--- a/oauth2client/client.py
+++ b/oauth2client/client.py
@@ -31,6 +31,7 @@
import urllib
import urlparse
+from anyjson import simplejson
HAS_OPENSSL = False
try:
@@ -41,16 +42,6 @@
except ImportError:
pass
-try: # pragma: no cover
- import simplejson
-except ImportError: # pragma: no cover
- try:
- # Try to import from django, should work on App Engine
- from django.utils import simplejson
- except ImportError:
- # Should work for Python2.6 and higher.
- import json as simplejson
-
try:
from urlparse import parse_qsl
except ImportError:
diff --git a/oauth2client/clientsecrets.py b/oauth2client/clientsecrets.py
index da48be7..1327a2a 100644
--- a/oauth2client/clientsecrets.py
+++ b/oauth2client/clientsecrets.py
@@ -21,15 +21,7 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
-try: # pragma: no cover
- import simplejson
-except ImportError: # pragma: no cover
- try:
- # Try to import from django, should work on App Engine
- from django.utils import simplejson
- except ImportError:
- # Should work for Python2.6 and higher.
- import json as simplejson
+from anyjson import simplejson
# Properties that make a client_secrets.json file valid.
TYPE_WEB = 'web'
diff --git a/oauth2client/crypt.py b/oauth2client/crypt.py
index 323345a..3df861d 100644
--- a/oauth2client/crypt.py
+++ b/oauth2client/crypt.py
@@ -21,16 +21,7 @@
import time
from OpenSSL import crypto
-
-try: # pragma: no cover
- import simplejson
-except ImportError: # pragma: no cover
- try:
- # Try to import from django, should work on App Engine
- from django.utils import simplejson
- except ImportError:
- # Should work for Python2.6 and higher.
- import json as simplejson
+from anyjson import simplejson
CLOCK_SKEW_SECS = 300 # 5 minutes in seconds
diff --git a/oauth2client/file.py b/oauth2client/file.py
index 34a5f48..d20cf6e 100644
--- a/oauth2client/file.py
+++ b/oauth2client/file.py
@@ -22,18 +22,7 @@
import threading
-
-try: # pragma: no cover
- import simplejson
-except ImportError: # pragma: no cover
- try:
- # Try to import from django, should work on App Engine
- from django.utils import simplejson
- except ImportError:
- # Should work for Python2.6 and higher.
- import json as simplejson
-
-
+from anyjson import simplejson
from client import Storage as BaseStorage
from client import Credentials
diff --git a/oauth2client/multistore_file.py b/oauth2client/multistore_file.py
index cf43dd9..b6126f5 100644
--- a/oauth2client/multistore_file.py
+++ b/oauth2client/multistore_file.py
@@ -37,16 +37,7 @@
import os
import threading
-try: # pragma: no cover
- import simplejson
-except ImportError: # pragma: no cover
- try:
- # Try to import from django, should work on App Engine
- from django.utils import simplejson
- except ImportError:
- # Should work for Python2.6 and higher.
- import json as simplejson
-
+from anyjson import simplejson
from client import Storage as BaseStorage
from client import Credentials