Re: [PATCH nft] tests: py: fix python3.

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

 



Hi Shekhar,

Please use git-format-patch option "-v" next revision.

On Wed, May 15, 2019 at 11:13:54PM +0530, Shekhar Sharma wrote:
> This changes all the python2 files to python3.
> Signed-off-by: Shekhar Sharma <shekhar250198@xxxxxxxxx>
> ---
[..]
> diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
> index 1c0afd0e..35c5d0e5 100755
> --- a/tests/py/nft-test.py
> +++ b/tests/py/nft-test.py
> @@ -436,7 +436,7 @@ def set_delete(table, filename=None, lineno=None):
>      '''
>      Deletes set and its content.
>      '''
> -    for set_name in all_set.keys():
> +    for set_name in list(all_set.keys()):
>          # Check if exists the set
>          if not set_exist(set_name, table, filename, lineno):
>              reason = "The set %s does not exist, " \
> @@ -1002,9 +1002,9 @@ def execute_cmd(cmd, filename, lineno, stdout_log=False, debug=False):
>      :param debug: temporarily set these debug flags
>      '''
>      global log_file
> -    print >> log_file, "command: %s" % cmd
> +    print("command: %s" % cmd, file= log_file)

python2 throws a syntax error here.

    $ python2 -m py_compile tests/py/nft-test.py                                                                                                                                                                                            
      File "tests/py/nft-test.py", line 1005                                                                                                                                                                                                                                        
        print("command: %s" % cmd, file= log_file)

    SyntaxError: invalid syntax

I think you need to add this to the top of the file:

    from __future__ import print_function

>      if debug_option:
> -        print cmd
> +        print(cmd)
>  
>      if debug:
>          debug_old = nftables.get_debug()
[..]
> @@ -1353,15 +1353,15 @@ def main():
>      signal.signal(signal.SIGTERM, signal_handler)
>  
>      if os.getuid() != 0:
> -        print "You need to be root to run this, sorry"
> +        print("You need to be root to run this, sorry") 

nit: This adds a space at the end which git-am complains about.



[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux