ef87783e7b7a004cfa607bd8ee70c187ccb1bd33
6 def put_data(dev_uid
, format
, data
, username
, password
):
7 cmd
= '/subscriptions/%s/%d.%s' % (username
, dev_uid
, format
)
8 connection
= httplib
.HTTPConnection('127.0.0.1:8000')
10 headers
['Authorization'] = ' '.join(('Basic', base64
.encodestring(':'.join((username
, password
)))))
11 connection
.request('PUT', cmd
, data
, headers
)
12 response
= connection
.getresponse()
16 def get_data(dev_uid
, format
, username
, password
):
18 cmd
= '/subscriptions/%s/%d.%s' % (username
, dev_uid
, format
)
19 connection
= httplib
.HTTPConnection('127.0.0.1:8000')
21 headers
['Authorization'] = ' '.join(('Basic', base64
.encodestring(':'.join((username
, password
)))))
22 connection
.request('GET', cmd
, data
, headers
)
23 response
= connection
.getresponse()
27 if __name__
== "__main__":
30 p1
= 'http://www.podcast1.com'
31 p2
= 'http://www.podcast2.com'
32 p3
= 'http://www.podcast3.com'
33 p4
= 'http://www.podcast4.com'
34 data_txt_1
= '%s\n%s\n\n' % (p1
, p2
)
35 data_txt_2
= '%s\n%s\n\n' % (p2
, p3
)
36 data_txt_3
= '%s\n%s\n%s\n\n' % (p1
, p3
, p4
)
38 print 'put %s and %s on device %d' % (p1
, p2
, d1
)
39 put_data(d1
, 'txt', data_txt_1
, u
, p
)
40 print 'get subscriptions'
41 get_data(d1
, 'txt', u
, p
)
43 print 'put %s and %s on device %d' % (p2
, p3
, d1
)
44 put_data(d1
, 'txt', data_txt_2
, u
, p
)
45 print 'get subscriptions'
46 get_data(d1
, 'txt', u
, p
)
48 print 'put %s, %s and %s on device %d' % (p1
, p3
, p4
, d1
)
49 put_data(d1
, 'txt', data_txt_3
, u
, p
)
50 print 'get subscriptions'
51 get_data(d1
, 'txt', u
, p
)