2 # Shared type definitions
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
8 from PLC.Faults import *
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).
17 def __init__(self, typeval, doc="",
22 # Basic type of the parameter. Must be a builtin type
23 # that can be marshalled by XML-RPC.
26 # Documentation string for the parameter
29 # Basic value checking. For numeric types, the minimum and
30 # maximum possible values, inclusive. For string types, the
31 # minimum and maximum possible UTF-8 encoded byte lengths.
35 # Whether the sub-parameter is optional or not. If None,
36 # unknown whether it is optional.
37 self.optional = optional
39 # Whether the DB field is read-only.
42 # Whether the DB field can be NULL.
49 return repr(self.type)
53 A list (technically, a tuple) of types. Use in accepts and returns
54 to document method parameters that may return mixed types.
57 def __new__(cls, *types):
58 return tuple.__new__(cls, types)
62 Returns the Python type of the specified argument, which may be a
63 Python type, a typed value, or a Parameter.
66 if isinstance(arg, Parameter):
69 if isinstance(arg, type):
76 Returns the XML-RPC type of the specified argument, which may be a
77 Python type, a typed value, or a Parameter.
80 arg_type = python_type(arg)
82 if arg_type is type(None):
86 elif arg_type is bool:
88 elif arg_type is float:
92 elif arg_type in (list, tuple):
94 elif arg_type is dict:
96 elif arg_type == Mixed:
97 # Not really an XML-RPC type but return "mixed" for
98 # documentation purposes.
101 raise PLCAPIError("XML-RPC cannot marshal %s objects" % arg_type)