16
16
self.netloc = '%s:%d' % (host, port)
18
def archive_url(self, archive_name, query):
19
path = '/%s' % quote(archive_name)
18
def archive_url(self, archive_id, query):
19
path = '/%s' % quote(archive_id)
20
20
query_string = urlencode(query)
21
21
return urlunparse(('http', self.netloc, path, '', query_string, ''))
23
23
def _get_connection(self):
24
24
return httplib.HTTPConnection(self.host, self.port)
26
def _verb_archive(self, verb, archive_name, query, body=None):
27
url = self.archive_url(archive_name, query)
26
def _verb_archive(self, verb, archive_id, query, body=None):
27
url = self.archive_url(archive_id, query)
28
28
connection = self._get_connection()
29
29
connection.request(verb, url, body)
30
30
return connection.getresponse()
32
def put_message(self, archive_name, key, file_obj):
32
def put_message(self, archive_id, key, file_obj):
33
33
response = self._verb_archive(
34
'POST', archive_name, {'key': key}, file_obj.read())
34
'POST', archive_id, {'key': key}, file_obj.read())
35
35
data = response.read()
36
36
if response.status == httplib.BAD_REQUEST:
37
37
raise Exception('wtf')
41
41
raise Exception('!!')
43
def get_messages(self, archive_name, message_ids=None):
43
def get_messages(self, archive_id, message_ids=None):
45
45
if message_ids is not None:
46
46
parameters['message_ids'] = message_ids
47
47
query = {'parameters': simplejson.dumps(parameters)}
48
response = self._verb_archive('GET', archive_name, query)
48
response = self._verb_archive('GET', archive_id, query)
49
49
data = response.read()
50
50
return simplejson.loads(data)