Martin Panter added the comment:

Okay I see your point about backwards compatibility now. Indeed, I have written 
code myself before Python 3.3 that used to inspect err.args[0], and it would 
suffer a similar problem if I had not updated it to use the new Python 3.3 
exception subclasses.

Below I have written a comparison of two options that have been proposed. Both 
have disadvantages and would potentially require changes in user code.

A third middle-ground option might be to deprecate OSError.errno as well, and 
replace it with OSError.posix_errno or something. But I would still prefer the 
option to stop setting SSLError.errno, even though it breaks backwards 
compatibility. I think we can at least agree that “errno” and “args” should be 
deprecated for SSLError instances.

## Option 1: Add OSError.errno_scope ##

To avoid the bug in new Python versions we would still have to modify code 
handling a general OSError (EnvironmentError), for example:

# Buggy handler compatible with Python 3.2
try:
  return ssl_sock.read()
except EnvironmentError as e:
  if e.errno != errno.EINTR:
    raise

# Fixed handler, supporting new Python versions only
try:
  return ssl_sock.read()
except OSError as e:
  if e.errno_scope != POSIX or e.errno != errno.EINTR:
    raise

Advantages:
* Existing code still works if you don’t care about this bug
* No code changes required in SSL error handlers

## Option 2: Stop setting SSLError.errno ##

Existing SSLError handlers written for Python < 3.3 would stop catching 
exceptions, because “errno” defaults to None. This would probably cause an 
unhandled exception, and could be fixed as follows:

# Broken handler written for Python 3.2
try:
  return ssl_sock.read()
except SSLError as e:
  if e.errno != SSL_ERROR_WANT_READ:
    raise
  # Handle non-blocking read

# Fixed handler, supporting Python 3.3+ only
try:
  return ssl_sock.read()
except SSLWantReadError as e:
  # Handle non-blocking read

Advantages:
* Affected code should be easy to find due to breakage
* Only requires the user to change code that directly handles SSL errors
* No changes for code already written for Python 3.3
* Code changes only when relying on the undocumented errno behaviour, which is 
already asking for trouble

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23588>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to