Revision b166ef84 lib/rapi/baserlib.py
b/lib/rapi/baserlib.py | ||
---|---|---|
170 | 170 |
return result |
171 | 171 |
|
172 | 172 |
|
173 |
def FillOpcode(opcls, body, static): |
|
173 |
def FillOpcode(opcls, body, static, rename=None):
|
|
174 | 174 |
"""Fills an opcode with body parameters. |
175 | 175 |
|
176 | 176 |
Parameter types are checked. |
... | ... | |
181 | 181 |
@param body: Body parameters as received from client |
182 | 182 |
@type static: dict |
183 | 183 |
@param static: Static parameters which can't be modified by client |
184 |
@type rename: dict |
|
185 |
@param rename: Renamed parameters, key as old name, value as new name |
|
184 | 186 |
@return: Opcode object |
185 | 187 |
|
186 | 188 |
""" |
187 | 189 |
CheckType(body, dict, "Body contents") |
188 | 190 |
|
191 |
# Make copy to be modified |
|
192 |
params = body.copy() |
|
193 |
|
|
194 |
if rename: |
|
195 |
for old, new in rename.items(): |
|
196 |
if new in params and old in params: |
|
197 |
raise http.HttpBadRequest("Parameter '%s' was renamed to '%s', but" |
|
198 |
" both are specified" % |
|
199 |
(old, new)) |
|
200 |
if old in params: |
|
201 |
assert new not in params |
|
202 |
params[new] = params.pop(old) |
|
203 |
|
|
189 | 204 |
if static: |
190 |
overwritten = set(body.keys()) & set(static.keys())
|
|
205 |
overwritten = set(params.keys()) & set(static.keys())
|
|
191 | 206 |
if overwritten: |
192 | 207 |
raise http.HttpBadRequest("Can't overwrite static parameters %r" % |
193 | 208 |
overwritten) |
194 | 209 |
|
195 |
# Combine parameters |
|
196 |
params = body.copy() |
|
197 |
|
|
198 |
if static: |
|
199 | 210 |
params.update(static) |
200 | 211 |
|
201 | 212 |
# Convert keys to strings (simplejson decodes them as unicode) |
Also available in: Unified diff