On 2020/05/10 1:24, Daniel Shahaf wrote:
> Yasuhito FUTATSUKI wrote on Fri, 08 May 2020 20:55 +0900:
>> On 2020/05/08 2:46, Daniel Shahaf wrote:
>>> Yasuhito FUTATSUKI wrote on Thu, 07 May 2020 20:46 +0900:
>>>> I think it is need to escape characters in char *value when we print
>> ^some (not all)
>>>> them as Python's str value. The patch below may work for this purpose,
>>>> but I want someone to write more nice code :)
>>> How about simply adding the human-readable value in a comment? —
>> It's very nice. One of the reason I don't like my code is just
>> readability of the value of "value".
> Sure, in general it's nice for protocols and serialization formats to
> be texty, in order for them to be human-readable and -writable. On
> this instance, however, generating Python string literals that are both
> correct and human-readable seems to me like it'd be an effort spent for
> little gain. (I think there's a good chance that no one will _ever_
> run entries-dump by hand again once it properly supports Python 3.)
> One easy way to make the output nicer is to name the lambda function.
Yes, it's also one of the reasons that it uses lambda function.
I use it only to reduce the occurence of 'value' in
e.name = value if isinstance(value, str) else value.decode()
without using temporary named object, in the first patch.
Then I updated the patch. Not to use lambda function, I added
a method to set str attribute from bytes object to "Entry" class,
and move its definition to the output of entries-dump to show
what it does.
Yasuhito FUTATSUKI <futatuki_at_poem.co.jp>/<futatuki_at_yf.bsdclub.org>
Received on 2020-05-13 00:12:27 CEST