Deploying an SPDY Client Using Python 2.7

I am trying to use SPDY from Python 2.7. I found the Python-spdylay library as a wrapper around the C implementation. I understand that some parts of the library are only Python 3.

I would like to reproduce the behavior of the following example from the Python-spdylay documentation in Python 2.7 ( http://spdylay.sourceforge.net/python.html#simple-spdy-client ):

#!/usr/bin/env python # The example SPDY client. You need Python 3.3 or later because we # use TLS NPN. # # Usage: spdyclient.py URL... # import sys import spdylay 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)) def on_data(self, data): sys.stdout.write('Stream#{}\n'.format(self.stream_id)) sys.stdout.buffer.write(data) def on_close(self, status_code): sys.stdout.write('Stream#{} closed\n'.format(self.stream_id)) if __name__ == '__main__': uris = sys.argv[1:] spdylay.urlfetch(uris, MyStreamHandler) 

In other words, I just want to get the url and provide callbacks, but using SPDY.

PyPi provides this statement

The core library API works with Python 2 and 3. But ThreadedSPDYServer requires Python 3.3 because it uses the TLS NPN extension.

I assume this means that spylay.urlfetch and spdylay.BaseSPDYStreamHandler use ThreadedSPDYServer , so maybe there is a non-streaming SPDYServer that I can use?

+4
source share

Source: https://habr.com/ru/post/1483557/


All Articles