[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Health-dev] [bug #64414] Federation Queue Manager can not show no-ascii
From: |
Feng Shu |
Subject: |
[Health-dev] [bug #64414] Federation Queue Manager can not show no-ascii properly. |
Date: |
Sun, 16 Jul 2023 23:28:28 -0400 (EDT) |
Follow-up Comment #3, bug #64414 (project health):
[comment #2 comment #2:]
> Revert changeset 5888:6a0a46ff3791
> https://hg.savannah.gnu.org/hgweb/health/rev/336e36474d34
>
> We should keep it as str. There is a logic about using ensure_ascii=True, so
it makes sure it always returns a string, instead of a unicode object. To the
human eye the raw string might look strange, but its represntation in reports
and packages will be the correct one.
ensure_ascii=False seem to return a string too.
>>> json.dumps(a)
'{"a": "\\u4f60\\u597d"}'
>>> json.dumps(a, ensure_ascii=False)
'{"a": "你好"}'
>>> type(json.dumps(a, ensure_ascii=False))
<class 'str'>
>>>
>
> Thalamus (and Python in general) parses the unicode escaped strings
properly, so we should keep it like this for now, until we're sure unicode
objects are properly handled in every instance.
I think it maybe not hard, for:
we use ensure_ascii=False when we create args field of FederationQueue
object.
but, when we send federation queue object to Thalamus, we will do the
following two steps in send_record, so we alway send unicode escaped
strings to thalamus.
1. json.loads(record.args)
2. json.dumps(vals)
-----------------------------------------------------
def send_record(cls, record):
...
if (record.method == 'PATCH'):
if (record.federation_locator):
# [{resource, fields[{name, value}]
for arg in json.loads(record.args):
-------------------------------
...
send_data = requests.request(
'PATCH', url,
data=json.dumps(vals),
-----------------------------------
auth=(user, password), verify=verify_ssl)
...
------------------------------------------------------
json.loads work well when ensure_ascii=False:
>
> $python3
> Python 3.9.17 (main, Jun 22 2023, 01:13:35)
> [Clang 13.0.0 (git@github.com:llvm/llvm-project.git
llvmorg-13.0.0-0-gd7b669b3a on freebsd13
> Type "help", "copyright", "credits" or "license" for more information.
> >>> print("\u738b\u4e00\u5200")
> 王一刀
>
> Thanks!
> Luis
>
>
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?64414>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/