~unity-2d-team/unity-2d/Shell-MultiMonitor

« back to all changes in this revision

Viewing changes to grackle/client.py

  • Committer: Aaron Bentley
  • Date: 2012-01-11 08:06:03 UTC
  • mto: (6.1.30 trunk)
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: aaron@canonical.com-20120111080603-fxgo006hthzc89kq
check is PHONY

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import httplib
2
2
 
3
 
def put_message(archive_name, file_obj):
4
 
    connection = httplib.HTTPConnection('localhost', 8435)
5
 
    connection.request('POST', '/archive/%s' % archive_name, file_obj.read())
6
 
    response = connection.getresponse()
7
 
    data = response.read()
8
 
    if response.status == httplib.BAD_REQUEST:
9
 
        raise Exception('wtf')
10
 
    elif response.status == httplib.CREATED:
11
 
        return
12
 
    else:
13
 
        raise Exception('!!')
 
3
 
 
4
class GrackleClient:
 
5
 
 
6
    def __init__(self, host, port):
 
7
        self.host = host
 
8
        self.port = port
 
9
 
 
10
    def put_message(self, archive_name, permalink, file_obj):
 
11
        connection = httplib.HTTPConnection(self.host, self.port)
 
12
        connection.request('PUT', permalink, file_obj.read())
 
13
        response = connection.getresponse()
 
14
        data = response.read()
 
15
        if response.status == httplib.BAD_REQUEST:
 
16
            raise Exception('wtf')
 
17
        elif response.status == httplib.CREATED:
 
18
            return
 
19
        else:
 
20
            raise Exception('!!')