Fwd: String/Bytes Problem in layout2layout.py

José Abílio Matos jamatos at lyx.org
Mon Jan 3 14:04:20 UTC 2022


On Wednesday, 29 December 2021 14.52.29 WET Pavel Sanda wrote:
> Jose,
> 
> are the proposed changes sensible?
> I remember there were flowing similar patches to python codebase before.

The changes are reasonable for python 3.
I am not so sure about python 2 (because we support it) although it seems 
likely. :-)

We are using bytes here to avoid choosing an encoding, that it should be utf-8 
for all layout files, if I am not mistaken. In lyx2lyx we do this in 2 passes, 
first we determine the encoding and then we use that information to read the 
correct encoding.

Looking into further detail I would easily that the first part of the patch is 
correct (change "..." to b"...").

The second part where it changes sys.stdin to sys.stdin.buffer is probably 
incorrect:

The similar code in 2.4 is:
    # Open files
    if options.input_file:
        source = open(options.input_file, 'rb')
    elif PY2:
        source = sys.stdin
    else:
        source = sys.stdin.buffer

    if options.output_file:
        output = open(options.output_file, 'wb')
    elif PY2:
        output = sys.stdout
    else:
        output = sys.stdout.buffer

So this should be the right change, keep the previous form if PY2 (python 2 is 
used) else use the new call.

-- 
José Abílio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20220103/26f9ba63/attachment-0001.html>


More information about the lyx-devel mailing list