| 20 | self.local.connections.pop().close() |
| 21 | |
| 22 | def test(conn): |
| 23 | # Example use |
| 24 | from functools import partial |
| 25 | |
| 26 | with conn as s: |
| 27 | s.send(b'GET /index.html HTTP/1.0\r\n') |
| 28 | s.send(b'Host: www.python.org\r\n') |
| 29 | s.send(b'\r\n') |
| 30 | resp = b''.join(iter(partial(s.recv, 8192), b'')) |
| 31 | |
| 32 | print('Got {} bytes'.format(len(resp))) |
| 33 | |
| 34 | with conn as s1, conn as s2: |
| 35 | s1.send(b'GET /downloads HTTP/1.0\r\n') |
| 36 | s2.send(b'GET /index.html HTTP/1.0\r\n') |
| 37 | s1.send(b'Host: www.python.org\r\n') |
| 38 | s2.send(b'Host: www.python.org\r\n') |
| 39 | s1.send(b'\r\n') |
| 40 | s2.send(b'\r\n') |
| 41 | resp1 = b''.join(iter(partial(s1.recv, 8192), b'')) |
| 42 | resp2 = b''.join(iter(partial(s2.recv, 8192), b'')) |
| 43 | |
| 44 | print('resp1 got {} bytes'.format(len(resp1))) |
| 45 | print('resp2 got {} bytes'.format(len(resp2))) |
| 46 | |
| 47 | if __name__ == '__main__': |
| 48 | |