more ironing in the corner of that 'types' modules
[plcapi.git] / PLC / Method.py
index 81a1747..836eea0 100644 (file)
@@ -4,23 +4,21 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-import xmlrpc.client
-from types import *
+#import xmlrpc.client
 import textwrap
-import os
 import time
 import pprint
 
 from PLC.Faults import *
 from PLC.Parameter import Parameter, Mixed, python_type, xmlrpc_type
 from PLC.Auth import Auth
-from PLC.Debug import profile
+#from PLC.Debug import profile
 from PLC.Events import Event, Events
 from PLC.Nodes import Node, Nodes
 from PLC.Persons import Person, Persons
 
 # we inherit object because we use new-style classes for legacy methods
-class Method (object):
+class Method:
     """
     Base class for all PLCAPI functions. At a minimum, all PLCAPI
     functions must define:
@@ -57,13 +55,13 @@ class Method (object):
 
         return True
 
-    def __init__(self, api,caller=None):
+    def __init__(self, api, caller=None):
         self.name = self.__class__.__name__
         self.api = api
 
         if caller:
             # let a method call another one by propagating its caller
-            self.caller=caller
+            self.caller = caller
         else:
             # Auth may set this to a Person instance (if an anonymous
             # method, will remain None).
@@ -84,7 +82,7 @@ class Method (object):
 
             # legacy code cannot be type-checked, due to the way Method.args() works
             # as of 5.0-rc16 we don't use skip_type_check anymore
-            if not hasattr(self,"skip_type_check"):
+            if not hasattr(self, "skip_type_check"):
                 (min_args, max_args, defaults) = self.args()
 
                 # Check that the right number of arguments were passed in
@@ -150,7 +148,8 @@ class Method (object):
                     continue
                 # what type of auth this is
                 if 'AuthMethod' in arg:
-                    auth_methods = ['session', 'password', 'capability', 'gpg', 'hmac','anonymous']
+                    auth_methods = ['session', 'password', 'capability',
+                                    'gpg', 'hmac', 'anonymous']
                     auth_method = arg['AuthMethod']
                     if auth_method in auth_methods:
                         event['auth_type'] = auth_method
@@ -171,12 +170,12 @@ class Method (object):
         elif isinstance(self.caller, Node):
             event['node_id'] = self.caller['node_id']
 
-        event.sync(commit = False)
+        event.sync(commit=False)
 
         if hasattr(self, 'event_objects') and isinstance(self.event_objects, dict):
-            for key in list(self.event_objects.keys()):
+            for key in self.event_objects.keys():
                 for object_id in self.event_objects[key]:
-                    event.add_object(key, object_id, commit = False)
+                    event.add_object(key, object_id, commit=False)
 
 
         # Set the message for this event
@@ -188,7 +187,7 @@ class Method (object):
         # Commit
         event.sync()
 
-    def help(self, indent = "  "):
+    def help(self, indent="  "):
         """
         Text documentation for the method.
         """
@@ -228,9 +227,10 @@ class Method (object):
 
             # Print parameter documentation right below type
             if isinstance(param, Parameter):
-                wrapper = textwrap.TextWrapper(width = 70,
-                                               initial_indent = " " * param_offset,
-                                               subsequent_indent = " " * param_offset)
+                wrapper = textwrap.TextWrapper(
+                    width=70,
+                    initial_indent=" " * param_offset,
+                    subsequent_indent = " " * param_offset)
                 text += "\n".join(wrapper.wrap(param.doc)) + "\n"
                 param = param.type
 
@@ -338,7 +338,7 @@ class Method (object):
 
         # Integers and long integers are also special types. Accept
         # either int or long types if an int or long is expected.
-        elif expected_type in (IntType, LongType) and isinstance(value, (IntType, LongType)):
+    elif expected_type is int and isinstance(value, int):
             pass
 
         elif not isinstance(value, expected_type):