From 72376f779087a7c7dfdde80162e9b60c76e96448 Mon Sep 17 00:00:00 2001 From: Bob Farrell Date: Mon, 16 Jun 2008 22:37:01 +0100 Subject: [PATCH] scapy expecting file-like methods that don't exist scapy seems to have a bug in it in that it expects stdout to have a flush() method, which is not specified in the documentation for the sys module (it specifies that it requires only a write() method to be acceptable). So this is a hack to fix it, it's harmless though. --- bpython.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bpython.py b/bpython.py index 446e06e..31913bd 100644 --- a/bpython.py +++ b/bpython.py @@ -134,7 +134,7 @@ class Interpreter( code.InteractiveInterpreter ): map( self.write, [ "\x01y\x03%s" % i for i in l ] ) -class Repl: +class Repl( object ): """Implements the necessary guff for a Python-repl-alike interface The execution of the code entered and all that stuff was taken from the @@ -755,6 +755,20 @@ class Repl: self.echo( s ) self.s_hist.append( s.rstrip('\n') ) + def flush( self ): + """Olivier Grisel brought it to my attention that the scapy + module tries to call this method, since it makes assumptions + about stdout that may not necessarily be true. The docs for + sys.stdout say: + + "stdout and stderr needn't be built-in file objects: any + object is acceptable as long as it has a write() method + that takes a string argument." + + So I consider this to be a bug in scapy, and this is a hack + to fix it, unfortunately. I'm sure they're not the only ones.""" + pass + def echo( self, s, redraw=True ): """Parse and echo a formatted string with appropriate attributes. It uses the formatting method as defined in formatter.py to parse the srings. It won't update @@ -1071,7 +1085,7 @@ class Repl: if self.p_key() is None: return self.s -class Statusbar: +class Statusbar( object ): """This class provides the status bar at the bottom of the screen. It has message() and prompt() methods for user interactivity, as well as settext() and clear() methods for changing its appearance.