Skip to content

Commit 9a06d9e

Browse files
author
stonebig
committed
don't multiply utf-8 tags
1 parent 04af0c0 commit 9a06d9e

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

examples/sqlite_py_manager.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def __init__(self):
3838

3939
self.font_size = 10
4040
self.font_wheight = 0
41-
# self.chg_size()
4241
# With a Menubar and Toolbar
4342
self.create_menu()
4443
self.create_toolbar()
@@ -87,7 +86,7 @@ def create_menu(self):
8786
self.menu_help.add_command(label='about',
8887
command=lambda: messagebox.showinfo(message="""
8988
\nSqlite_py_manager : a graphic SQLite Client in 1 Python file
90-
\nversion 2014-06-09a : 'The magic 8th PEP'
89+
\nversion 2014-06-09b : 'The magic 8th PEP'
9190
\n(https://github.com/stonebig/baresql/blob/master/examples)"""))
9291

9392
def create_toolbar(self):
@@ -96,7 +95,7 @@ def create_toolbar(self):
9695
self.toolbar.pack(side=TOP, fill=X)
9796
self.tk_icon = self.get_tk_icons()
9897

99-
# list of image, action, tootip :
98+
# list of (image, action, tooltip) :
10099
to_show = [
101100
('refresh_img', self.actualize_db, "Actualize Databases"),
102101
('run_img', self.run_tab, "Run Script Selection"),
@@ -170,11 +169,10 @@ def savdb_script(self):
170169
title="save database structure in a text file",
171170
filetypes=[("default", "*.sql"), ("other", "*.txt"),
172171
("all", "*.*")])
173-
if filename == '':
174-
return
175-
with io.open(filename, 'w', encoding='utf-8') as f:
176-
for line in self.conn.iterdump():
177-
f.write('%s\n' % line)
172+
if filename != '':
173+
with io.open(filename, 'w', encoding='utf-8') as f:
174+
for line in self.conn.iterdump():
175+
f.write('%s\n' % line)
178176

179177
def sav_script(self):
180178
"""save a script in a file"""
@@ -188,11 +186,11 @@ def sav_script(self):
188186
title="save script in a sql file",
189187
filetypes=[("default", "*.sql"), ("other", "*.txt"),
190188
("all", "*.*")])
191-
if filename == "":
192-
return
193-
with io.open(filename, 'w', encoding='utf-8') as f:
194-
f.write("/*utf-8 bug safety : 你好 мир Artisou à croute blonde*/\n")
195-
f.write(script)
189+
if filename != "":
190+
with io.open(filename, 'w', encoding='utf-8') as f:
191+
if "你好 мир Artisou à croute" not in script:
192+
f.write("/*utf-8 tag : 你好 мир Artisou à croute*/\n")
193+
f.write(script)
196194

197195
def attach_db(self):
198196
"""attach an existing database"""
@@ -283,7 +281,8 @@ def exsav_script(self):
283281
if filename == "":
284282
return
285283
with io.open(filename, 'w', encoding='utf-8') as f:
286-
f.write("/*utf-8 bug safety : 你好 мир Artisou à croute blonde*/\n")
284+
if "你好 мир Artisou à croute" not in script:
285+
f.write("/*utf-8 tag : 你好 мир Artisou à croute*/\n")
287286
self.create_and_add_results(script, active_tab_id, limit=99, log=f)
288287
fw.focus_set() # workaround bug http://bugs.python.org/issue17511
289288

@@ -329,7 +328,7 @@ def get_tk_icons(self):
329328
# to create this base 64 from a toto.gif image of 24x24 size do :
330329
# import base64
331330
# b64 = base64.encodestring(open(r"toto.gif","rb").read())
332-
# print("'gif_img':'''\\\n" + b64.decode("utf8") + "'''")
331+
# print("'gif_img': '''\\\n" + b64.decode("utf8") + "'''")
333332
icons = {
334333
'run_img': '''\
335334
R0lGODdhGAAYAJkAADOqM////wCqMwAAACwAAAAAGAAYAAACM4SPqcvt7wJ8oU5W8025b9OFW0hO
@@ -404,10 +403,7 @@ def get_tk_icons(self):
404403
xlzceksqu6ET7JwtLRrhwNt+1HdDUQAAOw==
405404
'''
406405
}
407-
# transform 'in place' base64 icons into tk_icons
408-
for key, value in icons.items():
409-
icons[key] = PhotoImage(data=value)
410-
return icons
406+
return {k: PhotoImage(data=v) for k, v in icons.items()}
411407

412408
def createToolTip(self, widget, text):
413409
"""create a tooptip box for a widget."""
@@ -1123,8 +1119,8 @@ def close(self):
11231119

11241120
def iterdump(self):
11251121
"""dump the database (add tweaks over the default dump)"""
1126-
# force detection of utf-8
1127-
yield("/*utf-8 bug safety : 你好 мир Artisou à croute blonde*/\n")
1122+
# force detection of utf-8 by placing an only utf-8 comment at top
1123+
yield("/*utf-8 tag : 你好 мир Artisou à croute*/\n")
11281124
# add the Python functions pydef
11291125
for k in self.conn_def.values():
11301126
yield(k['pydef'] + ";\n")
@@ -1141,7 +1137,7 @@ def iterdump(self):
11411137
for row in self.conn.execute("PRAGMA foreign_keys"):
11421138
flag = 'ON' if row[0] == 1 else 'OFF'
11431139
yield("PRAGMA foreign_keys = %s;/*if SQlite*/;" % flag)
1144-
yield("PRAGMA foreign_keys = %s;/*if SQlite, twice*/;" % flag)
1140+
yield("PRAGMA foreign_keys = %s;/*if SQlite bug*/;" % flag)
11451141
yield("PRAGMA foreign_key_check;/*if SQLite, check*/;")
11461142
yield("\n/*SET foreign_key_checks = %s;/*if Mysql*/;\n" % row[0])
11471143

0 commit comments

Comments
 (0)