python3 - 2to3 + miscell obvious tweaks
[sfa.git] / sfatables / commands / moo.py
index a882854..3860e3c 100644 (file)
@@ -1,5 +1,7 @@
 import os, time
 
+from sfa.util.py23 import StringType
+
 class Command:
     commandline_options = []
     help = "Add a new rule"
@@ -57,7 +59,7 @@ class Command:
 
             # Indent struct fields and mixed types
             if isinstance(param, dict):
-                for name, subparam in param.iteritems():
+                for name, subparam in param.items():
                     text += param_text(name, subparam, indent + step, step)
             elif isinstance(param, Mixed):
                 for subparam in param:
@@ -90,8 +92,8 @@ class Command:
         """
         
         # Inspect call. Remove self from the argument list.
-        max_args = self.call.func_code.co_varnames[1:self.call.func_code.co_argcount]
-        defaults = self.call.func_defaults
+        max_args = self.call.__code__.co_varnames[1:self.call.__code__.co_argcount]
+        defaults = self.call.__defaults__
         if defaults is None:
             defaults = ()
 
@@ -152,7 +154,7 @@ class Command:
 
         # Strings are a special case. Accept either unicode or str
         # types if a string is expected.
-        if expected_type in StringTypes and isinstance(value, StringTypes):
+        if issubclass(expected_type, StringType) and isinstance(value, StringType):
             pass
 
         # Integers and long integers are also special types. Accept
@@ -167,7 +169,7 @@ class Command:
                                      name)
 
         # If a minimum or maximum (length, value) has been specified
-        if expected_type in StringTypes:
+        if issubclass(expected_type, StringType):
             if min is not None and \
                len(value.encode(self.api.encoding)) < min:
                 raise SfaInvalidArgument("%s must be at least %d bytes long" % (name, min))
@@ -197,13 +199,13 @@ class Command:
         # If a struct with particular (or required) types of items is
         # expected.
         elif isinstance(expected, dict):
-            for key in value.keys():
+            for key in list(value.keys()):
                 if key in expected:
                     self.type_check(name + "['%s']" % key, value[key], expected[key], args)
-            for key, subparam in expected.iteritems():
+            for key, subparam in expected.items():
                 if isinstance(subparam, Parameter) and \
                    subparam.optional is not None and \
-                   not subparam.optional and key not in value.keys():
+                   not subparam.optional and key not in list(value.keys()):
                     raise SfaInvalidArgument("'%s' not specified" % key, name)
 
         #if auth is not None: