Commit a1458850 authored by Denis Bilenko's avatar Denis Bilenko

socket: import from the stdlib's socket everything that we should be importing

- add __implements__, __extensions__ and __imports__
- do not add 'ssl' and 'sslerror' to __all__ if on Python >= 2.6
- add 'SSLType' to __all__ if on Python <= 2.5
parent ead3939c
......@@ -31,26 +31,45 @@ For convenience, exceptions (like :class:`error <socket.error>` and :class:`time
as well as the constants from :mod:`socket` module are imported into this module.
"""
__all__ = ['create_connection',
'error',
'fromfd',
'gaierror',
# standard functions and classes that this module re-implements in a gevent-aware way:
__implements__ = ['create_connection',
'getaddrinfo',
'gethostbyname',
'socket',
'SocketType',
'fromfd',
'socketpair']
# non-standard functions that this module provides:
__extensions__ = ['wait_read',
'wait_write',
'wait_readwrite']
# standard functions and classes that this module re-imports
__imports__ = ['error',
'gaierror',
'getfqdn',
'herror',
'htonl',
'htons',
'ntohl',
'ntohs',
'inet_aton',
'inet_ntoa',
'inet_pton',
'inet_ntop',
'socket',
'socketpair',
'timeout',
'ssl',
'sslerror',
'SocketType',
'wait_read',
'wait_write',
'wait_readwrite']
'gethostname',
'getprotobyname',
'getservbyname',
'getservbyport',
'getdefaulttimeout',
'setdefaulttimeout',
# Python 2.5 and older:
'RAND_add',
'RAND_egd',
'RAND_status']
import sys
import time
......@@ -83,49 +102,26 @@ except ImportError:
EBADF = 9
import _socket
error = _socket.error
timeout = _socket.timeout
_realsocket = _socket.socket
__socket__ = __import__('socket')
_fileobject = __socket__._fileobject
gaierror = _socket.gaierror
# Import public constants from the standard socket (called __socket__ here) into this module.
for name in __imports__[:]:
try:
value = getattr(__socket__, name)
globals()[name] = value
except AttributeError:
__imports__.remove(name)
for name in __socket__.__all__:
if name[:1].isupper():
value = getattr(__socket__, name)
if isinstance(value, (int, long, basestring)):
globals()[name] = value
__all__.append(name)
elif name == 'getfqdn':
globals()[name] = getattr(__socket__, name)
__all__.append(name)
__imports__.append(name)
del name, value
inet_ntoa = _socket.inet_ntoa
inet_aton = _socket.inet_aton
try:
inet_ntop = _socket.inet_ntop
except AttributeError:
def inet_ntop(address_family, packed_ip):
if address_family == AF_INET:
return inet_ntoa(packed_ip)
# XXX: ipv6 won't work on windows
raise NotImplementedError('inet_ntop() is not available on this platform')
try:
inet_pton = _socket.inet_pton
except AttributeError:
def inet_pton(address_family, ip_string):
if address_family == AF_INET:
return inet_aton(ip_string)
# XXX: ipv6 won't work on windows
raise NotImplementedError('inet_ntop() is not available on this platform')
# XXX: import other non-blocking stuff, like ntohl
# XXX: implement blocking functions that are not yet implemented
# XXX: add test that checks that socket.__all__ matches gevent.socket.__all__ on all supported platforms
from gevent.hub import getcurrent, get_hub
from gevent import core
......@@ -721,16 +717,17 @@ else:
_have_ssl = False
try:
from gevent.ssl import sslwrap_simple as ssl, SSLError as sslerror
from gevent.ssl import sslwrap_simple as ssl, SSLError as sslerror, SSLSocket as SSLType
_have_ssl = True
except ImportError:
try:
from gevent.sslold import ssl, sslerror
from gevent.sslold import ssl, sslerror, SSLObject as SSLType
_have_ssl = True
except ImportError:
pass
if not _have_ssl:
__all__.remove('ssl')
__all__.remove('sslerror')
if sys.version_info[:2] <= (2, 5) and _have_ssl:
__implements__.extend(['ssl', 'sslerror', 'SSLType'])
__all__ = __implements__ + __extensions__ + __imports__
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment