From e6efd5359b207196929a7b3c89f7905601de813c Mon Sep 17 00:00:00 2001 From: Joe Gregorio Date: Mon, 20 Sep 2010 11:13:50 -0400 Subject: [PATCH] Be flexible where simplejson comes from --- apiclient/discovery.py | 11 ++++++++++- discovery_extras.py | 13 +++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apiclient/discovery.py b/apiclient/discovery.py index d15c5b2..5a0ba33 100644 --- a/apiclient/discovery.py +++ b/apiclient/discovery.py @@ -25,11 +25,20 @@ import httplib2 import logging import os import re -import simplejson import uritemplate import urllib import urlparse +try: + import simplejson +except ImportError: + 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 + class HttpError(Exception): pass diff --git a/discovery_extras.py b/discovery_extras.py index f8c1d30..c0b84ba 100644 --- a/discovery_extras.py +++ b/discovery_extras.py @@ -23,9 +23,19 @@ __author__ = 'jcgregorio@google.com (Joe Gregorio)' import os import os.path -import simplejson import sys +try: + import simplejson +except ImportError: + 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 + + def main(): for filename in sys.argv[1:]: f = file(filename, "r") @@ -49,4 +59,3 @@ def main(): if __name__ == '__main__': main() -