~mordred/ubuntu/natty/python-eventlet/ipv6-fix

« back to all changes in this revision

Viewing changes to eventlet/support/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2010-08-23 08:54:30 UTC
  • Revision ID: james.westby@ubuntu.com-20100823085430-xmu81mc33go27hv9
Tags: upstream-0.9.10
ImportĀ upstreamĀ versionĀ 0.9.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
def get_errno(exc):
 
3
    """ Get the error code out of socket.error objects.
 
4
    socket.error in <2.5 does not have errno attribute
 
5
    socket.error in 3.x does not allow indexing access
 
6
    e.args[0] works for all.
 
7
    There are cases when args[0] is not errno.
 
8
    i.e. http://bugs.python.org/issue6471
 
9
    Maybe there are cases when errno is set, but it is not the first argument?
 
10
    """
 
11
 
 
12
    try:
 
13
        if exc.errno is not None: return exc.errno
 
14
    except AttributeError:
 
15
        pass
 
16
    try:
 
17
        return exc.args[0]
 
18
    except IndexError:
 
19
        return None
 
20
 
 
21
if sys.version_info[0]<3:
 
22
    from sys import exc_clear as clear_sys_exc_info
 
23
else:
 
24
    def clear_sys_exc_info():
 
25
        """No-op In py3k. 
 
26
        Exception information is not visible outside of except statements.
 
27
        sys.exc_clear became obsolete and removed."""
 
28
        pass
 
29
 
 
30
if sys.version_info[0]==2 and sys.version_info[1]<5:
 
31
    class BaseException:                      # pylint: disable-msg=W0622
 
32
        # not subclassing from object() intentionally, because in
 
33
        # that case "raise Timeout" fails with TypeError.
 
34
        pass
 
35
else:
 
36
    from __builtin__ import BaseException