Re: [PATCH nft v2]tests: json_echo: convert to py3

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

 



On Wed, May 29, 2019 at 1:19 PM Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> wrote:
>
> On Tue, May 28, 2019 at 06:06:53AM +0530, Shekhar Sharma wrote:
> > diff --git a/tests/json_echo/run-test.py b/tests/json_echo/run-test.py
> > index 0132b139..dd7797fb 100755
> > --- a/tests/json_echo/run-test.py
> > +++ b/tests/json_echo/run-test.py
> > @@ -1,5 +1,6 @@
> > -#!/usr/bin/python2
> > +#!/usr/bin/python
> >
> > +from __future__ import print_function
> >  import sys
> >  import os
> >  import json
> > @@ -13,8 +14,8 @@ from nftables import Nftables
> >  os.chdir(TESTS_PATH + "/../..")
> >
> >  if not os.path.exists('src/.libs/libnftables.so'):
> > -    print "The nftables library does not exist. " \
> > -          "You need to build the project."
> > +    print("The nftables library does not exist. "
> > +          "You need to build the project.")
> >      sys.exit(1)
> >
> >  nftables = Nftables(sofile = 'src/.libs/libnftables.so')
> > @@ -79,26 +80,26 @@ add_quota = { "add": {
> >  # helper functions
> >
> >  def exit_err(msg):
> > -    print "Error: %s" % msg
> > +    print("Error: %s" %msg)
> >      sys.exit(1)
> >
> >  def exit_dump(e, obj):
> > -    print "FAIL: %s" % e
> > -    print "Output was:"
> > +    print("FAIL: {}".format(e))
> > +    print("Output was:")
> >      json.dumps(out, sort_keys = True, indent = 4, separators = (',', ': '))
> >      sys.exit(1)
> >
> >  def do_flush():
> >      rc, out, err = nftables.json_cmd({ "nftables": [flush_ruleset] })
> >      if not rc is 0:
> > -        exit_err("flush ruleset failed: %s" % err)
> > +        exit_err("flush ruleset failed: {}".format(err))
> >
> >  def do_command(cmd):
> >      if not type(cmd) is list:
> >          cmd = [cmd]
> >      rc, out, err = nftables.json_cmd({ "nftables": cmd })
> >      if not rc is 0:
> > -        exit_err("command failed: %s" % err)
> > +        exit_err("command failed: {}".format(err))
> >      return out
> >
> >  def do_list_ruleset():
> > @@ -123,7 +124,7 @@ def get_handle(output, search):
> >              if not k in data:
> >                  continue
> >              found = True
> > -            for key in search[k].keys():
> > +            for key in list(search[k].keys()):
>
> list() is not necessary, as Eric already mentioned, right?
>
> Your patch is already in git.netfilter.org, so I have already pushed
> it out BTW. If this is the case, just avoid this in your follow up
> patches for other existing scripts. Thanks.

Sure, I will change it in the follow up patches.

Thanks!
Shekhar



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

  Powered by Linux