3
from txaws.version import ec2_api as ec2_api_version
4
from txaws.server.exception import APIError
8
"""Hold information about a single API call initiated by an HTTP request.
10
@param raw_params: The raw parameters for the action to be executed, the
11
format is a dictionary mapping parameter names to parameter values,
12
like C{{'ParamName': param_value}}.
13
@param principal: The principal issuing this API L{Call}.
14
@param action: The action to be performed.
16
@ivar id: A unique identifier for the API call.
17
@ivar principal: The principal performing the call.
18
@ivar args: An L{Arguments} object holding parameters extracted from the
19
raw parameters according to a L{Schema}, it will be available after
20
calling the C{parse} method.
21
@ivar rest: Extra parameters not included in the given arguments schema,
22
it will be available after calling the L{parse} method.
23
@ivar version: The version of the API call. Defaults to 2009-11-30.
26
def __init__(self, raw_params=None, principal=None, action=None,
27
version=None, id=None):
32
if raw_params is not None:
33
self._raw_params.update(raw_params)
36
version = ec2_api_version
37
self.version = version
38
self.principal = principal
40
def parse(self, schema, strict=True):
41
"""Update C{args} and C{rest}, parsing the raw request arguments.
43
@param schema: The L{Schema} the parameters must be extracted with.
44
@param strict: If C{True} an error is raised if parameters not included
45
in the schema are found, otherwise the extra parameters will be
46
saved in the C{rest} attribute.
48
self.args, self.rest = schema.extract(self._raw_params)
49
if strict and self.rest:
50
raise APIError(400, "UnknownParameter",
51
"The parameter %s is not "
52
"recognized" % self.rest.keys()[0])
54
def get_raw_params(self):
55
"""Return a C{dict} holding the raw API call paramaters.
57
The format of the dictionary is C{{'ParamName': param_value}}.
59
return self._raw_params.copy()