Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_encodeNoneConversion(self):
input = None
output = ujson.encode(input)
self.assertEquals(input, json.loads(output))
self.assertEquals(output, json.dumps(input))
self.assertEquals(input, ujson.decode(output))
pass
def test_encodeFalseConversion(self):
input = False
output = ujson.encode(input)
self.assertEquals(input, json.loads(output))
self.assertEquals(output, json.dumps(input))
self.assertEquals(input, ujson.decode(output))
pass
def test_encodeLongNegConversion(self):
input = -9223372036854775808
output = ujson.encode(input)
outputjson = json.loads(output)
outputujson = ujson.decode(output)
self.assertEquals(input, json.loads(output))
self.assertEquals(output, json.dumps(input))
self.assertEquals(input, ujson.decode(output))
pass
def ujsonEnc():
x = ujson.encode(testObject, ensure_ascii=False)
#print "ujsonEnc", x
def render(self):
stack_trace = traceback.format_exc()
if context.response_content_type == 'application/json':
return ujson.encode(
dict(stackTrace=stack_trace) if settings.debug else dict()
)
context.response_encoding = 'utf-8'
context.response_content_type = 'text/plain'
return stack_trace if settings.debug \
else self.status.split(' ', 1)[1]
def __init__(self, status=None, headers=None, body=None, status_code=None, status_text=None):
self.status_code = status_code
self.status_text = status_text
if status:
self.status = status
if isinstance(body, dict):
body = ujson.encode(body)
self.buffer = body.splitlines() if body else []
self.headers = headers or []
for i in self.headers:
k, v = i.split(': ') if isinstance(i, str) else i
if k == 'Content-Type':
match = CONTENT_TYPE_PATTERN.match(v)
if match:
self.content_type, self.encoding = match.groups()
break
def _handle_exception(self, ex):
context.response_encoding = 'utf-8'
error = ex if isinstance(ex, HttpStatus) else InternalServerError(sys.exc_info())
error_page = self._hook('request_error', error)
message = error.status_text
description = error.render() if settings.debug else error.info if error_page is None else error_page
if context.response_content_type == 'application/json':
response = ujson.encode(dict(
message=message,
description=description
))
else:
context.response_content_type = 'text/plain'
response = "%s\n%s" % (message, description)
if isinstance(error, InternalServerError):
traceback.print_exc()
def resp():
yield response
return error.status, resp()
def make_request(self, location, method, data=None, timeout=None, json=True, log=True):
url = location if location.startswith('http') else '%s/%s' % (self.url, location)
timeout = timeout if timeout is not None else self.timeout
payload = ujson.encode(data) if data else '{}'
if self.gzip:
payload = zlib.compress(payload, self.gzip)
start_time = time.time()
result, http_code, request_id = '', 500, None
try:
if method == 'get':
r = self.session.get(
url,
timeout=timeout,
verify=self.verify_ssl_cert,
proxies=self.proxies
)
else:
r = self.session.post(
url,