1
0
mirror of https://github.com/moparisthebest/spdylay synced 2024-12-22 23:58:53 -05:00
spdylay/python/spdyclient.py

27 lines
726 B
Python
Raw Normal View History

2012-08-22 14:15:35 -04:00
#!/usr/bin/env python
# The example SPDY client. You need Python 3.3 or later because we
# use TLS NPN.
#
2012-08-27 12:47:21 -04:00
# Usage: spdyclient.py URL...
2012-08-22 14:15:35 -04:00
#
import sys
import spdylay
2012-08-27 12:47:21 -04:00
class MyStreamHandler(spdylay.BaseSPDYStreamHandler):
def on_header(self, nv):
sys.stdout.write('Stream#{}\n'.format(self.stream_id))
for k, v in nv:
sys.stdout.write('{}: {}\n'.format(k, v))
2012-08-22 14:15:35 -04:00
2012-08-27 12:47:21 -04:00
def on_data(self, data):
sys.stdout.write('Stream#{}\n'.format(self.stream_id))
sys.stdout.buffer.write(data)
2012-08-22 14:15:35 -04:00
2012-08-27 12:47:21 -04:00
def on_close(self, status_code):
sys.stdout.write('Stream#{} closed\n'.format(self.stream_id))
2012-08-22 14:15:35 -04:00
if __name__ == '__main__':
2012-08-27 12:47:21 -04:00
uris = sys.argv[1:]
spdylay.urlfetch(uris, MyStreamHandler)