Skip to contentSkip to conversation

py: nftables.py: fix python3

PATCH In review Shekhar Sharma 2 participants 3 messages May 24, 2019 – May 28, 2019 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 py: nftables.py: fix python3

This patch converts the 'nftables.py' file (nftables/py/nftables.py) to run on both python2 and python3.

---
 py/nftables.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
py/nftables.py +1 -1
index 33cd2dfd..badcfa5c 100644
@@ -297,7 +297,7 @@ class Nftables:
         val = self.nft_ctx_output_get_debug(self.__ctx)
 
         names = []
-        for n,v in self.debug_flags.items():
+        for n,v in list(self.debug_flags.items()):
             if val & v:
                 names.append(n)
                 val &= ~v
Signature · 1 line
2.21.0.windows.1
#1 lore raw
Quoted 13 lines · Shekhar Sharma

This patch converts the 'nftables.py' file (nftables/py/nftables.py) to run on both python2 and python3.

---
 py/nftables.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
py/nftables.py +0 -0
index 33cd2dfd..badcfa5c 100644

py/nftables.py class Nftables: · line 303

Quoted 8 lines
py/nftables.py +1 -1
@@ -297,7 +297,7 @@ class Nftables:
         val = self.nft_ctx_output_get_debug(self.__ctx)
 
         names = []
-        for n,v in self.debug_flags.items():
+        for n,v in list(self.debug_flags.items()):
             if val & v:
                 names.append(n)
                 val &= ~v

Are you fixing an issue here? I don't think the conversion to list is necessary. The dictionary view can still be iterated. The dictionary is not being modified.

#2 lore raw
Quoted 17 lines · Eric Garver
Quoted 15 lines · Shekhar Sharma

This patch converts the 'nftables.py' file (nftables/py/nftables.py) to run on both python2 and python3.

---
 py/nftables.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
py/nftables.py +0 -0
index 33cd2dfd..badcfa5c 100644
@@ -297,7 +297,7 @@ class Nftables:
         val = self.nft_ctx_output_get_debug(self.__ctx)
 
Quoted 10 lines

py/nftables.py class Nftables: · line 303

Quoted 6 lines
py/nftables.py +1 -1
         names = []
-        for n,v in self.debug_flags.items():
+        for n,v in list(self.debug_flags.items()):
             if val & v:
                 names.append(n)
                 val &= ~v

Are you fixing an issue here? I don't think the conversion to list is necessary. The dictionary view can still be iterated. The dictionary is not being modified.

Yes, when i compiled the code with python3 in my computer, it ran without the conversion to list
but when i used an online compiler, it complained about it and i read online that methods like .items and .keys()
do not return iterables in python3 as they do in python2. I think the conversion is not necessary. We can omit it.

Shekhar