예제 #1
0
class JsonResource(resource.Resource):

    json_encoder = json.JSONEncoder()

    def render(self, txrequest):
        r = resource.Resource.render(self, txrequest)
        return self.render_object(r, txrequest)

    def render_object(self, obj, txrequest):
        r = self.json_encoder.encode(obj) + "\n"
        txrequest.setHeader('Content-Type', 'application/json')
        txrequest.setHeader('Content-Length', len(r))
        return r
예제 #2
0
 def __init__(self, file, **kwargs):
     self._configure(kwargs)
     self.file = file
     self.encoder = json.JSONEncoder(**kwargs)
     self.first_item = True