[Yum-devel] [PATCH] Sick hack to work around python readline changes. BZ 448864

Nick Jacek njacek at redhat.com
Thu Aug 4 21:00:05 UTC 2011


This is a modification of a patch geppetto posted a while ago, see
http://lists.baseurl.org/pipermail/yum-devel/2010-September/007495.htm
The changes from that patch are: changing __builtin__.raw_input so
that _sick_hack_raw_input is used when raw_input is called from other
modules; calling to_utf8 on the prompt to raw_input, so that non-ascii
prompts don't break anything; and finally resetting sys.stdout fewer
times, to be simpler.  I've tested the shell quite a bit using a
Japanese locale so that lots of unicode characters are printed, I
don't speak Japanese, so it might be outputting nonsense, but as far
as I can tell everything works as it should.
---
 shell.py |   33 ++++++++++++++++++++++++++++++---
 1 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/shell.py b/shell.py
index 636f12c..34a492e 100644
--- a/shell.py
+++ b/shell.py
@@ -23,10 +23,11 @@ import cmd
 import shlex
 import logging
 
-from yum import Errors
+from yum import Errors, _
 from yum.constants import *
 import yum.logginglevels as logginglevels
-
+from yum.i18n import to_utf8
+import __builtin__
 
 class YumShell(cmd.Cmd):
     """A class to implement an interactive yum shell."""
@@ -72,7 +73,33 @@ class YumShell(cmd.Cmd):
                 raise Errors.YumBaseError, "Fatal error in script, exiting"
         
         return inputs
-        
+
+    def cmdloop(self, *args, **kwargs):
+        """ Sick hack for readline. """
+
+        oraw_input = raw_input
+        owriter    = sys.stdout
+        _ostdout   = owriter.stream
+
+        def _sick_hack_raw_input(prompt):
+            sys.stdout = _ostdout
+            rret = oraw_input(to_utf8(prompt))
+            sys.stdout = owriter
+
+            return rret
+
+        __builtin__.raw_input = _sick_hack_raw_input
+
+        try:
+            cret = cmd.Cmd.cmdloop(self, *args, **kwargs)
+        except:
+            __builtin__.raw_input  = oraw_input
+            raise
+
+        __builtin__.raw_input = oraw_input
+
+        return cret
+
     def script(self):
         """Execute a script file in the yum shell.  The location of
         the script file is supplied by the :class:`cli.YumBaseCli`
-- 
1.7.5.4



More information about the Yum-devel mailing list