mirror of
https://github.com/xcat2/confluent.git
synced 2025-02-16 18:49:04 +00:00
Handle non-ascii unicode better
Clarify that the data is in UTF-8 where applicable. It is expected that clients are capable of handling UTF-8 for now. Additionally, the HTML api explorer handling of numeric data is fixed.
This commit is contained in:
parent
6acaac8644
commit
384baea038
@ -2,6 +2,7 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2014 IBM Corporation
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -108,7 +109,7 @@ def updatestatus(stateinfo={}):
|
||||
def recurse_format(datum, levels=0):
|
||||
ret = ''
|
||||
import json
|
||||
return json.dumps(datum, indent=1)
|
||||
return json.dumps(datum, ensure_ascii=False, indent=1)
|
||||
if isinstance(datum, dict):
|
||||
for key in datum.iterkeys():
|
||||
if datum[key] is None:
|
||||
|
@ -1,6 +1,7 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2014 IBM Corporation
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -32,7 +33,7 @@ def send(handle, data):
|
||||
handle.sendall(data)
|
||||
elif isinstance(data, dict): # JSON currently only goes to 4 bytes
|
||||
# Some structured message, like what would be seen in http responses
|
||||
sdata = json.dumps(data, separators=(',', ':'))
|
||||
sdata = json.dumps(data, ensure_ascii=False, separators=(',', ':'))
|
||||
tl = len(sdata)
|
||||
if tl > 16777215:
|
||||
raise Exception("JSON data exceeds protocol limits")
|
||||
|
@ -1,6 +1,7 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2014 IBM Corporation
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -395,7 +396,7 @@ def resourcehandler_backend(env, start_response):
|
||||
yield '501 Not Implemented'
|
||||
|
||||
def _assemble_html(responses, resource, querydict, url, extension):
|
||||
yield '<html><head><title>' \
|
||||
yield '<html><head><meta charset="UTF-8"><title>' \
|
||||
'Confluent REST Explorer: ' + url + '</title></head>' \
|
||||
'<body><form action="' + \
|
||||
resource + '" method="post">'
|
||||
@ -486,7 +487,7 @@ def _assemble_json(responses, resource, url, extension):
|
||||
else:
|
||||
rspdata[dk] = rsp[dk]
|
||||
rspdata["_links"] = links
|
||||
yield json.dumps(rspdata, sort_keys=True, indent=4)
|
||||
yield json.dumps(rspdata, sort_keys=True, indent=4, ensure_ascii=False)
|
||||
|
||||
|
||||
def serve():
|
||||
|
@ -1,6 +1,7 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2014 IBM Corporation
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
@ -1,6 +1,7 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2014 IBM Corporation
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -26,16 +27,17 @@ def _htmlify_structure(indict):
|
||||
if isinstance(indict, dict):
|
||||
for key in indict.iterkeys():
|
||||
ret += "<li>{0}: ".format(key)
|
||||
if type(indict[key]) in (str, unicode):
|
||||
ret += indict[key]
|
||||
if type(indict[key]) in (str, unicode, float, int):
|
||||
ret += str(indict[key])
|
||||
else:
|
||||
ret += _htmlify_structure(indict[key])
|
||||
elif isinstance(indict, list):
|
||||
if type(indict[0]) in (str, unicode):
|
||||
ret += ",".join(indict)
|
||||
else:
|
||||
for v in indict:
|
||||
ret += _htmlify_structure(v)
|
||||
if len(indict) > 0:
|
||||
if type(indict[0]) in (str, unicode):
|
||||
ret += ",".join(indict)
|
||||
else:
|
||||
for v in indict:
|
||||
ret += _htmlify_structure(v)
|
||||
return ret + '</ul>'
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user