On 05/03/2019 16:42, Wei Liu wrote:
> All scripts are transformed by 2to3.
>
> The only addition is "from __future__ import print_function" so that
> print("BLAH", file=sys.stderr) can work.
>
> https://python-future.org/compatible_idioms.html
>
> Tested with 2.7 and 3.5.
>
> Signed-off-by: Wei Liu <wei.l...@citrix.com>
> ---
> I don't have environment to test 2.4 -- it is almost 15 years old. We
> may want to consider bumping the minimum requirement to 2.7?

The compatible way to do this is  sys.stderr.write(msg + "\n") and using
print() without the future import.

> @@ -269,7 +271,7 @@ class KeyedUnion(Aggregate):
>          if not isinstance(keyvar_type, Enumeration):
>              raise ValueError
>  
> -        kv_kwargs = dict([(x.lstrip('keyvar_'),y) for (x,y) in 
> kwargs.items() if x.startswith('keyvar_')])
> +        kv_kwargs = dict([(x.lstrip('keyvar_'),y) for (x,y) in 
> list(kwargs.items()) if x.startswith('keyvar_')])

This shouldn't need changing.  List comprehensions are one of the few
uses of .items() which is compatible with older versions of python IIRC.

> @@ -362,11 +364,10 @@ def parse(f):
>              globs[n] = t
>  
>      try:
> -        execfile(f, globs, locs)
> -    except SyntaxError,e:
> -        raise SyntaxError, \
> -              "Errors were found at line %d while processing %s:\n\t%s"\
> -              %(e.lineno,f,e.text)
> +        exec(compile(open(f).read(), f, 'exec'), globs, locs)
> +    except SyntaxError as e:

This is the only really awkward bit, and isn't Py 2.4 compatible.

The only option here to retain pre 2.6 compatibility is:

try:
    ...
except SyntaxError:
    _, e = sys.exc_info()[:2]
    ...

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reply via email to