3
def put_message(archive_name, file_obj):
4
connection = httplib.HTTPConnection('localhost', 8435)
5
connection.request('POST', 'foo', file_obj.read())
6
response = connection.getresponse()
8
if response.status == httplib.BAD_REQUEST:
10
elif response.status == httplib.CREATED:
2
from urlparse import urlunparse
3
from urllib import quote
6
def message_path(archive_name, message_id):
7
return '/%s/%s' % (quote(archive_name), quote(message_id))
12
def __init__(self, host, port):
16
def message_url(self, archive_name, message_id):
17
netloc = '%s:%d' % (self.host, self.port)
18
path = message_path(archive_name, message_id)
19
return urlunparse(('http', netloc, path, '', '', ''))
21
def put_message(self, archive_name, message_id, file_obj):
22
url = self.message_url(archive_name, message_id)
23
connection = httplib.HTTPConnection(self.host, self.port)
24
connection.request('PUT', url, file_obj.read())
25
response = connection.getresponse()
26
data = response.read()
27
if response.status == httplib.BAD_REQUEST:
28
raise Exception('wtf')
29
elif response.status == httplib.CREATED: