~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/service.py

  • Committer: Curtis Hovey
  • Date: 2012-03-17 23:01:16 UTC
  • Revision ID: curtis.hovey@canonical.com-20120317230116-vjf7ztzwg0asr2x0
Use wsgiref.headers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
from signal import SIGKILL
11
11
import simplejson
12
12
import sys
 
13
from wsgiref.headers import Headers
13
14
from wsgiref.simple_server import make_server
14
15
from wsgiref.util import shift_path_info
 
16
 
15
17
from grackle.store import (
16
18
    MemoryStore,
17
19
    )
27
29
    def __call__(self, environ, start_response):
28
30
        self.environ = environ
29
31
        self.start_response = start_response
 
32
        self.headers = Headers([('content-type', 'application/json')])
30
33
        self.method = environ['REQUEST_METHOD']
31
34
        if '://' in environ['PATH_INFO']:
32
35
            # All the needed information is embedded in PATH_INFO.
57
60
            return self.do_GET()
58
61
        return self.send_response(httplib.METHOD_NOT_ALLOWED)
59
62
 
60
 
    def send_response(self, code, response='', reason=None, headers={}):
 
63
    def send_response(self, code, response='', reason=None):
61
64
        """Set the status code and reason, then return the response."""
62
65
        if reason is None:
63
66
            reason = httplib.responses[code]
64
67
        response_status = '%s %s' % (code, reason)
65
 
        response_headers = {'content-type': 'application/json'}
66
 
        response_headers.update(headers.items())
67
 
        self.start_response(response_status, response_headers.items())
 
68
        self.start_response(response_status, self.headers.items())
68
69
        return [response]
69
70
 
70
71
    def do_PUT(self):