X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FPCUProtocolTypes.py;h=9281c46af07157afdcbaf437c3994500c427d23b;hb=HEAD;hp=9475d314631578f0531348dd66e80130a3e82e92;hpb=b7acbd2d6232f77f6a682b1966acd37e61b9b7b3;p=plcapi.git diff --git a/PLC/PCUProtocolTypes.py b/PLC/PCUProtocolTypes.py index 9475d31..9281c46 100644 --- a/PLC/PCUProtocolTypes.py +++ b/PLC/PCUProtocolTypes.py @@ -4,8 +4,6 @@ # Mark Huang # 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)