16
19
self.netloc = '%s:%d' % (host, port)
18
def archive_url(self, archive_name, query):
19
path = '/%s' % quote(archive_name)
20
query = urlencode(query)
21
url = urlunparse(('http', self.netloc, path, '', '', ''))
21
def archive_url(self, archive_id, query):
22
path = '/archive/%s' % quote(archive_id)
23
query_string = urlencode(query)
24
return urlunparse(('http', self.netloc, path, '', query_string, ''))
23
26
def _get_connection(self):
24
print 'Connecting to %s' % self.port
25
27
return httplib.HTTPConnection(self.host, self.port)
27
def _verb_archive(self, verb, archive_name, query, body=None):
28
url = self.archive_url(archive_name, query)
29
def _verb_archive(self, verb, archive_id, query, body=None):
30
url = self.archive_url(archive_id, query)
29
31
connection = self._get_connection()
30
32
connection.request(verb, url, body)
31
33
return connection.getresponse()
33
def put_message(self, archive_name, key, file_obj):
35
def put_message(self, archive_id, key, file_obj):
34
36
response = self._verb_archive(
35
'POST', archive_name, {'key': key}, file_obj.read())
37
'POST', archive_id, {'key': key}, file_obj.read())
36
38
data = response.read()
37
39
if response.status == httplib.BAD_REQUEST:
38
40
raise Exception('wtf')
42
44
raise Exception('!!')
44
def get_messages(self, archive_name, message_ids=None):
46
def get_messages(self, archive_id, message_ids=None, limit=None,
47
memo=None, order=None, headers=None,
48
max_body_length=None, include_hidden=False):
46
50
if message_ids is not None:
47
parameters[message_ids] = message_ids
51
parameters['message_ids'] = message_ids
53
parameters['limit'] = limit
55
parameters['memo'] = memo
57
parameters['order'] = order
58
if headers is not None:
59
parameters['headers'] = headers
60
if max_body_length is not None:
61
parameters['max_body_length'] = max_body_length
62
parameters['include_hidden'] = include_hidden
48
63
query = {'parameters': simplejson.dumps(parameters)}
49
response = self._verb_archive('GET', archive_name, query)
64
response = self._verb_archive('GET', archive_id, query)
65
if response.status == httplib.BAD_REQUEST:
66
raise UnsupportedOrder
67
data = response.read()
68
return simplejson.loads(data)