Issue27413
Created on 2016-06-29 11:49 by legnaleurc, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| json-add-an-option-to-bypass-non-ascii-characters-v4.patch | legnaleurc, 2016-08-28 08:45 | review | ||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 201 | closed | dhimmel, 2017-02-23 20:10 | |
| PR 2720 | closed | dhimmel, 2017-07-15 19:00 | |
| PR 17472 | merged | wim.glenn, 2019-12-05 08:11 | |
| Messages (13) | |||
|---|---|---|---|
| msg269479 - (view) | Author: Wei-Cheng Pan (legnaleurc) * | Date: 2016-06-29 11:49 | |
This patch adds a command line option "--no-escape" that allows json.tool to display non-ASCII characters. e.g.: $ echo '"測試"' | python -m json.tool "\u6e2c\u8a66" $ echo '"測試"' | python -m json.tool --no-escape "測試" |
|||
| msg269498 - (view) | Author: R. David Murray (r.david.murray) * | Date: 2016-06-29 14:15 | |
Maybe name it --no-insure-ascii? Or --insure-ascii=no/yes. (or true/false). |
|||
| msg269559 - (view) | Author: Wei-Cheng Pan (legnaleurc) * | Date: 2016-06-30 03:30 | |
If the arguments should be aligned with those in dump/load, then maybe "--no-ensure-ascii" is an option? |
|||
| msg269584 - (view) | Author: R. David Murray (r.david.murray) * | Date: 2016-06-30 15:25 | |
Sorry, yes, that's what I meant. I think it will make it easier to understand and remember if the option uses the same terminology as the function. |
|||
| msg269641 - (view) | Author: Wei-Cheng Pan (legnaleurc) * | Date: 2016-07-01 03:52 | |
Use "--no-ensure-ascii" instead. |
|||
| msg269648 - (view) | Author: Berker Peksag (berker.peksag) * | Date: 2016-07-01 07:36 | |
The patch needs tests and documentation.
> + parser.add_argument('--no-ensure-ascii', action='store_true', default=False,
I'd go with ``action='store_false', default=True``.
|
|||
| msg269667 - (view) | Author: Wei-Cheng Pan (legnaleurc) * | Date: 2016-07-01 13:45 | |
> The patch needs tests and documentation.
Ok, I'll update it later.
>> + parser.add_argument('--no-ensure-ascii', action='store_true', default=False,
>I'd go with ``action='store_false', default=True``.
If I'm not misreading your comment, this will change the original behavior, right? (because options.no_ensure_ascii will be set to True by default)
|
|||
| msg273803 - (view) | Author: Wei-Cheng Pan (legnaleurc) * | Date: 2016-08-28 03:21 | |
Added doc and test. |
|||
| msg273814 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2016-08-28 08:07 | |
Test fails on non-utf8 locale. $ LC_ALL=en_US ./python -m test.regrtest -v -m test_no_ensure_ascii_flag test_json ... ====================================================================== FAIL: test_no_ensure_ascii_flag (test.test_json.test_tool.TestTool) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/serhiy/py/cpython/Lib/test/test_json/test_tool.py", line 115, in test_no_ensure_ascii_flag self.assertEqual(out.splitlines(), b'"\\u6e2c\\u8a66"\n'.splitlines()) AssertionError: Lists differ: [b'"\\u00e6\\u00b8\\u00ac\\u00e8\\u00a9\\u00a6"'] != [b'"\\u6e2c\\u8a66"'] First differing element 0: b'"\\u00e6\\u00b8\\u00ac\\u00e8\\u00a9\\u00a6"' b'"\\u6e2c\\u8a66"' - [b'"\\u00e6\\u00b8\\u00ac\\u00e8\\u00a9\\u00a6"'] + [b'"\\u6e2c\\u8a66"'] ---------------------------------------------------------------------- |
|||
| msg273817 - (view) | Author: Wei-Cheng Pan (legnaleurc) * | Date: 2016-08-28 08:45 | |
1. Replaced non-ASCII literals to \uXXXX 2. Removed failed assertion Test passed with LC_ALL=en_US and LC_ALL=en_US.UTF-8 . I've tried to use locale.getdefaultlocale(), but seems the output string will vary in different locales. |
|||
| msg273819 - (view) | Author: Berker Peksag (berker.peksag) * | Date: 2016-08-28 10:23 | |
> If I'm not misreading your comment, this will change the original behavior, right? Assuming you also change ensure_ascii = not options.no_ensure_ascii to ensure_ascii = options.no_ensure_ascii no, it won't change the original behavior. That way you won't need to invert the value of ``options.no_ensure_ascii`` in line 37. |
|||
| msg273911 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2016-08-30 11:36 | |
The last change just sweeps a problem under a rug. For now json.tool never fails with valid data. But with the --no-ensure-ascii option it can fail when output a string not encodable with the locale encoding. All can work with common cases on common UTF-8 environment, but unexpectedly fail on nonstandard environment. It would be better to output encodable characters as is and represent unencodable characters with \uXXXX encoding. |
|||
| msg357902 - (view) | Author: Inada Naoki (methane) * | Date: 2019-12-06 06:44 | |
New changeset efefe25443c56988841ab96cdac01352123ba268 by Inada Naoki (wim glenn) in branch 'master': bpo-27413: json.tool: Add --no-ensure-ascii option. (GH-17472) https://github.com/python/cpython/commit/efefe25443c56988841ab96cdac01352123ba268 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:33 | admin | set | github: 71600 |
| 2019-12-06 06:44:23 | methane | set | status: open -> closed stage: patch review -> resolved resolution: fixed versions: + Python 3.9, - Python 3.7 |
| 2019-12-06 06:44:05 | methane | set | nosy:
+ methane messages: + msg357902 |
| 2019-12-05 08:11:04 | wim.glenn | set | pull_requests: + pull_request16953 |
| 2017-08-16 12:22:16 | r.david.murray | set | versions: + Python 3.7, - Python 3.6 |
| 2017-08-16 12:22:10 | r.david.murray | set | nosy:
+ qingyunha |
| 2017-08-16 12:21:46 | r.david.murray | link | issue31216 superseder |
| 2017-07-15 19:00:48 | dhimmel | set | pull_requests: + pull_request2779 |
| 2017-02-23 20:10:42 | dhimmel | set | pull_requests: + pull_request232 |
| 2016-08-30 11:36:21 | serhiy.storchaka | set | messages: + msg273911 |
| 2016-08-28 10:23:47 | berker.peksag | set | messages: + msg273819 |
| 2016-08-28 09:09:22 | rhettinger | set | messages: - msg273813 |
| 2016-08-28 08:49:42 | rhettinger | set | assignee: rhettinger -> |
| 2016-08-28 08:45:51 | legnaleurc | set | files: - json-add-an-option-to-bypass-non-ascii-characters-v3.patch |
| 2016-08-28 08:45:43 | legnaleurc | set | files:
+ json-add-an-option-to-bypass-non-ascii-characters-v4.patch messages: + msg273817 |
| 2016-08-28 08:07:30 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg273814 |
| 2016-08-28 07:34:28 | rhettinger | set | assignee: rhettinger messages:
+ msg273813 |
| 2016-08-28 03:21:30 | legnaleurc | set | files: - json-add-an-option-to-bypass-non-ascii-characters.patch |
| 2016-08-28 03:21:13 | legnaleurc | set | files:
+ json-add-an-option-to-bypass-non-ascii-characters-v3.patch messages: + msg273803 |
| 2016-07-01 13:45:39 | legnaleurc | set | messages: + msg269667 |
| 2016-07-01 07:36:21 | berker.peksag | set | nosy:
+ berker.peksag messages:
+ msg269648 |
| 2016-07-01 03:52:49 | legnaleurc | set | files:
+ json-add-an-option-to-bypass-non-ascii-characters.patch messages: + msg269641 |
| 2016-07-01 03:51:22 | legnaleurc | set | files: - json-add-an-option-to-bypass-non-ascii-characters.patch |
| 2016-06-30 15:25:08 | r.david.murray | set | messages: + msg269584 |
| 2016-06-30 03:30:32 | legnaleurc | set | messages: + msg269559 |
| 2016-06-29 14:15:50 | r.david.murray | set | nosy:
+ r.david.murray messages: + msg269498 |
| 2016-06-29 11:49:29 | legnaleurc | create | |