On 15 August 2012 11:33, Daniel P. Berrange <berra...@redhat.com> wrote:
>  class QMPShell(qmp.QEMUMonitorProtocol):
> -    def __init__(self, address):
> +    def __init__(self, address, pp=None):
>          qmp.QEMUMonitorProtocol.__init__(self, self.__get_address(address))
>          self._greeting = None
>          self._completer = None
> +        self._pp = pp
>
>      def __get_address(self, arg):
>          """
> @@ -114,7 +116,11 @@ class QMPShell(qmp.QEMUMonitorProtocol):
>          if resp is None:
>              print 'Disconnected'
>              return False
> -        print resp
> +
> +        if self._pp is not None:
> +            self._pp.pprint(resp)
> +        else:
> +            print resp

If not pretty printing, you could initialise self._pp to a dummy object
with a pprint method that just does "print", which would let you avoid
the conditional here and just always do "self._pp.pprint(resp)".

Dunno whether that's worth the effort -- probably depends whether
there are likely to be other places in the code in future that want
to pretty-print an object.

-- PMM

Reply via email to