Setting tag plcapi-5.4-2
[plcapi.git] / PLC / PCUProtocolTypes.py
index 9475d31..9281c46 100644 (file)
@@ -4,8 +4,6 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: 
-#
 
 from PLC.Faults import *
 from PLC.Parameter import Parameter
@@ -22,27 +20,27 @@ class PCUProtocolType(Row):
     primary_key = 'pcu_protocol_type_id'
     join_tables = []
     fields = {
-       'pcu_protocol_type_id': Parameter(int, "PCU protocol type identifier"),
-       'pcu_type_id': Parameter(int, "PCU type identifier"), 
-       'port': Parameter(int, "PCU port"),
-       'protocol': Parameter(str, "Protocol"),
-       'supported': Parameter(bool, "Is the port/protocol supported by PLC") 
+        'pcu_protocol_type_id': Parameter(int, "PCU protocol type identifier"),
+        'pcu_type_id': Parameter(int, "PCU type identifier"),
+        'port': Parameter(int, "PCU port"),
+        'protocol': Parameter(str, "Protocol"),
+        'supported': Parameter(bool, "Is the port/protocol supported by PLC")
         }
 
     def validate_port(self, port):
-       # make sure port is not blank
-       
-       if not port:
+        # make sure port is not blank
+
+        if not port:
             raise PLCInvalidArgument, "Port must be specified"
-       
-       return port
+
+        return port
 
     def validate_protocol(self, protocol):
         # make sure port is not blank
         if not len(protocol):
             raise PLCInvalidArgument, "protocol must be specified"
 
-       return protocol
+        return protocol
 
 class PCUProtocolTypes(Table):
     """
@@ -54,22 +52,16 @@ class PCUProtocolTypes(Table):
 
         sql = "SELECT %s FROM pcu_protocol_type WHERE True" % \
               ", ".join(self.columns)
-        
-       if protocol_type_filter is not None:
-            if isinstance(protocol_type_filter, (list, tuple, set)):
-                # Separate the list into integers and strings
-                ints = filter(lambda x: isinstance(x, (int, long)), protocol_type_filter)
-                protocol_type_filter = Filter(PCUProtocolType.fields, {'pcu_protocol_type_id': ints})
+
+        if protocol_type_filter is not None:
+            if isinstance(protocol_type_filter, (list, tuple, set, int, long)):
+                protocol_type_filter = Filter(PCUProtocolType.fields, {'pcu_protocol_type_id': protocol_type_filter})
                 sql += " AND (%s) %s" % protocol_type_filter.sql(api, "OR")
             elif isinstance(protocol_type_filter, dict):
                 protocol_type_filter = Filter(PCUProtocolType.fields, protocol_type_filter)
-                sql += " AND (%s) %s" % protocol_type_filter.sql(api, "AND")
-            elif isinstance (protocol_type_filter, int):
-                protocol_type_filter = Filter(PCUProtocolType.fields, {'pcu_protocol_type_id':[protocol_type_filter]})
-
                 sql += " AND (%s) %s" % protocol_type_filter.sql(api, "AND")
             else:
-                raise PLCInvalidArgument, "Wrong pcu_protocol_type filter %r"%protocol_type_filter     
+                raise PLCInvalidArgument, "Wrong pcu_protocol_type filter %r"%protocol_type_filter
 
 
         self.selectall(sql)