Skip to content

Commit 6ae34d7

Browse files
committed
Use json from the stdlib.
1 parent a540cf7 commit 6ae34d7

File tree

10 files changed

+33
-34
lines changed

10 files changed

+33
-34
lines changed

describe.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
__author__ = '[email protected] (Joe Gregorio)'
2525

2626
import argparse
27+
import json
2728
import os
2829
import re
2930
import string
@@ -32,7 +33,6 @@
3233
from googleapiclient.discovery import DISCOVERY_URI
3334
from googleapiclient.discovery import build
3435
from googleapiclient.discovery import build_from_document
35-
from oauth2client.anyjson import simplejson
3636
import httplib2
3737
import uritemplate
3838

@@ -346,7 +346,7 @@ def document_api(name, version):
346346
'api': name,
347347
'apiVersion': version})
348348
)
349-
discovery = simplejson.loads(content)
349+
discovery = json.loads(content)
350350

351351
version = safe_version(version)
352352

@@ -362,7 +362,7 @@ def document_api_from_discovery_document(uri):
362362
"""
363363
http = httplib2.Http()
364364
response, content = http.request(FLAGS.discovery_uri)
365-
discovery = simplejson.loads(content)
365+
discovery = json.loads(content)
366366

367367
service = build_from_document(discovery)
368368

@@ -383,7 +383,7 @@ def document_api_from_discovery_document(uri):
383383
FLAGS.directory_uri,
384384
headers={'X-User-IP': '0.0.0.0'})
385385
if resp.status == 200:
386-
directory = simplejson.loads(content)['items']
386+
directory = json.loads(content)['items']
387387
for api in directory:
388388
document_api(api['name'], api['version'])
389389
else:

googleapiclient/discovery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from email.generator import Generator
3333
from email.mime.multipart import MIMEMultipart
3434
from email.mime.nonmultipart import MIMENonMultipart
35+
import json
3536
import keyword
3637
import logging
3738
import mimetypes
@@ -64,7 +65,6 @@
6465
from googleapiclient.model import MediaModel
6566
from googleapiclient.model import RawModel
6667
from googleapiclient.schema import Schemas
67-
from oauth2client.anyjson import simplejson
6868
from oauth2client.client import GoogleCredentials
6969
from oauth2client.util import _add_query_parameter
7070
from oauth2client.util import positional
@@ -204,7 +204,7 @@ def build(serviceName,
204204
raise HttpError(resp, content, uri=requested_url)
205205

206206
try:
207-
service = simplejson.loads(content)
207+
service = json.loads(content)
208208
except ValueError, e:
209209
logger.error('Failed to parse as JSON: ' + content)
210210
raise InvalidJsonError()
@@ -254,7 +254,7 @@ def build_from_document(
254254
future = {}
255255

256256
if isinstance(service, basestring):
257-
service = simplejson.loads(service)
257+
service = json.loads(service)
258258
base = urlparse.urljoin(service['rootUrl'], service['servicePath'])
259259
schema = Schemas(service)
260260

googleapiclient/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
__author__ = '[email protected] (Joe Gregorio)'
2424

25+
import json
2526

2627
from oauth2client import util
27-
from oauth2client.anyjson import simplejson
2828

2929

3030
class Error(Exception):
@@ -45,7 +45,7 @@ def _get_reason(self):
4545
"""Calculate the reason for the error from the response content."""
4646
reason = self.resp.reason
4747
try:
48-
data = simplejson.loads(self.content)
48+
data = json.loads(self.content)
4949
reason = data['error']['message']
5050
except (ValueError, KeyError):
5151
pass

googleapiclient/http.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import copy
2727
import gzip
2828
import httplib2
29+
import json
2930
import logging
3031
import mimeparse
3132
import mimetypes
@@ -49,7 +50,6 @@
4950
from errors import UnexpectedMethodError
5051
from model import JsonModel
5152
from oauth2client import util
52-
from oauth2client.anyjson import simplejson
5353

5454

5555
DEFAULT_CHUNK_SIZE = 512*1024
@@ -221,7 +221,7 @@ def _to_json(self, strip=None):
221221
del d[member]
222222
d['_class'] = t.__name__
223223
d['_module'] = t.__module__
224-
return simplejson.dumps(d)
224+
return json.dumps(d)
225225

226226
def to_json(self):
227227
"""Create a JSON representation of an instance of MediaUpload.
@@ -244,7 +244,7 @@ def new_from_json(cls, s):
244244
An instance of the subclass of MediaUpload that was serialized with
245245
to_json().
246246
"""
247-
data = simplejson.loads(s)
247+
data = json.loads(s)
248248
# Find and call the right classmethod from_json() to restore the object.
249249
module = data['_module']
250250
m = __import__(module, fromlist=module.split('.')[:-1])
@@ -436,7 +436,7 @@ def to_json(self):
436436

437437
@staticmethod
438438
def from_json(s):
439-
d = simplejson.loads(s)
439+
d = json.loads(s)
440440
return MediaFileUpload(d['_filename'], mimetype=d['_mimetype'],
441441
chunksize=d['_chunksize'], resumable=d['_resumable'])
442442

@@ -913,12 +913,12 @@ def to_json(self):
913913
del d['_sleep']
914914
del d['_rand']
915915

916-
return simplejson.dumps(d)
916+
return json.dumps(d)
917917

918918
@staticmethod
919919
def from_json(s, http, postproc):
920920
"""Returns an HttpRequest populated with info from a JSON object."""
921-
d = simplejson.loads(s)
921+
d = json.loads(s)
922922
if d['resumable'] is not None:
923923
d['resumable'] = MediaUpload.new_from_json(d['resumable'])
924924
return HttpRequest(
@@ -1430,8 +1430,8 @@ def __call__(self, http, postproc, uri, method='GET', body=None,
14301430
# or expecting a body and not provided one.
14311431
raise UnexpectedBodyError(expected_body, body)
14321432
if isinstance(expected_body, str):
1433-
expected_body = simplejson.loads(expected_body)
1434-
body = simplejson.loads(body)
1433+
expected_body = json.loads(expected_body)
1434+
body = json.loads(body)
14351435
if body != expected_body:
14361436
raise UnexpectedBodyError(expected_body, body)
14371437
return HttpRequestMock(resp, content, postproc)
@@ -1522,7 +1522,7 @@ def request(self, uri,
15221522
if content == 'echo_request_headers':
15231523
content = headers
15241524
elif content == 'echo_request_headers_as_json':
1525-
content = simplejson.dumps(headers)
1525+
content = json.dumps(headers)
15261526
elif content == 'echo_request_body':
15271527
if hasattr(body, 'read'):
15281528
content = body.read()

googleapiclient/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
__author__ = '[email protected] (Joe Gregorio)'
2626

27+
import json
2728
import logging
2829
import urllib
2930

3031
from googleapiclient import __version__
3132
from errors import HttpError
32-
from oauth2client.anyjson import simplejson
3333

3434

3535
dump_request_response = False
@@ -125,7 +125,7 @@ def request(self, headers, path_params, query_params, body_value):
125125
path_params: dict, parameters that appear in the request path
126126
query_params: dict, parameters that appear in the query
127127
body_value: object, the request body as a Python object, which must be
128-
serializable by simplejson.
128+
serializable by json.
129129
Returns:
130130
A tuple of (headers, path_params, query, body)
131131
@@ -254,11 +254,11 @@ def serialize(self, body_value):
254254
if (isinstance(body_value, dict) and 'data' not in body_value and
255255
self._data_wrapper):
256256
body_value = {'data': body_value}
257-
return simplejson.dumps(body_value)
257+
return json.dumps(body_value)
258258

259259
def deserialize(self, content):
260260
content = content.decode('utf-8')
261-
body = simplejson.loads(content)
261+
body = json.loads(content)
262262
if self._data_wrapper and isinstance(body, dict) and 'data' in body:
263263
body = body['data']
264264
return body

googleapiclient/schema.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
import copy
6565

6666
from oauth2client import util
67-
from oauth2client.anyjson import simplejson
6867

6968

7069
class Schemas(object):

samples/api-python-client-doc/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import httplib2
2828
import inspect
29+
import json
2930
import logging
3031
import os
3132
import pydoc
@@ -40,7 +41,6 @@
4041
from google.appengine.ext import webapp
4142
from google.appengine.ext.webapp import template
4243
from google.appengine.ext.webapp import util
43-
from oauth2client.anyjson import simplejson
4444

4545

4646
DISCOVERY_URI = 'https://www.googleapis.com/discovery/v1/apis?preferred=true'
@@ -53,7 +53,7 @@ def get_directory_doc():
5353
if ip:
5454
uri += ('&userIp=' + ip)
5555
resp, content = http.request(uri)
56-
directory = simplejson.loads(content)['items']
56+
directory = json.loads(content)['items']
5757
for item in directory:
5858
item['title'] = item.get('title', item.get('description', ''))
5959
item['safe_version'] = describe.safe_version(item['version'])

tests/test_discovery.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import copy
2727
import datetime
2828
import httplib2
29+
import json
2930
import os
3031
import pickle
3132
import sys
@@ -65,7 +66,6 @@
6566
from googleapiclient.http import tunnel_patch
6667
from oauth2client import GOOGLE_TOKEN_URI
6768
from oauth2client import util
68-
from oauth2client.anyjson import simplejson
6969
from oauth2client.client import OAuth2Credentials
7070

7171
import uritemplate
@@ -108,7 +108,7 @@ class Utilities(unittest.TestCase):
108108

109109
def setUp(self):
110110
with open(datafile('zoo.json'), 'r') as fh:
111-
self.zoo_root_desc = simplejson.loads(fh.read())
111+
self.zoo_root_desc = json.loads(fh.read())
112112
self.zoo_get_method_desc = self.zoo_root_desc['methods']['query']
113113
self.zoo_animals_resource = self.zoo_root_desc['resources']['animals']
114114
self.zoo_insert_method_desc = self.zoo_animals_resource['methods']['insert']
@@ -337,7 +337,7 @@ def test_can_build_from_local_document(self):
337337

338338
def test_can_build_from_local_deserialized_document(self):
339339
discovery = open(datafile('plus.json')).read()
340-
discovery = simplejson.loads(discovery)
340+
discovery = json.loads(discovery)
341341
plus = build_from_document(discovery, base="https://www.googleapis.com/")
342342
self.assertTrue(plus is not None)
343343
self.assertTrue(hasattr(plus, 'activities'))
@@ -1045,7 +1045,7 @@ def test_resumable_media_handle_resume_of_upload_of_unknown_size(self):
10451045
'Content-Range': 'bytes */14',
10461046
'content-length': '0'
10471047
}
1048-
self.assertEqual(expected, simplejson.loads(e.content),
1048+
self.assertEqual(expected, json.loads(e.content),
10491049
'Should send an empty body when requesting the current upload status.')
10501050

10511051
def test_pickle(self):

tests/test_json_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
__author__ = '[email protected] (Joe Gregorio)'
2323

2424
import copy
25+
import json
2526
import os
2627
import unittest
2728
import httplib2
@@ -30,7 +31,6 @@
3031
from googleapiclient import __version__
3132
from googleapiclient.errors import HttpError
3233
from googleapiclient.model import JsonModel
33-
from oauth2client.anyjson import simplejson
3434

3535
# Python 2.5 requires different modules
3636
try:
@@ -225,7 +225,7 @@ def __init__(self, items):
225225
'field2': 'value2'
226226
}
227227
body_string = model.request({}, {}, {}, request_body)[-1]
228-
json_body = simplejson.loads(body_string)
228+
json_body = json.loads(body_string)
229229
self.assertEqual(request_body, json_body)
230230

231231
response = {'status': 200,
@@ -240,7 +240,7 @@ def __init__(self, items):
240240
googleapiclient.model.logging.info_record)
241241
self.assertTrue('response_field_2: response_value_2' in
242242
googleapiclient.model.logging.info_record)
243-
self.assertEqual(simplejson.loads(googleapiclient.model.logging.info_record[-2]),
243+
self.assertEqual(json.loads(googleapiclient.model.logging.info_record[-2]),
244244
request_body)
245245
self.assertEqual(googleapiclient.model.logging.info_record[-1],
246246
'--response-end--')

tests/test_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
__author__ = '[email protected] (Joe Gregorio)'
1818

19+
import json
1920
import os
2021
import unittest
2122
import StringIO
2223

2324
from googleapiclient.schema import Schemas
24-
from oauth2client.anyjson import simplejson
2525

2626

2727
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
@@ -51,7 +51,7 @@ def setUp(self):
5151
f = file(datafile('zoo.json'))
5252
discovery = f.read()
5353
f.close()
54-
discovery = simplejson.loads(discovery)
54+
discovery = json.loads(discovery)
5555
self.sc = Schemas(discovery)
5656

5757
def test_basic_formatting(self):

0 commit comments

Comments
 (0)