[pygtk-docs] * Allow longer input strings to facilitate cut-and-paste of code.



commit df505b909236aa755983e817410f5f6c30ac8eb3
Author: John Finlay <finlay moeraki com>
Date:   Mon Jul 13 17:20:19 2009 -0700

    	* Allow longer input strings to facilitate cut-and-paste of code.

 examples/pygtkconsole.py |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/examples/pygtkconsole.py b/examples/pygtkconsole.py
index 92fafab..53dcf8e 100755
--- a/examples/pygtkconsole.py
+++ b/examples/pygtkconsole.py
@@ -13,6 +13,7 @@ from code import InteractiveInterpreter, InteractiveConsole
 
 import gtk
 import gobject
+import struct
 
 # For compatibility, instead of using GDK.INPUT_READ or
 # gtk.gdk.INPUT_READ depending on the PyGtk version
@@ -26,7 +27,7 @@ class Mainloop(InteractiveInterpreter):
         gobject.io_add_watch(read_fd, GDK_INPUT_READ, self.input_func)
 
     def read_message(self):
-        length = ord(self._rfd.read(1))
+        length, = struct.unpack('H', self._rfd.read(2))
         return self._rfd.read(length)
 
     def input_func(self, fd, cond):
@@ -46,7 +47,7 @@ class Console(InteractiveConsole):
         self.pid = pid
 
     def send_message(self, message):
-        self._wfd.write('%c%s' % (len(message), message))
+        self._wfd.write(struct.pack('H', len(message)) + message)
         self._wfd.flush()
 
     def interact(self, banner=None):



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