Use json from the stdlib.
diff --git a/describe.py b/describe.py
index be99352..1a7a24b 100755
--- a/describe.py
+++ b/describe.py
@@ -24,6 +24,7 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
import argparse
+import json
import os
import re
import string
@@ -32,7 +33,6 @@
from googleapiclient.discovery import DISCOVERY_URI
from googleapiclient.discovery import build
from googleapiclient.discovery import build_from_document
-from oauth2client.anyjson import simplejson
import httplib2
import uritemplate
@@ -346,7 +346,7 @@
'api': name,
'apiVersion': version})
)
- discovery = simplejson.loads(content)
+ discovery = json.loads(content)
version = safe_version(version)
@@ -362,7 +362,7 @@
"""
http = httplib2.Http()
response, content = http.request(FLAGS.discovery_uri)
- discovery = simplejson.loads(content)
+ discovery = json.loads(content)
service = build_from_document(discovery)
@@ -383,7 +383,7 @@
FLAGS.directory_uri,
headers={'X-User-IP': '0.0.0.0'})
if resp.status == 200:
- directory = simplejson.loads(content)['items']
+ directory = json.loads(content)['items']
for api in directory:
document_api(api['name'], api['version'])
else:
diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py
index 93600cd..638929c 100644
--- a/googleapiclient/discovery.py
+++ b/googleapiclient/discovery.py
@@ -32,6 +32,7 @@
from email.generator import Generator
from email.mime.multipart import MIMEMultipart
from email.mime.nonmultipart import MIMENonMultipart
+import json
import keyword
import logging
import mimetypes
@@ -64,7 +65,6 @@
from googleapiclient.model import MediaModel
from googleapiclient.model import RawModel
from googleapiclient.schema import Schemas
-from oauth2client.anyjson import simplejson
from oauth2client.client import GoogleCredentials
from oauth2client.util import _add_query_parameter
from oauth2client.util import positional
@@ -204,7 +204,7 @@
raise HttpError(resp, content, uri=requested_url)
try:
- service = simplejson.loads(content)
+ service = json.loads(content)
except ValueError, e:
logger.error('Failed to parse as JSON: ' + content)
raise InvalidJsonError()
@@ -254,7 +254,7 @@
future = {}
if isinstance(service, basestring):
- service = simplejson.loads(service)
+ service = json.loads(service)
base = urlparse.urljoin(service['rootUrl'], service['servicePath'])
schema = Schemas(service)
diff --git a/googleapiclient/errors.py b/googleapiclient/errors.py
index b03c6e3..cad5688 100644
--- a/googleapiclient/errors.py
+++ b/googleapiclient/errors.py
@@ -22,9 +22,9 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
+import json
from oauth2client import util
-from oauth2client.anyjson import simplejson
class Error(Exception):
@@ -45,7 +45,7 @@
"""Calculate the reason for the error from the response content."""
reason = self.resp.reason
try:
- data = simplejson.loads(self.content)
+ data = json.loads(self.content)
reason = data['error']['message']
except (ValueError, KeyError):
pass
diff --git a/googleapiclient/http.py b/googleapiclient/http.py
index 371eafe..bb4ad6d 100644
--- a/googleapiclient/http.py
+++ b/googleapiclient/http.py
@@ -26,6 +26,7 @@
import copy
import gzip
import httplib2
+import json
import logging
import mimeparse
import mimetypes
@@ -49,7 +50,6 @@
from errors import UnexpectedMethodError
from model import JsonModel
from oauth2client import util
-from oauth2client.anyjson import simplejson
DEFAULT_CHUNK_SIZE = 512*1024
@@ -221,7 +221,7 @@
del d[member]
d['_class'] = t.__name__
d['_module'] = t.__module__
- return simplejson.dumps(d)
+ return json.dumps(d)
def to_json(self):
"""Create a JSON representation of an instance of MediaUpload.
@@ -244,7 +244,7 @@
An instance of the subclass of MediaUpload that was serialized with
to_json().
"""
- data = simplejson.loads(s)
+ data = json.loads(s)
# Find and call the right classmethod from_json() to restore the object.
module = data['_module']
m = __import__(module, fromlist=module.split('.')[:-1])
@@ -436,7 +436,7 @@
@staticmethod
def from_json(s):
- d = simplejson.loads(s)
+ d = json.loads(s)
return MediaFileUpload(d['_filename'], mimetype=d['_mimetype'],
chunksize=d['_chunksize'], resumable=d['_resumable'])
@@ -913,12 +913,12 @@
del d['_sleep']
del d['_rand']
- return simplejson.dumps(d)
+ return json.dumps(d)
@staticmethod
def from_json(s, http, postproc):
"""Returns an HttpRequest populated with info from a JSON object."""
- d = simplejson.loads(s)
+ d = json.loads(s)
if d['resumable'] is not None:
d['resumable'] = MediaUpload.new_from_json(d['resumable'])
return HttpRequest(
@@ -1430,8 +1430,8 @@
# or expecting a body and not provided one.
raise UnexpectedBodyError(expected_body, body)
if isinstance(expected_body, str):
- expected_body = simplejson.loads(expected_body)
- body = simplejson.loads(body)
+ expected_body = json.loads(expected_body)
+ body = json.loads(body)
if body != expected_body:
raise UnexpectedBodyError(expected_body, body)
return HttpRequestMock(resp, content, postproc)
@@ -1522,7 +1522,7 @@
if content == 'echo_request_headers':
content = headers
elif content == 'echo_request_headers_as_json':
- content = simplejson.dumps(headers)
+ content = json.dumps(headers)
elif content == 'echo_request_body':
if hasattr(body, 'read'):
content = body.read()
diff --git a/googleapiclient/model.py b/googleapiclient/model.py
index e06c0d0..62d48cf 100644
--- a/googleapiclient/model.py
+++ b/googleapiclient/model.py
@@ -24,12 +24,12 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
+import json
import logging
import urllib
from googleapiclient import __version__
from errors import HttpError
-from oauth2client.anyjson import simplejson
dump_request_response = False
@@ -125,7 +125,7 @@
path_params: dict, parameters that appear in the request path
query_params: dict, parameters that appear in the query
body_value: object, the request body as a Python object, which must be
- serializable by simplejson.
+ serializable by json.
Returns:
A tuple of (headers, path_params, query, body)
@@ -254,11 +254,11 @@
if (isinstance(body_value, dict) and 'data' not in body_value and
self._data_wrapper):
body_value = {'data': body_value}
- return simplejson.dumps(body_value)
+ return json.dumps(body_value)
def deserialize(self, content):
content = content.decode('utf-8')
- body = simplejson.loads(content)
+ body = json.loads(content)
if self._data_wrapper and isinstance(body, dict) and 'data' in body:
body = body['data']
return body
diff --git a/googleapiclient/schema.py b/googleapiclient/schema.py
index c235f54..603f9f7 100644
--- a/googleapiclient/schema.py
+++ b/googleapiclient/schema.py
@@ -64,7 +64,6 @@
import copy
from oauth2client import util
-from oauth2client.anyjson import simplejson
class Schemas(object):
diff --git a/samples/api-python-client-doc/main.py b/samples/api-python-client-doc/main.py
index d95c612..d0a9eef 100755
--- a/samples/api-python-client-doc/main.py
+++ b/samples/api-python-client-doc/main.py
@@ -26,6 +26,7 @@
import httplib2
import inspect
+import json
import logging
import os
import pydoc
@@ -40,7 +41,6 @@
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp import util
-from oauth2client.anyjson import simplejson
DISCOVERY_URI = 'https://www.googleapis.com/discovery/v1/apis?preferred=true'
@@ -53,7 +53,7 @@
if ip:
uri += ('&userIp=' + ip)
resp, content = http.request(uri)
- directory = simplejson.loads(content)['items']
+ directory = json.loads(content)['items']
for item in directory:
item['title'] = item.get('title', item.get('description', ''))
item['safe_version'] = describe.safe_version(item['version'])
diff --git a/tests/test_discovery.py b/tests/test_discovery.py
index bc7836f..5acb0cd 100644
--- a/tests/test_discovery.py
+++ b/tests/test_discovery.py
@@ -26,6 +26,7 @@
import copy
import datetime
import httplib2
+import json
import os
import pickle
import sys
@@ -65,7 +66,6 @@
from googleapiclient.http import tunnel_patch
from oauth2client import GOOGLE_TOKEN_URI
from oauth2client import util
-from oauth2client.anyjson import simplejson
from oauth2client.client import OAuth2Credentials
import uritemplate
@@ -108,7 +108,7 @@
def setUp(self):
with open(datafile('zoo.json'), 'r') as fh:
- self.zoo_root_desc = simplejson.loads(fh.read())
+ self.zoo_root_desc = json.loads(fh.read())
self.zoo_get_method_desc = self.zoo_root_desc['methods']['query']
self.zoo_animals_resource = self.zoo_root_desc['resources']['animals']
self.zoo_insert_method_desc = self.zoo_animals_resource['methods']['insert']
@@ -337,7 +337,7 @@
def test_can_build_from_local_deserialized_document(self):
discovery = open(datafile('plus.json')).read()
- discovery = simplejson.loads(discovery)
+ discovery = json.loads(discovery)
plus = build_from_document(discovery, base="https://www.googleapis.com/")
self.assertTrue(plus is not None)
self.assertTrue(hasattr(plus, 'activities'))
@@ -1045,7 +1045,7 @@
'Content-Range': 'bytes */14',
'content-length': '0'
}
- self.assertEqual(expected, simplejson.loads(e.content),
+ self.assertEqual(expected, json.loads(e.content),
'Should send an empty body when requesting the current upload status.')
def test_pickle(self):
diff --git a/tests/test_json_model.py b/tests/test_json_model.py
index 468db28..654aac9 100644
--- a/tests/test_json_model.py
+++ b/tests/test_json_model.py
@@ -22,6 +22,7 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
import copy
+import json
import os
import unittest
import httplib2
@@ -30,7 +31,6 @@
from googleapiclient import __version__
from googleapiclient.errors import HttpError
from googleapiclient.model import JsonModel
-from oauth2client.anyjson import simplejson
# Python 2.5 requires different modules
try:
@@ -225,7 +225,7 @@
'field2': 'value2'
}
body_string = model.request({}, {}, {}, request_body)[-1]
- json_body = simplejson.loads(body_string)
+ json_body = json.loads(body_string)
self.assertEqual(request_body, json_body)
response = {'status': 200,
@@ -240,7 +240,7 @@
googleapiclient.model.logging.info_record)
self.assertTrue('response_field_2: response_value_2' in
googleapiclient.model.logging.info_record)
- self.assertEqual(simplejson.loads(googleapiclient.model.logging.info_record[-2]),
+ self.assertEqual(json.loads(googleapiclient.model.logging.info_record[-2]),
request_body)
self.assertEqual(googleapiclient.model.logging.info_record[-1],
'--response-end--')
diff --git a/tests/test_schema.py b/tests/test_schema.py
index 48f123d..ec6dd42 100644
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -16,12 +16,12 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
+import json
import os
import unittest
import StringIO
from googleapiclient.schema import Schemas
-from oauth2client.anyjson import simplejson
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
@@ -51,7 +51,7 @@
f = file(datafile('zoo.json'))
discovery = f.read()
f.close()
- discovery = simplejson.loads(discovery)
+ discovery = json.loads(discovery)
self.sc = Schemas(discovery)
def test_basic_formatting(self):