parent
e97e9aedaa
commit
f552316681
|
@ -14,7 +14,10 @@
|
||||||
|
|
||||||
"""HTTPError exception class."""
|
"""HTTPError exception class."""
|
||||||
|
|
||||||
import json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
import xml.etree.ElementTree as et
|
import xml.etree.ElementTree as et
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -170,8 +173,7 @@ class HTTPError(Exception):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
obj = self.to_dict(OrderedDict)
|
obj = self.to_dict(OrderedDict)
|
||||||
return json.dumps(obj, indent=4, separators=(',', ': '),
|
return json.dumps(obj, ensure_ascii=False)
|
||||||
ensure_ascii=False)
|
|
||||||
|
|
||||||
def to_xml(self):
|
def to_xml(self):
|
||||||
"""Returns an XML-encoded representation of the error.
|
"""Returns an XML-encoded representation of the error.
|
||||||
|
|
|
@ -13,7 +13,10 @@
|
||||||
"""Request class."""
|
"""Request class."""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# NOTE(kgrifs): In Python 2.6 and 2.7, socket._fileobject is a
|
# NOTE(kgrifs): In Python 2.6 and 2.7, socket._fileobject is a
|
||||||
|
|
|
@ -32,7 +32,10 @@ This package includes utilities for simulating HTTP requests against a
|
||||||
WSGI callable, without having to stand up a WSGI server.
|
WSGI callable, without having to stand up a WSGI server.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
import wsgiref.validate
|
import wsgiref.validate
|
||||||
|
|
|
@ -24,7 +24,10 @@ directly from the `testing` package::
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from json import dumps as json_dumps
|
try:
|
||||||
|
from ujson import dumps as json_dumps
|
||||||
|
except ImportError:
|
||||||
|
from json import dumps as json_dumps
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
from .helpers import rand_string
|
from .helpers import rand_string
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import functools
|
import functools
|
||||||
import json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
from falcon import testing
|
from falcon import testing
|
||||||
|
@ -179,11 +182,11 @@ class TestHooks(testing.TestCase):
|
||||||
def test_output_validator(self):
|
def test_output_validator(self):
|
||||||
result = self.simulate_get()
|
result = self.simulate_get()
|
||||||
self.assertEqual(result.status_code, 723)
|
self.assertEqual(result.status_code, 723)
|
||||||
self.assertEqual(result.text, '{\n "title": "Tricky"\n}')
|
self.assertEqual(result.text, json.dumps({'title': 'Tricky'}))
|
||||||
|
|
||||||
def test_serializer(self):
|
def test_serializer(self):
|
||||||
result = self.simulate_put()
|
result = self.simulate_put()
|
||||||
self.assertEqual('{"animal": "falcon"}', result.text)
|
self.assertEqual(result.text, json.dumps({'animal': 'falcon'}))
|
||||||
|
|
||||||
def test_hook_as_callable_class(self):
|
def test_hook_as_callable_class(self):
|
||||||
result = self.simulate_post()
|
result = self.simulate_post()
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import functools
|
import functools
|
||||||
import io
|
import io
|
||||||
import json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
import falcon.testing as testing
|
import falcon.testing as testing
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
import json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
from wsgiref import simple_server
|
from wsgiref import simple_server
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
# -*- coding: utf-8
|
# -*- coding: utf-8
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
import xml.etree.ElementTree as et
|
import xml.etree.ElementTree as et
|
||||||
|
|
||||||
import ddt
|
import ddt
|
||||||
|
@ -284,7 +287,7 @@ class TestHTTPError(testing.TestBase):
|
||||||
def test_no_description_json(self):
|
def test_no_description_json(self):
|
||||||
body = self.simulate_request('/fail', method='PATCH')
|
body = self.simulate_request('/fail', method='PATCH')
|
||||||
self.assertEqual(self.srmock.status, falcon.HTTP_400)
|
self.assertEqual(self.srmock.status, falcon.HTTP_400)
|
||||||
self.assertEqual(body, [b'{\n "title": "400 Bad Request"\n}'])
|
self.assertEqual(body, [json.dumps({'title': '400 Bad Request'}).encode('utf8')])
|
||||||
|
|
||||||
def test_no_description_xml(self):
|
def test_no_description_xml(self):
|
||||||
body = self.simulate_request('/fail', method='PATCH',
|
body = self.simulate_request('/fail', method='PATCH',
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
import falcon.testing as testing
|
import falcon.testing as testing
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
from datetime import date
|
from datetime import date
|
||||||
import json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
|
|
||||||
import ddt
|
import ddt
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import functools
|
import functools
|
||||||
import io
|
import io
|
||||||
import json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
import json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
from falcon import testing
|
from falcon import testing
|
||||||
|
|
Loading…
Reference in New Issue