(conn)
| 20 | del self.local.sock |
| 21 | |
| 22 | def test(conn): |
| 23 | from functools import partial |
| 24 | |
| 25 | # Connection closed |
| 26 | with conn as s: |
| 27 | # conn.__enter__() executes: connection open |
| 28 | s.send(b'GET /index.html HTTP/1.0\r\n') |
| 29 | s.send(b'Host: www.python.org\r\n') |
| 30 | s.send(b'\r\n') |
| 31 | resp = b''.join(iter(partial(s.recv, 8192), b'')) |
| 32 | # conn.__exit__() executes: connection closed |
| 33 | |
| 34 | print('Got {} bytes'.format(len(resp))) |
| 35 | |
| 36 | if __name__ == '__main__': |
| 37 | conn = LazyConnection(('www.python.org', 80)) |