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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2010-07-28 04:12:08 UTC
  • mfrom: (1790.1.8 codemirror-srsly)
  • Revision ID: grantw@unimelb.edu.au-20100728041208-mciagtog1785oje4
Move from CodePress to CodeMirror. It's now an external dependency, too, so you'll need to install it yourself.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import os
24
24
import urlparse
25
25
 
26
 
try:
27
 
    import json
28
 
except ImportError:
29
 
    import simplejson as json
30
 
 
 
26
import cjson
31
27
import genshi.template
32
28
 
33
29
from ivle.webapp.base.views import BaseView
93
89
              req.headers_in['X-IVLE-Patch-Semantics'].lower() == 'yes'):
94
90
            self.authorize_method(req, self.PATCH)
95
91
            try:
96
 
                input = json.loads(req.read())
97
 
            except ValueError:
 
92
                input = cjson.decode(req.read())
 
93
            except cjson.DecodeError:
98
94
                raise BadRequest('Invalid JSON data')
99
95
            outjson = self.PATCH(req, input)
100
96
        elif req.method == 'PUT':
101
97
            self.authorize_method(req, self.PUT)
102
98
            try:
103
 
                input = json.loads(req.read())
104
 
            except ValueError:
 
99
                input = cjson.decode(req.read())
 
100
            except cjson.DecodeError:
105
101
                raise BadRequest('Invalid JSON data')
106
102
            outjson = self.PUT(req, input)
107
103
        # POST implies named operation.
117
113
    #This is a separate function to allow additional data to be passed through
118
114
    def write_json(self, req, outjson):
119
115
        if outjson is not None:
120
 
            req.write(json.dumps(outjson))
 
116
            req.write(cjson.encode(outjson))
121
117
            req.write("\n")
122
118
 
123
119
    def _named_operation(self, req, opargs, readonly=False):
189
185
    # This renders the template and adds it to the json
190
186
    def write_json(self, req, outjson):
191
187
        outjson["html"] = self.render_fragment()
192
 
        req.write(json.dumps(outjson))
 
188
        req.write(cjson.encode(outjson))
193
189
        req.write("\n")
194
190
 
195
191
class _named_operation(object):