[pygobject] [gtk-demo] In Python3, GLib.file_get_contents returns a bytes object but Gtk.TextBuffer.insert expec



commit c2979a37d6d505095b6e55789150a6498d95819d
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date:   Mon Aug 22 14:22:18 2011 +0200

    [gtk-demo] In Python3, GLib.file_get_contents returns a bytes object but Gtk.TextBuffer.insert expects a string.
    
    Fixed by using codes.open() as hinted in http://docs.python.org/dev/howto/pyporting.html#text-files
    section "If pre-2.6 compatibility is needed" (because configure.ac is still happy with Python 2.5.2).

 demos/gtk-demo/gtk-demo.py |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
---
diff --git a/demos/gtk-demo/gtk-demo.py b/demos/gtk-demo/gtk-demo.py
index de31768..218bb63 100755
--- a/demos/gtk-demo/gtk-demo.py
+++ b/demos/gtk-demo/gtk-demo.py
@@ -22,6 +22,7 @@
 
 import os
 import sys
+import codecs
 import glob
 import tokenize
 import keyword
@@ -219,7 +220,10 @@ class GtkDemoWindow(Gtk.Window):
             return
 
         description = demo.module.description
-        code = GLib.file_get_contents(demo.filename)[1]
+
+        f = codecs.open(demo.filename, 'rU', 'utf-8')
+        code = f.read()
+        f.close()
 
         # output and style the title
         (start, end) = self.info_buffer.get_bounds()



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