~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/service.py

  • Committer: Curtis Hovey
  • Date: 2012-03-17 21:28:19 UTC
  • Revision ID: curtis.hovey@canonical.com-20120317212819-qb4izc3zxecemxso
Handle usupported URLS and methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
        return self.handle_request()
34
34
 
35
35
    def handle_request(self):
 
36
        """Select the method to handle the request and return a response."""
 
37
        if self.application != 'archive':
 
38
            return self.send_response(
 
39
                httplib.BAD_REQUEST, reason='Unsupported URL')
36
40
        if self.method == 'PUT':
37
41
            return self.do_PUT()
38
 
        if self.method == 'POST':
 
42
        elif self.method == 'POST':
39
43
            return self.do_POST()
40
 
        if self.method == 'GET':
 
44
        elif self.method == 'GET':
41
45
            return self.do_GET()
 
46
        return self.send_response(
 
47
            httplib.BAD_REQUEST, reason='Unsupported method')
42
48
 
43
49
    def send_response(self, code, response='', reason=None, headers={}):
 
50
        """Set the status code and reason, then return the response."""
44
51
        if reason is None:
45
52
            reason = httplib.responses[code]
46
53
        response_code = '%s %s' % (code, reason)