On 2019-07-14, Jürgen Spitzmüller wrote:

> [-- Type: text/plain, Encoding: quoted-printable --]

> Am Sonntag, den 14.07.2019, 08:17 +0000 schrieb Guenter Milde:
>> This file is for Python2.

>> The patch below made it work with Python3.5 here.

> Does it also still work with python 2.7?

It did not. Is it required?

The patch below makes it run with both, 2.7 and 3.5 in a simple
test:

 python3 postats.py "2.4.0dev" ar.po de.po
 
 python postats.py "2.4.0dev" ar.po de.po
 
 
Günter

diff --git a/po/postats.py b/po/postats.py
index 8c5f058642..52690967da 100755
--- a/po/postats.py
+++ b/po/postats.py
@@ -37,6 +37,8 @@ ommitted = ('en.po')
 
 import os
 import sys
+import codecs
+from subprocess import Popen, PIPE
 
 # Reset the locale
 import locale
@@ -69,7 +71,7 @@ def read_pofile(pofile):
     """ Read the header of the pofile and return it as a dictionary"""
     header = {}
     read_header = False
-    for line in open(pofile):
+    for line in codecs.open(pofile, encoding='utf8'):
         line = line[:-1]
         if line[:5] == 'msgid':
             if read_header:
@@ -112,12 +114,13 @@ def run_msgfmt(pofile):
     prop["email"] = prop["email"].replace(".", " ! ")
     translator = header['Last-Translator'].split('<')[0].strip()
     try:
-        prop["translator"] = 
translator.decode(charset).encode('ascii','xmlcharrefreplace')
+        prop["translator"] = translator.encode('ascii','xmlcharrefreplace')
     except LookupError:
         prop["translator"] = translator
 
-    p_in, p_out = os.popen4("msgfmt --statistics -o %s %s" % (gmofile, pofile))
-    extract_number(p_out.readline(),
+    P = Popen("msgfmt --statistics -o %s %s" % (gmofile, pofile),
+              shell=True, stdin=PIPE, stdout=PIPE, close_fds=True)
+    extract_number(P.stdout.readline().decode(),
                    ('translated', 'fuzzy', 'untranslated'),
                    prop)
     return """
 

Reply via email to