|
11 | 11 | from roundup.exceptions import * |
12 | 12 | from roundup import xmlrpc |
13 | 13 |
|
| 14 | +def props_from_args(db, cl, args, itemid=None): |
| 15 | + props = {} |
| 16 | + for arg in args: |
| 17 | + try: |
| 18 | + key = arg.name |
| 19 | + value = arg.value |
| 20 | + except ValueError: |
| 21 | + raise UsageError('argument "%s" not propname=value' % arg) |
| 22 | + if isinstance(key, unicode): |
| 23 | + try: |
| 24 | + key = key.encode('ascii') |
| 25 | + except UnicodeEncodeError: |
| 26 | + raise UsageError('argument %r is no valid ascii keyword' % key) |
| 27 | + if isinstance(value, unicode): |
| 28 | + value = value.encode('utf-8') |
| 29 | + if value: |
| 30 | + try: |
| 31 | + props[key] = hyperdb.rawToHyperdb(db, cl, itemid, key, value) |
| 32 | + except hyperdb.HyperdbValueError: |
| 33 | + pass # pass if a parameter is not a property of the class |
| 34 | + else: |
| 35 | + props[key] = None |
| 36 | + |
| 37 | + return props |
14 | 38 |
|
15 | 39 | class RestfulInstance(object): |
16 | 40 | """Dummy Handler for REST |
@@ -58,8 +82,7 @@ def post_collection(self, class_name, input): |
58 | 82 | class_obj = self.db.getclass(class_name) |
59 | 83 |
|
60 | 84 | # convert types |
61 | | - input_data = ["%s=%s" % (item.name, item.value) for item in input.value] |
62 | | - props = xmlrpc.props_from_args(self.db, class_obj, input_data) |
| 85 | + props = props_from_args(self.db, class_obj, input.value) |
63 | 86 |
|
64 | 87 | # check for the key property |
65 | 88 | key = class_obj.getkey() |
@@ -91,8 +114,7 @@ def put_collection(self, class_name, input): |
91 | 114 | def put_element(self, class_name, item_id, input): |
92 | 115 | class_obj = self.db.getclass(class_name) |
93 | 116 |
|
94 | | - input_data = ["%s=%s" % (item.name, item.value) for item in input.value] |
95 | | - props = xmlrpc.props_from_args(self.db, class_obj, input_data, item_id) |
| 117 | + props = props_from_args(self.db, class_obj, input.value, item_id) |
96 | 118 | for p in props.iterkeys(): |
97 | 119 | if not self.db.security.hasPermission('Edit', self.db.getuid(), |
98 | 120 | class_name, p, item_id): |
|
0 commit comments