Skip to content

Commit

Permalink
Fix crashes when writing out files
Browse files Browse the repository at this point in the history
XML files as well as key files should always be in UTF-8 encodings.
  • Loading branch information
magcius committed Nov 17, 2012
1 parent d006c55 commit f7835d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Alacarte/MainWindow.py
Expand Up @@ -19,6 +19,7 @@

from gi.repository import Gtk, GObject, Gio, GdkPixbuf, Gdk, GMenu, GLib
import cgi
import codecs
import os
import gettext
import subprocess
Expand Down Expand Up @@ -319,7 +320,9 @@ def on_edit_properties_activate(self, menu):

if not os.path.isfile(file_path):
data = open(item.get_desktop_file_path()).read()
open(file_path, 'w').write(data)
fd = codecs.open(file_path, 'w', 'utf8')
fd.write(data)
fd.close()

if file_path not in self.edit_pool:
self.edit_pool.append(file_path)
Expand Down
9 changes: 5 additions & 4 deletions Alacarte/MenuEditor.py
Expand Up @@ -16,6 +16,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import codecs
import os
import xml.dom.minidom
import xml.parsers.expat
Expand Down Expand Up @@ -48,7 +49,7 @@ def menuChanged(self, *a):
self.load()

def save(self):
fd = open(self.path, 'w')
fd = codecs.open(self.path, 'w', 'utf8')
fd.write(self.dom.toprettyxml())
fd.close()

Expand Down Expand Up @@ -259,7 +260,7 @@ def copyItem(self, item, new_parent, before=None, after=None):

contents, length = keyfile.to_data()

f = open(out_path, 'w')
f = codecs.open(out_path, 'w', 'utf8')
f.write(contents)
f.close()

Expand Down Expand Up @@ -400,7 +401,7 @@ def writeItem(self, item, **kwargs):

contents, length = keyfile.to_data()

f = open(os.path.join(util.getUserItemPath(), file_id), 'w')
f = codecs.open(os.path.join(util.getUserItemPath(), file_id), 'w', 'utf8')
f.write(contents)
f.close()
return file_id
Expand All @@ -421,7 +422,7 @@ def writeMenu(self, menu, **kwargs):

contents, length = keyfile.to_data()

f = open(os.path.join(util.getUserDirectoryPath(), file_id), 'w')
f = codecs.open(os.path.join(util.getUserDirectoryPath(), file_id), 'w', 'utf8')
f.write(contents)
f.close()
return file_id
Expand Down

0 comments on commit f7835d7

Please sign in to comment.