qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 3/4] tracetool: avoid str.rpartition() Python 2.


From: Lluís Vilanova
Subject: Re: [Qemu-devel] [PATCH 3/4] tracetool: avoid str.rpartition() Python 2.5 function
Date: Fri, 27 Apr 2012 19:47:12 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

Stefan Hajnoczi writes:

> The str.rpartition() function is related to str.split() and is used for
> splitting strings.  It was introduced in Python 2.5 and therefore cannot
> be used in tracetool as Python 2.4 compatibility is required.

> Replace the code using str.rsplit().

> Signed-off-by: Stefan Hajnoczi <address@hidden>

Reviewed-by: Lluís Vilanova <address@hidden>


> ---
>  scripts/tracetool/__init__.py |   17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)

> diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
> index 49858c9..175df08 100644
> --- a/scripts/tracetool/__init__.py
> +++ b/scripts/tracetool/__init__.py
> @@ -64,14 +64,17 @@ class Arguments:
>          res = []
>          for arg in arg_str.split(","):
>              arg = arg.strip()
> -            parts = arg.split()
> -            head, sep, tail = parts[-1].rpartition("*")
> -            parts = parts[:-1]
> -            if tail == "void":
> -                assert len(parts) == 0 and sep == ""
> +            if arg == 'void':
>                  continue
> -            arg_type = " ".join(parts + [ " ".join([head, sep]).strip() 
> ]).strip()
> -            res.append((arg_type, tail))
> +
> +            if '*' in arg:
> +                arg_type, identifier = arg.rsplit('*', 1)
> +                arg_type += '*'
> +                identifier = identifier.strip()
> +            else:
> +                arg_type, identifier = arg.rsplit(None, 1)
> +
> +            res.append((arg_type, identifier))
>          return Arguments(res)
 
>      def __iter__(self):
> -- 
> 1.7.10


-- 
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth



reply via email to

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