|
13 | 13 | from urlparse import urlparse |
14 | 14 | import os |
15 | 15 | import json |
16 | | -import pprint |
17 | 16 | import sys |
18 | 17 | import time |
19 | 18 | import traceback |
20 | 19 | import re |
21 | 20 |
|
22 | 21 | try: |
23 | 22 | # if dicttoxml installed in roundup directory, use it |
24 | | - from .dicttoxml import dicttoxml |
| 23 | + from roundup.dicttoxml import dicttoxml |
25 | 24 | except ImportError: |
26 | 25 | try: |
27 | 26 | # else look in sys.path |
|
58 | 57 | else: |
59 | 58 | logger.warning("**SystemRandom not available. Using poor random generator") |
60 | 59 |
|
61 | | -import time |
62 | | - |
63 | 60 | chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' |
64 | 61 |
|
65 | 62 | def _data_decorator(func): |
@@ -183,7 +180,7 @@ def obtain_etags(headers,input): |
183 | 180 | '''Get ETags value from headers or payload data''' |
184 | 181 | etags = [] |
185 | 182 | if '@etag' in input: |
186 | | - etags.append(input['@etag'].value); |
| 183 | + etags.append(input['@etag'].value) |
187 | 184 | etags.append(headers.get("If-Match", None)) |
188 | 185 | return etags |
189 | 186 |
|
@@ -228,10 +225,10 @@ def parse_accept_header(accept): |
228 | 225 | if len(rest): |
229 | 226 | # add the version as a media param |
230 | 227 | try: |
231 | | - version = media_params.append(('version', |
| 228 | + media_params.append(('version', |
232 | 229 | rest)) |
233 | 230 | except ValueError: |
234 | | - version = 1.0 # could not be parsed |
| 231 | + pass # return no version value; use rest default |
235 | 232 | # add the vendor code as a media param |
236 | 233 | media_params.append(('vendor', vnd)) |
237 | 234 | # and re-write media_type to something like application/json so |
@@ -540,6 +537,9 @@ def format_item(self, node, item_id, props=None, verbose=1): |
540 | 537 | else: |
541 | 538 | version = self.api_version |
542 | 539 |
|
| 540 | + # version never gets used since we only |
| 541 | + # support version 1 at this time. Set it as |
| 542 | + # placeholder for later use. |
543 | 543 | result = {} |
544 | 544 | try: |
545 | 545 | # pn = propname |
@@ -781,7 +781,6 @@ def get_element(self, class_name, item_id, input): |
781 | 781 | raise UsageError ("Field %s is not key property"%k) |
782 | 782 | except ValueError: |
783 | 783 | v = item_id |
784 | | - pass |
785 | 784 | if not self.db.security.hasPermission( |
786 | 785 | 'View', uid, class_name, itemid=item_id, property=keyprop |
787 | 786 | ): |
@@ -1173,6 +1172,9 @@ def delete_collection(self, class_name, input): |
1173 | 1172 | count (int): number of deleted objects |
1174 | 1173 | """ |
1175 | 1174 | raise Unauthorised('Deletion of a whole class disabled') |
| 1175 | + ''' Hide original code to silence pylint. |
| 1176 | + Leave it here in case we need to re-enable. |
| 1177 | + FIXME: Delete in December 2020 if not used. |
1176 | 1178 | if class_name not in self.db.classes: |
1177 | 1179 | raise NotFound('Class %s not found' % class_name) |
1178 | 1180 | if not self.db.security.hasPermission( |
@@ -1200,6 +1202,7 @@ def delete_collection(self, class_name, input): |
1200 | 1202 | } |
1201 | 1203 |
|
1202 | 1204 | return 200, result |
| 1205 | + ''' |
1203 | 1206 |
|
1204 | 1207 | @Routing.route("/data/<:class_name>/<:item_id>", 'DELETE') |
1205 | 1208 | @_data_decorator |
@@ -1270,8 +1273,8 @@ def delete_attribute(self, class_name, item_id, attr_name, input): |
1270 | 1273 | raise UsageError("Attribute '%s' not valid for class %s."%( |
1271 | 1274 | attr_name, class_name)) |
1272 | 1275 | if attr_name in class_obj.get_required_props(): |
1273 | | - raise UsageError("Attribute '%s' is required by class %s and can not be deleted."%( |
1274 | | - attr_name, class_name)) |
| 1276 | + raise UsageError("Attribute '%s' is required by class %s and can not be deleted."%( |
| 1277 | + attr_name, class_name)) |
1275 | 1278 | props = {} |
1276 | 1279 | prop_obj = class_obj.get(item_id, attr_name) |
1277 | 1280 | if isinstance(prop_obj, list): |
@@ -1746,7 +1749,8 @@ def dispatch(self, method, uri, input): |
1746 | 1749 | self.api_version = int(part[1]['version']) |
1747 | 1750 | except KeyError: |
1748 | 1751 | self.api_version = None |
1749 | | - except ValueError: |
| 1752 | + except (ValueError, TypeError): |
| 1753 | + # TypeError if int(None) |
1750 | 1754 | msg=( "Unrecognized version: %s. " |
1751 | 1755 | "See /rest without specifying version " |
1752 | 1756 | "for supported versions."%( |
@@ -1830,7 +1834,7 @@ def dispatch(self, method, uri, input): |
1830 | 1834 | # Use default if not specified for now. |
1831 | 1835 | self.api_version = self.__default_api_version |
1832 | 1836 | elif self.api_version not in self.__supported_api_versions: |
1833 | | - raise UsageError(msg%self.api_version) |
| 1837 | + raise UsageError(msg%self.api_version) |
1834 | 1838 |
|
1835 | 1839 | # sadly del doesn't work on FieldStorage which can be the type of |
1836 | 1840 | # input. So we have to ignore keys starting with @ at other |
|
0 commit comments