unset None fields, if allowed
[plcapi.git] / PLC / Parameter.py
1 #
2 # Shared type definitions
3 #
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
6 #
7 # $Id: Parameter.py,v 1.4 2006/10/25 14:27:12 mlhuang Exp $
8 #
9
10 class Parameter:
11     """
12     Typed value wrapper. Use in accepts and returns to document method
13     parameters. Set the optional and default attributes for
14     sub-parameters (i.e., dict fields).
15     """
16
17     def __init__(self, type, doc = "",
18                  min = None, max = None,
19                  optional = None,
20                  ro = False,
21                  nullok = False):
22         # Basic type of the parameter. May be a builtin type or Mixed.
23         self.type = type
24
25         # Documentation string for the parameter
26         self.doc = doc
27
28         # Basic value checking. For numeric types, the minimum and
29         # maximum possible values, inclusive. For string types, the
30         # minimum and maximum possible UTF-8 encoded byte lengths.
31         self.min = min
32         self.max = max
33
34         # Whether the sub-parameter is optional or not. If None,
35         # unknown whether it is optional.
36         self.optional = optional
37
38         # Whether the DB field is read-only.
39         self.ro = ro
40
41         # Whether the DB field can be NULL.
42         self.nullok = nullok
43
44     def __repr__(self):
45         return repr(self.type)
46
47 class Mixed(tuple):
48     """
49     A list (technically, a tuple) of types. Use in accepts and returns
50     to document method parameters that may return mixed types.
51     """
52
53     def __new__(cls, *types):
54         return tuple.__new__(cls, types)