Use swift.common.utils.json

We should use swift.common.utils.json to keep code consistency.

Change-Id: Ie3420a29cfb954c4d16526023b6bff7c8a39afdc
This commit is contained in:
Kota Tsuyuzaki
2015-01-29 00:30:36 -08:00
parent ff12a24b2a
commit 07937ab09e
9 changed files with 29 additions and 28 deletions

View File

@@ -13,9 +13,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from simplejson import loads
from swift.common.http import HTTP_OK from swift.common.http import HTTP_OK
from swift.common.utils import json
from swift3.controllers.base import Controller from swift3.controllers.base import Controller
from swift3.controllers.acl import handle_acl_header from swift3.controllers.acl import handle_acl_header
@@ -68,7 +67,7 @@ class BucketController(Controller):
resp = req.get_response(self.app, query=query) resp = req.get_response(self.app, query=query)
objects = loads(resp.body) objects = json.loads(resp.body)
elem = Element('ListBucketResult') elem = Element('ListBucketResult')
SubElement(elem, 'Name').text = req.container_name SubElement(elem, 'Name').text = req.container_name

View File

@@ -42,10 +42,9 @@ upload information:
Static Large Object. Static Large Object.
""" """
from simplejson import loads, dumps
import os import os
from swift.common.utils import split_path from swift.common.utils import split_path, json
from swift3.controllers.base import Controller, bucket_operation, \ from swift3.controllers.base import Controller, bucket_operation, \
object_operation object_operation
@@ -171,7 +170,7 @@ class UploadsController(Controller):
container = req.container_name + MULTIUPLOAD_SUFFIX container = req.container_name + MULTIUPLOAD_SUFFIX
resp = req.get_response(self.app, container=container, query=query) resp = req.get_response(self.app, container=container, query=query)
objects = loads(resp.body) objects = json.loads(resp.body)
objects = filter(filter_max_uploads, objects) objects = filter(filter_max_uploads, objects)
@@ -308,7 +307,7 @@ class UploadController(Controller):
container = req.container_name + MULTIUPLOAD_SUFFIX container = req.container_name + MULTIUPLOAD_SUFFIX
resp = req.get_response(self.app, container=container, obj='', resp = req.get_response(self.app, container=container, obj='',
query=query) query=query)
objects = loads(resp.body) objects = json.loads(resp.body)
last_part = 0 last_part = 0
@@ -394,7 +393,7 @@ class UploadController(Controller):
resp = req.get_response(self.app, 'GET', container, '', query=query) resp = req.get_response(self.app, 'GET', container, '', query=query)
# Iterate over the segment objects and delete them individually # Iterate over the segment objects and delete them individually
objects = loads(resp.body) objects = json.loads(resp.body)
for o in objects: for o in objects:
container = req.container_name + MULTIUPLOAD_SUFFIX container = req.container_name + MULTIUPLOAD_SUFFIX
req.get_response(self.app, container=container, obj=o['name']) req.get_response(self.app, container=container, obj=o['name'])
@@ -423,7 +422,7 @@ class UploadController(Controller):
container = req.container_name + MULTIUPLOAD_SUFFIX container = req.container_name + MULTIUPLOAD_SUFFIX
resp = req.get_response(self.app, 'GET', container, '', query=query) resp = req.get_response(self.app, 'GET', container, '', query=query)
objinfo = loads(resp.body) objinfo = json.loads(resp.body)
objtable = dict((o['name'], objtable = dict((o['name'],
{'path': '/'.join(['', container, o['name']]), {'path': '/'.join(['', container, o['name']]),
'etag': o['hash'], 'etag': o['hash'],
@@ -463,7 +462,7 @@ class UploadController(Controller):
try: try:
# TODO: add support for versioning # TODO: add support for versioning
resp = req.get_response(self.app, 'PUT', body=dumps(manifest), resp = req.get_response(self.app, 'PUT', body=json.dumps(manifest),
query={'multipart-manifest': 'put'}, query={'multipart-manifest': 'put'},
headers=headers) headers=headers)
except BadSwiftRequest as e: except BadSwiftRequest as e:

View File

@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from simplejson import loads from swift.common.utils import json
from swift3.controllers.base import Controller from swift3.controllers.base import Controller
from swift3.etree import Element, SubElement, tostring from swift3.etree import Element, SubElement, tostring
@@ -32,7 +32,7 @@ class ServiceController(Controller):
""" """
resp = req.get_response(self.app, query={'format': 'json'}) resp = req.get_response(self.app, query={'format': 'json'})
containers = loads(resp.body) containers = json.loads(resp.body)
containers = filter( containers = filter(
lambda item: validate_bucket_name(item['name']), containers) lambda item: validate_bucket_name(item['name']), containers)

View File

@@ -14,7 +14,8 @@
# limitations under the License. # limitations under the License.
from functools import partial from functools import partial
from simplejson import loads, dumps
from swift.common.utils import json
from swift3.response import InvalidArgument, MalformedACLError, \ from swift3.response import InvalidArgument, MalformedACLError, \
S3NotImplemented, InvalidRequest, AccessDenied S3NotImplemented, InvalidRequest, AccessDenied
@@ -69,7 +70,7 @@ def encode_acl(resource, acl):
header_value.update({"Grant": grants}) header_value.update({"Grant": grants})
headers = {} headers = {}
key = sysmeta_header(resource, 'acl') key = sysmeta_header(resource, 'acl')
headers[key] = dumps(header_value, separators=(',', ':')) headers[key] = json.dumps(header_value, separators=(',', ':'))
return headers return headers
@@ -95,7 +96,7 @@ def decode_acl(resource, headers):
return ACL(Owner(None, None), []) return ACL(Owner(None, None), [])
try: try:
encode_value = loads(value) encode_value = json.loads(value)
if not isinstance(encode_value, dict): if not isinstance(encode_value, dict):
return ACL(Owner(None, None), []) return ACL(Owner(None, None), [])

View File

@@ -15,10 +15,10 @@
import unittest import unittest
import cgi import cgi
import json
from swift.common import swob from swift.common import swob
from swift.common.swob import Request from swift.common.swob import Request
from swift.common.utils import json
from swift3.test.unit import Swift3TestCase from swift3.test.unit import Swift3TestCase
from swift3.etree import Element, SubElement, fromstring, tostring from swift3.etree import Element, SubElement, fromstring, tostring

View File

@@ -14,12 +14,12 @@
# limitations under the License. # limitations under the License.
import unittest import unittest
import simplejson as json
from mock import patch from mock import patch
from urllib import quote from urllib import quote
from swift.common import swob from swift.common import swob
from swift.common.swob import Request from swift.common.swob import Request
from swift.common.utils import json
from swift3.test.unit import Swift3TestCase from swift3.test.unit import Swift3TestCase
from swift3.etree import fromstring, tostring from swift3.etree import fromstring, tostring

View File

@@ -14,7 +14,6 @@
# limitations under the License. # limitations under the License.
import unittest import unittest
import simplejson as json
import functools import functools
import sys import sys
import traceback import traceback
@@ -22,6 +21,7 @@ from mock import patch, MagicMock
from swift.common import swob from swift.common import swob
from swift.common.swob import Request from swift.common.swob import Request
from swift.common.utils import json
from swift3.etree import tostring, Element, SubElement from swift3.etree import tostring, Element, SubElement
from swift3.subresource import ACL, ACLPrivate, User, encode_acl, \ from swift3.subresource import ACL, ACLPrivate, User, encode_acl, \

View File

@@ -14,11 +14,11 @@
# limitations under the License. # limitations under the License.
import unittest import unittest
import simplejson
from mock import patch from mock import patch
from swift.common import swob from swift.common import swob
from swift.common.swob import Request from swift.common.swob import Request
from swift.common.utils import json
from swift3.test.unit.test_s3_acl import s3acl from swift3.test.unit.test_s3_acl import s3acl
from swift3.test.unit import Swift3TestCase from swift3.test.unit import Swift3TestCase
@@ -34,7 +34,7 @@ class TestSwift3Service(Swift3TestCase):
json_pattern = '{' + ','.join(json_pattern) + '}' json_pattern = '{' + ','.join(json_pattern) + '}'
json_out = [] json_out = []
for b in self.buckets: for b in self.buckets:
name = simplejson.dumps(b[0]) name = json.dumps(b[0])
json_out.append(json_pattern % json_out.append(json_pattern %
(name, b[1], b[2])) (name, b[1], b[2]))
bucket_list = '[' + ','.join(json_out) + ']' bucket_list = '[' + ','.join(json_out) + ']'
@@ -109,7 +109,7 @@ class TestSwift3Service(Swift3TestCase):
json_pattern = '{' + ','.join(json_pattern) + '}' json_pattern = '{' + ','.join(json_pattern) + '}'
json_out = [] json_out = []
for b in buckets: for b in buckets:
name = simplejson.dumps(b[0]) name = json.dumps(b[0])
json_out.append(json_pattern % json_out.append(json_pattern %
(name, b[1], b[2])) (name, b[1], b[2]))
bucket_list = '[' + ','.join(json_out) + ']' bucket_list = '[' + ','.join(json_out) + ']'
@@ -145,7 +145,7 @@ class TestSwift3Service(Swift3TestCase):
json_out = [] json_out = []
for b in buckets: for b in buckets:
name = simplejson.dumps(b[0]) name = json.dumps(b[0])
json_out.append(json_pattern % json_out.append(json_pattern %
(name, b[1], b[2])) (name, b[1], b[2]))

View File

@@ -14,7 +14,9 @@
# limitations under the License. # limitations under the License.
import unittest import unittest
from simplejson import dumps, loads
from swift.common.utils import json
from swift3.response import AccessDenied from swift3.response import AccessDenied
from swift3.subresource import User, AuthenticatedUsers, AllUsers, \ from swift3.subresource import User, AuthenticatedUsers, AllUsers, \
ACLPrivate, ACLPublicRead, ACLPublicReadWrite, ACLAuthenticatedRead, \ ACLPrivate, ACLPublicRead, ACLPublicReadWrite, ACLAuthenticatedRead, \
@@ -204,7 +206,7 @@ class TestSwift3Subresource(unittest.TestCase):
'Grant': [{'Permission': 'FULL_CONTROL', 'Grant': [{'Permission': 'FULL_CONTROL',
'Grantee': 'test:tester'}]} 'Grantee': 'test:tester'}]}
headers = {sysmeta_header('container', 'acl'): headers = {sysmeta_header('container', 'acl'):
dumps(access_control_policy)} json.dumps(access_control_policy)}
acl = decode_acl('container', headers) acl = decode_acl('container', headers)
self.assertEqual(type(acl), ACL) self.assertEqual(type(acl), ACL)
@@ -219,7 +221,7 @@ class TestSwift3Subresource(unittest.TestCase):
'Grant': [{'Permission': 'FULL_CONTROL', 'Grant': [{'Permission': 'FULL_CONTROL',
'Grantee': 'test:tester'}]} 'Grantee': 'test:tester'}]}
headers = {sysmeta_header('object', 'acl'): headers = {sysmeta_header('object', 'acl'):
dumps(access_control_policy)} json.dumps(access_control_policy)}
acl = decode_acl('object', headers) acl = decode_acl('object', headers)
self.assertEqual(type(acl), ACL) self.assertEqual(type(acl), ACL)
@@ -240,7 +242,7 @@ class TestSwift3Subresource(unittest.TestCase):
acl = ACLPrivate(Owner(id='test:tester', acl = ACLPrivate(Owner(id='test:tester',
name='test:tester')) name='test:tester'))
acp = encode_acl('container', acl) acp = encode_acl('container', acl)
header_value = loads(acp[sysmeta_header('container', 'acl')]) header_value = json.loads(acp[sysmeta_header('container', 'acl')])
self.assertTrue('Owner' in header_value) self.assertTrue('Owner' in header_value)
self.assertTrue('Grant' in header_value) self.assertTrue('Grant' in header_value)
@@ -251,7 +253,7 @@ class TestSwift3Subresource(unittest.TestCase):
acl = ACLPrivate(Owner(id='test:tester', acl = ACLPrivate(Owner(id='test:tester',
name='test:tester')) name='test:tester'))
acp = encode_acl('object', acl) acp = encode_acl('object', acl)
header_value = loads(acp[sysmeta_header('object', 'acl')]) header_value = json.loads(acp[sysmeta_header('object', 'acl')])
self.assertTrue('Owner' in header_value) self.assertTrue('Owner' in header_value)
self.assertTrue('Grant' in header_value) self.assertTrue('Grant' in header_value)
@@ -269,7 +271,7 @@ class TestSwift3Subresource(unittest.TestCase):
acp = encode_acl('container', acl) acp = encode_acl('container', acl)
header_value = acp[sysmeta_header('container', 'acl')] header_value = acp[sysmeta_header('container', 'acl')]
header_value = loads(header_value) header_value = json.loads(header_value)
self.assertTrue('Owner' in header_value) self.assertTrue('Owner' in header_value)
self.assertTrue('Grant' in header_value) self.assertTrue('Grant' in header_value)