File: 0006-Add-utf-16-encoding-when-opening-the-phrase-file.patch

package info (click to toggle)
libpyzy 1.0.1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,544 kB
  • sloc: python: 23,416; cpp: 20,929; makefile: 346; sql: 94; php: 16; sh: 16
file content (34 lines) | stat: -rw-r--r-- 1,275 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
From: Pugalendhi Ganesan <pugalendhi.ganesan@lge.com>
Date: Wed, 29 Jul 2020 18:04:48 +0530
Subject: Add "utf-16" encoding when opening the phrase file
Forwarded: https://github.com/pyzy/pyzy/pull/4

Signed-off-by: Martin Jansa <martin.jansa@lge.com>
---
 data/db/android/create_db.py | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/data/db/android/create_db.py b/data/db/android/create_db.py
index d6a1a27..f648670 100755
--- a/data/db/android/create_db.py
+++ b/data/db/android/create_db.py
@@ -17,8 +17,7 @@ def get_sheng_yun(pinyin):
     return "", pinyin
 
 def read_phrases(filename):
-    buf = open(filename, 'r+b').read()
-    buf = str(buf, "utf16")
+    buf = open(filename,encoding='utf-16').read()
     buf = buf.strip()
     for l in buf.split('\n'):
         hanzi, freq, flag, pinyin = l.split(' ', 3)
@@ -70,8 +69,7 @@ def create_db(filename):
             s, y = pinyin_id[s], pinyin_id[y]
             columns.append(s)
             columns.append(y)
-        values = "'%s', %d, %s" % (hanzi.encode("utf8"), freq, ",".join(map(str,columns)))
-            
+        values = "'%s', %d, %s" % (hanzi, freq, ",".join(map(str,columns)))
         sql = insert_sql % (len(hanzi) - 1, values)
         print(sql)
     print("COMMIT;")