[Top][All Lists]

[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 
> 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 

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, 
                        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 (
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:


Message sent via Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]