shazow/urllib3 — pull request #233 by t-8ch (2013-08-27 17:32:15+00:00)
Title: RFC: Fix WantReadError when using pyOpenSSL and Timeouts

Fixes the issues mentioned in kennethreitz/requests#749

Prevent WantReadError by using a fileobject which correctly handles those.
socket._fileobject which was previously used only handled builtin `EINTR` which
are is the corresponding error from the stdlib to WantReadError.
The new implementation inherits from socket._fileobject overwriting read() and
readline(). The overwritten methods are taken straight from CPython 2.7.5 and
modified as follows in the relevant places:

```
-except error, e:
- if e.args[0] == EINTR:
- continue
- raise
+except OpenSSL.SSL.WantReadError:
+ continue
```

urllib3 itself only needs `readline()` overwritten, but requests also needs
`read()`.
The handshake could have been handled automatically by writes and reads, but
when requesting the certificate directly after connection setup an error is
thrown.