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