[gedit] Open files with utf-8 encoding



commit a2f45f6e4b1ab42b6e0feb93eecf90d1f895db09
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sat Apr 12 17:04:28 2014 +0200

    Open files with utf-8 encoding
    
    This fixes issues in python 3 for reading tools and snippets
    files when gedit is run in an environment with a non utf-8
    locale
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722948

 plugins/externaltools/tools/library.py  |    8 ++++----
 plugins/quickopen/quickopen/__init__.py |    4 ++--
 plugins/snippets/snippets/library.py    |    2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/plugins/externaltools/tools/library.py b/plugins/externaltools/tools/library.py
index 478b617..adfd943 100644
--- a/plugins/externaltools/tools/library.py
+++ b/plugins/externaltools/tools/library.py
@@ -246,7 +246,7 @@ class Tool(object):
         if filename is None:
             return
 
-        fp = open(filename, 'r', 1)
+        fp = open(filename, 'r', 1, encoding='utf-8')
         in_block = False
         lang = locale.getlocale(locale.LC_MESSAGES)[0]
 
@@ -395,7 +395,7 @@ class Tool(object):
         if filename is None:
             return True
 
-        fp = open(filename, 'r', 1)
+        fp = open(filename, 'r', 1, encoding='utf-8')
         for line in fp:
             if line.strip() == '':
                 continue
@@ -411,7 +411,7 @@ class Tool(object):
         if filename is None:
             return ["#!/bin/sh\n"]
 
-        fp = open(filename, 'r', 1)
+        fp = open(filename, 'r', 1, encoding='utf-8')
         lines = list()
 
         # before entering the data block
@@ -445,7 +445,7 @@ class Tool(object):
 
     def save_with_script(self, script):
         filename = self.library.get_full_path(self.filename, 'w')
-        fp = open(filename, 'w', 1)
+        fp = open(filename, 'w', 1, encoding='utf-8')
 
         # Make sure to first print header (shebang, modeline), then
         # properties, and then actual content
diff --git a/plugins/quickopen/quickopen/__init__.py b/plugins/quickopen/quickopen/__init__.py
index 317b48e..9cf874f 100644
--- a/plugins/quickopen/quickopen/__init__.py
+++ b/plugins/quickopen/quickopen/__init__.py
@@ -119,7 +119,7 @@ class QuickOpenPlugin(GObject.Object, Gedit.WindowActivatable):
 
         paths = []
 
-        for line in open(filename, 'r'):
+        for line in open(filename, 'r', encoding='utf-8'):
             uri = line.strip().split(" ")[0]
             f = Gio.file_new_for_uri(uri)
 
@@ -146,7 +146,7 @@ class QuickOpenPlugin(GObject.Object, Gedit.WindowActivatable):
         desktopdir = None
 
         if os.path.isfile(config):
-            for line in open(config, 'r'):
+            for line in open(config, 'r', encoding='utf-8'):
                 line = line.strip()
 
                 if line.startswith('XDG_DESKTOP_DIR'):
diff --git a/plugins/snippets/snippets/library.py b/plugins/snippets/snippets/library.py
index 92adc3c..455ac91 100644
--- a/plugins/snippets/snippets/library.py
+++ b/plugins/snippets/snippets/library.py
@@ -453,7 +453,7 @@ class SnippetsSystemFile:
         self.insnippet = False
 
         try:
-            f = open(self.path, "r")
+            f = open(self.path, "r", encoding='utf-8')
         except IOError:
             self.ok = False
             return


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]