[PATCH] Remove 'encoding=iso-8859-1' from json.dumps()

The encoding option for json.dumps() is used to indicate the charsets of the passed in str. Currently, we use the encoding of iso-8859-1, but actually we don't have any data encoded in iso-8859-1. It doesn't cause any problem because the strings in the data passed are ascii chars or unicode. If we pass a utf-8 str, it will canse an expected result. So we could remove the option, and after that it can accept utf-8 str too because json.dumps use utf-8 as default encoding. Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com> --- src/kimchi/template.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/kimchi/template.py b/src/kimchi/template.py index 1f19c4a..f854657 100644 --- a/src/kimchi/template.py +++ b/src/kimchi/template.py @@ -84,9 +84,7 @@ def can_accept_html(): def render(resource, data): if can_accept('application/json'): cherrypy.response.headers['Content-Type'] = 'application/json;charset=utf-8' - return json.dumps(data, indent=2, - separators=(',', ':'), - encoding='iso-8859-1') + return json.dumps(data, indent=2, separators=(',', ':')) elif can_accept_html(): filename = config.get_template_path(resource) try: -- 1.8.4.2

On 01/22/2014 07:09 PM, Mark Wu wrote:
The encoding option for json.dumps() is used to indicate the charsets of the passed in str. Currently, we use the encoding of iso-8859-1, but actually we don't have any data encoded in iso-8859-1. It doesn't cause any problem because the strings in the data passed are ascii chars or unicode. If we pass a utf-8 str, it will canse an expected result. canse?
So we could remove the option, and after that it can accept utf-8 str too because json.dumps use utf-8 as default encoding.
Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com> --- src/kimchi/template.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/kimchi/template.py b/src/kimchi/template.py index 1f19c4a..f854657 100644 --- a/src/kimchi/template.py +++ b/src/kimchi/template.py @@ -84,9 +84,7 @@ def can_accept_html(): def render(resource, data): if can_accept('application/json'): cherrypy.response.headers['Content-Type'] = 'application/json;charset=utf-8' - return json.dumps(data, indent=2, - separators=(',', ':'), - encoding='iso-8859-1') + return json.dumps(data, indent=2, separators=(',', ':')) elif can_accept_html(): filename = config.get_template_path(resource) try:
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 01/22/2014 09:17 AM, Sheldon wrote:
On 01/22/2014 07:09 PM, Mark Wu wrote:
The encoding option for json.dumps() is used to indicate the charsets of the passed in str. Currently, we use the encoding of iso-8859-1, but actually we don't have any data encoded in iso-8859-1. It doesn't cause any problem because the strings in the data passed are ascii chars or unicode. If we pass a utf-8 str, it will canse an expected result. canse?
I will fix the typo and apply.
So we could remove the option, and after that it can accept utf-8 str too because json.dumps use utf-8 as default encoding.
Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com> --- src/kimchi/template.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/kimchi/template.py b/src/kimchi/template.py index 1f19c4a..f854657 100644 --- a/src/kimchi/template.py +++ b/src/kimchi/template.py @@ -84,9 +84,7 @@ def can_accept_html(): def render(resource, data): if can_accept('application/json'): cherrypy.response.headers['Content-Type'] = 'application/json;charset=utf-8' - return json.dumps(data, indent=2, - separators=(',', ':'), - encoding='iso-8859-1') + return json.dumps(data, indent=2, separators=(',', ':')) elif can_accept_html(): filename = config.get_template_path(resource) try:

Reviewed-by: Crístian Viana <vianac@linux.vnet.ibm.com> Am 22-01-2014 09:09, schrieb Mark Wu:
The encoding option for json.dumps() is used to indicate the charsets of the passed in str. Currently, we use the encoding of iso-8859-1, but actually we don't have any data encoded in iso-8859-1. It doesn't cause any problem because the strings in the data passed are ascii chars or unicode. If we pass a utf-8 str, it will canse an expected result. So we could remove the option, and after that it can accept utf-8 str too because json.dumps use utf-8 as default encoding.
Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com>
participants (4)
-
Aline Manera
-
Crístian Viana
-
Mark Wu
-
Sheldon