qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] qmp: make qmp-shell work with python3


From: Igor Mammedov
Subject: Re: [Qemu-devel] [PATCH] qmp: make qmp-shell work with python3
Date: Thu, 20 Jun 2019 11:11:03 +0200

On Wed, 19 Jun 2019 09:29:24 -0400
Cleber Rosa <address@hidden> wrote:

> On Tue, Jun 18, 2019 at 10:29:31AM -0400, Igor Mammedov wrote:
> > python3 doesn't have raw_input(), so qmp-shell breaks.
> > Use input() instead and override it with raw_input()
> > if running on python2.
> > 
> > Signed-off-by: Igor Mammedov <address@hidden>
> > ---
> >  scripts/qmp/qmp-shell | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> > index 7776c7b141..8c49b39afa 100755
> > --- a/scripts/qmp/qmp-shell
> > +++ b/scripts/qmp/qmp-shell
> > @@ -308,7 +308,11 @@ class QMPShell(qmp.QEMUMonitorProtocol):
> >          @return True if execution was ok, return False if disconnected.
> >          """
> >          try:
> > -            cmdline = raw_input(prompt)
> > +            try: # attempt to set Python2 override
> > +               import __builtin__;
> > +               getattr(__builtin__, 'raw_input', input)
> > +            except ModuleNotFoundError: pass  
> 
> Something like:
> 
>    if sys.version_info[0] == 2:
>        input = raw_input
> 
> Also does the job, and may be considered simpler and easier to read.

that causes scope issues on python3

> 
> - Cleber.
> 
> > +            cmdline = input(prompt)
> >          except EOFError:
> >              print()
> >              return False
> > -- 
> > 2.18.1
> >   
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]