~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/base/rest.py

Move the remaining images to the new framework, in the new ivle.webapp.core
plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
            setattr(self, key, kwargs[key])
38
38
 
39
39
    def render(self, req):
40
 
        if req.method == 'GET':
41
 
            outstr = self.GET(req)
42
 
        # XXX PATCH hack
43
 
        if req.method == 'PUT':
44
 
            outstr = self.PATCH(req, req.read())
45
 
        req.content_type = self.content_type
46
 
        req.write(outstr)
 
40
        raise NotImplementedError()
47
41
 
48
42
class JSONRESTView(RESTView):
49
43
    """
66
60
        elif req.method == 'PATCH' or (req.method == 'PUT' and
67
61
              'X-IVLE-Patch-Semantics' in req.headers_in and
68
62
              req.headers_in['X-IVLE-Patch-Semantics'].lower() == 'yes'):
69
 
            outjson = self.PATCH(req, cjson.decode(req.read()))
 
63
            try:
 
64
                input = cjson.decode(req.read())
 
65
            except cjson.DecodeError:
 
66
                raise BadRequest('Invalid JSON data')
 
67
            outjson = self.PATCH(req, input)
70
68
        elif req.method == 'PUT':
71
 
            outjson = self.PUT(req, cjson.decode(req.read()))
 
69
            try:
 
70
                input = cjson.decode(req.read())
 
71
            except cjson.DecodeError:
 
72
                raise BadRequest('Invalid JSON data')
 
73
            outjson = self.PUT(req, input)
72
74
        # POST implies named operation.
73
75
        elif req.method == 'POST':
74
76
            # TODO: Check Content-Type and implement multipart/form-data.
98
100
            # we are OK.
99
101
            unspec = set(args) - set(opargs.keys())
100
102
            if unspec and not defaults:
101
 
                raise BadRequest('Missing arguments: ' + ','.join(unspec))
 
103
                raise BadRequest('Missing arguments: ' + ', '.join(unspec))
102
104
 
103
105
            unspec = [k for k in unspec if k not in args[-len(defaults):]]
104
106
 
105
107
            if unspec:
106
 
                raise BadRequest('Missing arguments: ' + ','.join(unspec))
 
108
                raise BadRequest('Missing arguments: ' + ', '.join(unspec))
107
109
 
108
110
            # We have extra arguments if the are no match args in the function
109
111
            # signature, AND there is no **.
112
114
                raise BadRequest('Extra arguments: ' + ', '.join(extra))
113
115
 
114
116
            outjson = op(req, **opargs)
115
 
        else:
116
 
            raise AssertionError('Unknown method somehow got through.')
117
117
 
118
118
        req.content_type = self.content_type
119
119
        if outjson is not None: