Fixes issue #85. Also moves all json imports to go through oauth2client.anyjson. Reviewed in http://codereview.appspot.com/5531064/.
diff --git a/Makefile b/Makefile
index 8d5b402..4f568a4 100644
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,7 @@
python runtests.py tests/test_oauth2client.py
python runtests.py tests/test_oauth.py
python runtests.py tests/test_protobuf_model.py
+ python runtests.py tests/test_schema.py
python runtests.py tests/test_oauth2client_appengine.py
.PHONY: docs
diff --git a/apiclient/discovery.py b/apiclient/discovery.py
index 9344392..a2c81c6 100644
--- a/apiclient/discovery.py
+++ b/apiclient/discovery.py
@@ -39,7 +39,6 @@
except ImportError:
from cgi import parse_qsl
-from apiclient.anyjson import simplejson
from apiclient.errors import HttpError
from apiclient.errors import InvalidJsonError
from apiclient.errors import MediaUploadSizeError
@@ -54,6 +53,7 @@
from apiclient.schema import Schemas
from email.mime.multipart import MIMEMultipart
from email.mime.nonmultipart import MIMENonMultipart
+from oauth2client.anyjson import simplejson
URITEMPLATE = re.compile('{[^}]*}')
diff --git a/apiclient/errors.py b/apiclient/errors.py
index fca3960..b6ee9a5 100644
--- a/apiclient/errors.py
+++ b/apiclient/errors.py
@@ -23,7 +23,7 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
-from anyjson import simplejson
+from oauth2client.anyjson import simplejson
class Error(Exception):
diff --git a/apiclient/http.py b/apiclient/http.py
index 6bf1de4..4563bd1 100644
--- a/apiclient/http.py
+++ b/apiclient/http.py
@@ -36,7 +36,6 @@
import urlparse
import uuid
-from anyjson import simplejson
from email.mime.multipart import MIMEMultipart
from email.mime.nonmultipart import MIMENonMultipart
from email.parser import FeedParser
@@ -46,6 +45,7 @@
from errors import UnexpectedBodyError
from errors import UnexpectedMethodError
from model import JsonModel
+from oauth2client.anyjson import simplejson
class MediaUploadProgress(object):
diff --git a/apiclient/model.py b/apiclient/model.py
index 7f40efa..aafd88b 100644
--- a/apiclient/model.py
+++ b/apiclient/model.py
@@ -28,8 +28,8 @@
import logging
import urllib
-from anyjson import simplejson
from errors import HttpError
+from oauth2client.anyjson import simplejson
FLAGS = gflags.FLAGS
diff --git a/apiclient/oauth.py b/apiclient/oauth.py
index 11eb680..bd4125b 100644
--- a/apiclient/oauth.py
+++ b/apiclient/oauth.py
@@ -26,7 +26,8 @@
import oauth2 as oauth
import urllib
import urlparse
-from anyjson import simplejson
+
+from oauth2client.anyjson import simplejson
try:
from urlparse import parse_qsl
diff --git a/apiclient/schema.py b/apiclient/schema.py
index cd5a7cb..ddcd670 100644
--- a/apiclient/schema.py
+++ b/apiclient/schema.py
@@ -62,7 +62,7 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
import copy
-from apiclient.anyjson import simplejson
+from oauth2client.anyjson import simplejson
class Schemas(object):
@@ -262,13 +262,13 @@
self.emitEnd('%s,' % str(value), schema.get('description', ''))
elif stype == 'string':
value = schema.get('default', 'A String')
- self.emitEnd('"%s",' % value, schema.get('description', ''))
+ self.emitEnd('"%s",' % str(value), schema.get('description', ''))
elif stype == 'integer':
- value = schema.get('default', 42)
- self.emitEnd('%d,' % value, schema.get('description', ''))
+ value = schema.get('default', '42')
+ self.emitEnd('%s,' % str(value), schema.get('description', ''))
elif stype == 'number':
- value = schema.get('default', 3.14)
- self.emitEnd('%f,' % value, schema.get('description', ''))
+ value = schema.get('default', '3.14')
+ self.emitEnd('%s,' % str(value), schema.get('description', ''))
elif stype == 'null':
self.emitEnd('None,', schema.get('description', ''))
elif stype == 'any':
diff --git a/apiclient/anyjson.py b/oauth2client/anyjson.py
similarity index 90%
rename from apiclient/anyjson.py
rename to oauth2client/anyjson.py
index 7fb7846..ae21c33 100644
--- a/apiclient/anyjson.py
+++ b/oauth2client/anyjson.py
@@ -22,11 +22,11 @@
try: # pragma: no cover
- import simplejson
+ # 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
- except ImportError:
- # Should work for Python2.6 and higher.
- import json as 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
diff --git a/tests/test_json_model.py b/tests/test_json_model.py
index 7ab2f98..43b0421 100644
--- a/tests/test_json_model.py
+++ b/tests/test_json_model.py
@@ -28,9 +28,9 @@
import httplib2
import apiclient.model
-from apiclient.anyjson import simplejson
from apiclient.errors import HttpError
from apiclient.model import JsonModel
+from oauth2client.anyjson import simplejson
FLAGS = gflags.FLAGS
diff --git a/tests/test_oauth2client.py b/tests/test_oauth2client.py
index 8286eed..dfcbf72 100644
--- a/tests/test_oauth2client.py
+++ b/tests/test_oauth2client.py
@@ -33,17 +33,8 @@
except ImportError:
from cgi import parse_qs
-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 apiclient.http import HttpMockSequence
+from oauth2client.anyjson import simplejson
from oauth2client.client import AccessTokenCredentials
from oauth2client.client import AccessTokenCredentialsError
from oauth2client.client import AccessTokenRefreshError
diff --git a/tests/test_oauth2client_appengine.py b/tests/test_oauth2client_appengine.py
index 4ab4f03..f2f470f 100644
--- a/tests/test_oauth2client_appengine.py
+++ b/tests/test_oauth2client_appengine.py
@@ -35,18 +35,18 @@
import dev_appserver
dev_appserver.fix_sys_path()
-from apiclient.anyjson import simplejson
from apiclient.http import HttpMockSequence
from google.appengine.api import apiproxy_stub
from google.appengine.api import apiproxy_stub_map
from google.appengine.api import users
from google.appengine.ext import testbed
from google.appengine.ext import webapp
-from oauth2client.client import AccessTokenRefreshError
-from oauth2client.client import FlowExchangeError
+from oauth2client.anyjson import simplejson
from oauth2client.appengine import AppAssertionCredentials
from oauth2client.appengine import OAuth2Decorator
from oauth2client.appengine import OAuth2Handler
+from oauth2client.client import AccessTokenRefreshError
+from oauth2client.client import FlowExchangeError
from webtest import TestApp
diff --git a/tests/test_oauth2client_file.py b/tests/test_oauth2client_file.py
index 2d6f3b5..a34cce7 100644
--- a/tests/test_oauth2client_file.py
+++ b/tests/test_oauth2client_file.py
@@ -30,24 +30,13 @@
import tempfile
import unittest
-
-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 apiclient.http import HttpMockSequence
-
-from oauth2client.client import OAuth2Credentials
+from oauth2client import multistore_file
+from oauth2client.anyjson import simplejson
from oauth2client.client import AccessTokenCredentials
from oauth2client.client import AssertionCredentials
+from oauth2client.client import OAuth2Credentials
from oauth2client.file import Storage
-from oauth2client import multistore_file
FILENAME = tempfile.mktemp('oauth2client_test.data')
diff --git a/tests/test_oauth2client_jwt.py b/tests/test_oauth2client_jwt.py
index 01a7331..50dab5a 100644
--- a/tests/test_oauth2client_jwt.py
+++ b/tests/test_oauth2client_jwt.py
@@ -34,21 +34,12 @@
except ImportError:
from cgi import parse_qs
-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 apiclient.http import HttpMockSequence
from oauth2client import crypt
+from oauth2client.anyjson import simplejson
from oauth2client.client import SignedJwtAssertionCredentials
-from oauth2client.client import verify_id_token
from oauth2client.client import VerifyJwtTokenError
+from oauth2client.client import verify_id_token
def datafile(filename):
diff --git a/tests/test_schema.py b/tests/test_schema.py
index 7430ac7..2cdb200 100644
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -20,8 +20,8 @@
import unittest
import StringIO
-from apiclient.anyjson import simplejson
from apiclient.schema import Schemas
+from oauth2client.anyjson import simplejson
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
@@ -39,7 +39,7 @@
"anyVal": "", # Anything will do.
"nullVal": None,
"stringVal": "A String",
- "doubleVal": 3.140000,
+ "doubleVal": 3.14,
"booleanVal": True or False, # True or False.
},
],