Am Samstag, 14. Oktober 2017 um 21:09:05, schrieb Kornel Benko <kor...@lyx.org>
> Am Samstag, 14. Oktober 2017 um 20:38:04, schrieb Uwe Stöhr <uwesto...@web.de>
> > > Is there some reason we can't use Python 3.5? You bundle this with the
> > > application, right?
> >
> > I tried now the latest Python 3.5 and today's 2.3 branch and get this error:
> >
> > Generating Additional.lyx
> >    Traceback (most recent call last):
> >      File "D:/LyXGit/2.3.x/development/cmake/doc/ReplaceValues.py", line
> > 55, in <module> SubstituteDataInFile(args[0])
> >      File "D:/LyXGit/2.3.x/development/cmake/doc/ReplaceValues.py", line
> > 36, in SubstituteDataInFile for line in open(InFile):
> >      File "C:\Program Files (x86)\Python35-32\lib\encodings\cp1252.py",
> > line 23, in decode return
> > codecs.charmap_decode(input,self.errors,decoding_table)[0]
> >    UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in
> > position 2528: character maps to <undefined>
> >
> > So what should I do? I cannot provide an installer for LyX 2.3 because
> > of this.
> >
> > thanks and regards
> > Uwe
>
> What is the exact directory name of Additional.lyx on your platform?
> Check also \origin part of  Additional.lyx.
>
> Can it be that python looks for wrong encoding (e.g. cp1252) which does _not_ 
> contain 0x9d char.
>
> Maybe this helps a little
>       
> https://stackoverflow.com/questions/42130110/character-with-byte-sequence-0x9d-in-encoding-win1252-has-no-equivalent-in-enc
>

Could you try the attached?

        Kornel
#! /usr/bin/env python

from __future__ import print_function

# file ReplaceValues.py
#
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.
#
# author: Kornel Benko, kor...@lyx.org
#
# Syntax: ReplaceValues.py [<var1>=<Subst1> [<var2>=<Subst> ...]] <Inputfile> [<Inputfile> ...]

import sys
import re
import codecs

Subst = {}  # map of desired substitutions
prog = re.compile("")

def createProg():
    matchingS = "\\b|\\b".join(Subst.keys())
    pattern = "".join(["(.*)(\\b", matchingS, "\\b)(.*)"])
    return re.compile(pattern)

def SubstituteDataInLine(line):
    result = line
    m = prog.match(result)
    if m:
        return "".join([SubstituteDataInLine(m.group(1)),
                        Subst[m.group(2)],
                        SubstituteDataInLine(m.group(3))])
    return line


def SubstituteDataInFile(InFile):
    for line in codecs.open(InFile, 'r', 'UTF-8'):
        print(SubstituteDataInLine(line[:-1]))

##########################################


args = sys.argv

del args[0] # we don't need the name ot this script
while len(args) > 0:
    arg = args[0]
    entry = args[0].split("=",1)
    if len(entry) == 2:
        key=entry[0]
        val=entry[1]
        if len(key) > 0:
            Subst[key] = val
    else:
        prog = createProg()
        SubstituteDataInFile(args[0])
    del args[0]

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to