Hello,

this patch for recursive_print() in common.py fixes printing dicts with 
py3. It also replaced the tabs() lambda function with a plain string, 
and the brace() lambda function with a simple formatstring to make the 
code easier to understand.


=== modified file 'utils/apparmor/common.py'
--- utils/apparmor/common.py    2014-10-14 10:54:39 +0000
+++ utils/apparmor/common.py    2014-11-10 23:34:07 +0000
@@ -75,33 +84,31 @@
     # print recursively in a nicely formatted way
     # useful for debugging, too verbose for production code ;-)
 
-    # "stolen" from 
http://code.activestate.com/recipes/578094-recursively-print-nested-dictionaries/
-    # by Scott S-Allen / MIT License
-    # (output format slightly modified)
+    # based on code "stolen" from Scott S-Allen / MIT License
+    # 
http://code.activestate.com/recipes/578094-recursively-print-nested-dictionaries/
     """ Recursively prints nested elements."""
-    tabs = lambda n: ' ' * n * 4  # or 2 or 8 or...
-    brace = lambda s, n: '[%s]' % (s)
+    tabs = ' ' * dpth * 4  # or 2 or 8 or...
 
     if isinstance(src, dict):
         empty = True
-        for key, value in src.iteritems():
-            print (tabs(dpth) + brace(key, dpth))
-            recursive_print(value, dpth + 1, key)
+        for key in src.keys():
+            print (tabs + '[%s]' % key)
+            recursive_print(src[key], dpth + 1, key)
             empty = False
         if empty:
-            print (tabs(dpth) + '[--- empty ---]')
+            print (tabs + '[--- empty ---]')
     elif isinstance(src, list) or isinstance(src, tuple):
         empty = True
         for litem in src:
             recursive_print(litem, dpth + 2)
             empty = False
         if empty:
-            print (tabs(dpth) + '[--- empty ---]')
+            print (tabs + '[--- empty ---]')
     else:
         if key:
-            print (tabs(dpth) + '%s = %s' % (key, src))
+            print (tabs + '%s = %s' % (key, src))
         else:
-            print (tabs(dpth) + '- %s' % src)
+            print (tabs + '- %s' % src)
 
 def cmd(command):
     '''Try to execute the given command.'''



Regards,

Christian Boltz
-- 
[PHP] Das Problem ist, daß ich auf den stinkenden Haufen oben drauf
kacken kann, oder die Scheiße von Jahrhunderten fachgerecht entfernen.
Entscheidungen, Entscheidungen, ...
[Kristian Köhntopp auf http://vvv.koehntopp.de/wpkris/?p=738204]


-- 
AppArmor mailing list
AppArmor@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to