2 # Shared type definitions
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
9 from PLC.Faults import *
13 Typed value wrapper. Use in accepts and returns to document method
14 parameters. Set the optional and default attributes for
15 sub-parameters (i.e., dict fields).
18 def __init__(self, typeval, doc = "",
19 min = None, max = None,
26 # Basic type of the parameter. Must be a builtin type
27 # that can be marshalled by XML-RPC.
30 # Documentation string for the parameter
33 # Basic value checking. For numeric types, the minimum and
34 # maximum possible values, inclusive. For string types, the
35 # minimum and maximum possible UTF-8 encoded byte lengths.
39 # Whether the sub-parameter is optional or not. If None,
40 # unknown whether it is optional.
41 self.optional = optional
43 # Whether the DB field is read-only.
46 # Whether the DB field can be NULL.
49 self.primary_key = primary_key
55 return repr(self.type)
59 A list (technically, a tuple) of types. Use in accepts and returns
60 to document method parameters that may return mixed types.
63 def __new__(cls, *types):
64 return tuple.__new__(cls, types)
68 Returns the Python type of the specified argument, which may be a
69 Python type, a typed value, or a Parameter.
72 if isinstance(arg, Parameter):
75 if isinstance(arg, type):
82 Returns the XML-RPC type of the specified argument, which may be a
83 Python type, a typed value, or a Parameter.
86 arg_type = python_type(arg)
88 if arg_type == NoneType:
90 elif arg_type == IntType or arg_type == LongType:
92 elif arg_type == bool:
94 elif arg_type == FloatType:
96 elif arg_type in StringTypes:
98 elif arg_type == ListType or arg_type == TupleType:
100 elif arg_type == DictType:
102 elif arg_type == Mixed:
103 # Not really an XML-RPC type but return "mixed" for
104 # documentation purposes.
107 raise PLCAPIError, "XML-RPC cannot marshal %s objects" % arg_type