summaryrefslogtreecommitdiff
path: root/eventlet/green
diff options
context:
space:
mode:
authorSergey Shepelev <temotor@gmail.com>2013-10-07 16:48:34 +0400
committerSergey Shepelev <temotor@gmail.com>2013-12-03 22:36:29 +0400
commitd2bbbd79d3f903fbff59f09467af681d5b9282cf (patch)
tree6a6da9b62894d62fdaa1050acbd39c46e710b9e8 /eventlet/green
parent35f600600c59c295fab0131c7bc0032e28b70045 (diff)
downloadeventlet-d2bbbd79d3f903fbff59f09467af681d5b9282cf.tar.gz
python3 compat: remove lots of Python 2.5 and earlier dependent code; use print() function syntax
Diffstat (limited to 'eventlet/green')
-rw-r--r--eventlet/green/_socket_nodns.py27
-rw-r--r--eventlet/green/ssl.py38
-rw-r--r--eventlet/green/subprocess.py30
3 files changed, 38 insertions, 57 deletions
diff --git a/eventlet/green/_socket_nodns.py b/eventlet/green/_socket_nodns.py
index 9a526ff..211201d 100644
--- a/eventlet/green/_socket_nodns.py
+++ b/eventlet/green/_socket_nodns.py
@@ -4,7 +4,7 @@ __all__ = __socket.__all__
__patched__ = ['fromfd', 'socketpair', 'ssl', 'socket']
from eventlet.patcher import slurp_properties
-slurp_properties(__socket, globals(),
+slurp_properties(__socket, globals(),
ignore=__patched__, srckeys=dir(__socket))
os = __import__('os')
@@ -87,24 +87,15 @@ class GreenSSLObject(object):
try:
- try:
- # >= Python 2.6
- from eventlet.green import ssl as ssl_module
- sslerror = __socket.sslerror
- __socket.ssl
- def ssl(sock, certificate=None, private_key=None):
- warnings.warn("socket.ssl() is deprecated. Use ssl.wrap_socket() instead.",
- DeprecationWarning, stacklevel=2)
- return ssl_module.sslwrap_simple(sock, private_key, certificate)
- except ImportError:
- # <= Python 2.5 compatibility
- sslerror = __socket.sslerror
- __socket.ssl
- def ssl(sock, certificate=None, private_key=None):
- from eventlet import util
- wrapped = util.wrap_ssl(sock, certificate, private_key)
- return GreenSSLObject(wrapped)
+ from eventlet.green import ssl as ssl_module
+ sslerror = __socket.sslerror
+ __socket.ssl
except AttributeError:
# if the real socket module doesn't have the ssl method or sslerror
# exception, we can't emulate them
pass
+else:
+ def ssl(sock, certificate=None, private_key=None):
+ warnings.warn("socket.ssl() is deprecated. Use ssl.wrap_socket() instead.",
+ DeprecationWarning, stacklevel=2)
+ return ssl_module.sslwrap_simple(sock, private_key, certificate)
diff --git a/eventlet/green/ssl.py b/eventlet/green/ssl.py
index 40d29b0..62fec77 100644
--- a/eventlet/green/ssl.py
+++ b/eventlet/green/ssl.py
@@ -22,20 +22,20 @@ else:
__patched__ = ['SSLSocket', 'wrap_socket', 'sslwrap_simple']
class GreenSSLSocket(__ssl.SSLSocket):
- """ This is a green version of the SSLSocket class from the ssl module added
+ """ This is a green version of the SSLSocket class from the ssl module added
in 2.6. For documentation on it, please see the Python standard
documentation.
-
+
Python nonblocking ssl objects don't give errors when the other end
of the socket is closed (they do notice when the other end is shutdown,
though). Any write/read operations will simply hang if the socket is
closed from the other end. There is no obvious fix for this problem;
it appears to be a limitation of Python's ssl object implementation.
A workaround is to set a reasonable timeout on the socket using
- settimeout(), and to close/reopen the connection when a timeout
+ settimeout(), and to close/reopen the connection when a timeout
occurs at an unexpected juncture in the code.
"""
- # we are inheriting from SSLSocket because its constructor calls
+ # we are inheriting from SSLSocket because its constructor calls
# do_handshake whose behavior we wish to override
def __init__(self, sock, *args, **kw):
if not isinstance(sock, GreenSocket):
@@ -44,7 +44,7 @@ class GreenSSLSocket(__ssl.SSLSocket):
self.act_non_blocking = sock.act_non_blocking
self._timeout = sock.gettimeout()
super(GreenSSLSocket, self).__init__(sock.fd, *args, **kw)
-
+
# the superclass initializer trashes the methods so we remove
# the local-object versions of them and let the actual class
# methods shine through
@@ -53,13 +53,13 @@ class GreenSSLSocket(__ssl.SSLSocket):
delattr(self, fn)
except AttributeError:
pass
-
+
def settimeout(self, timeout):
self._timeout = timeout
-
+
def gettimeout(self):
return self._timeout
-
+
def setblocking(self, flag):
if flag:
self.act_non_blocking = False
@@ -141,7 +141,7 @@ class GreenSSLSocket(__ssl.SSLSocket):
if self.act_non_blocking:
raise
if get_errno(e) == errno.EWOULDBLOCK:
- trampoline(self, write=True,
+ trampoline(self, write=True,
timeout=self.gettimeout(), timeout_exc=timeout_exc('timed out'))
if get_errno(e) in SOCKET_CLOSED:
return ''
@@ -164,13 +164,13 @@ class GreenSSLSocket(__ssl.SSLSocket):
if self.act_non_blocking:
raise
if get_errno(e) == errno.EWOULDBLOCK:
- trampoline(self, read=True,
+ trampoline(self, read=True,
timeout=self.gettimeout(), timeout_exc=timeout_exc('timed out'))
if get_errno(e) in SOCKET_CLOSED:
return ''
raise
-
+
def recv_into (self, buffer, nbytes=None, flags=0):
if not self.act_non_blocking:
trampoline(self, read=True, timeout=self.gettimeout(), timeout_exc=timeout_exc('timed out'))
@@ -180,7 +180,7 @@ class GreenSSLSocket(__ssl.SSLSocket):
if not self.act_non_blocking:
trampoline(self, read=True, timeout=self.gettimeout(), timeout_exc=timeout_exc('timed out'))
return super(GreenSSLSocket, self).recvfrom(addr, buflen, flags)
-
+
def recvfrom_into (self, buffer, nbytes=None, flags=0):
if not self.act_non_blocking:
trampoline(self, read=True, timeout=self.gettimeout(), timeout_exc=timeout_exc('timed out'))
@@ -190,7 +190,7 @@ class GreenSSLSocket(__ssl.SSLSocket):
return GreenSocket(self._call_trampolining(
super(GreenSSLSocket, self).unwrap))
- def do_handshake(self):
+ def do_handshake(self):
"""Perform a TLS/SSL handshake."""
return self._call_trampolining(
super(GreenSSLSocket, self).do_handshake)
@@ -220,7 +220,7 @@ class GreenSSLSocket(__ssl.SSLSocket):
real_connect(self, addr)
except orig_socket.error as exc:
if get_errno(exc) in CONNECT_ERR:
- trampoline(self, write=True,
+ trampoline(self, write=True,
timeout=end-time.time(), timeout_exc=timeout_exc('timed out'))
elif get_errno(exc) in CONNECT_SUCCESS:
return
@@ -228,7 +228,7 @@ class GreenSSLSocket(__ssl.SSLSocket):
raise
if time.time() >= end:
raise timeout_exc('timed out')
-
+
def connect(self, addr):
"""Connects to remote ADDR, and then wraps the connection in
@@ -281,7 +281,7 @@ class GreenSSLSocket(__ssl.SSLSocket):
def dup(self):
raise NotImplementedError("Can't dup an ssl object")
-
+
SSLSocket = GreenSSLSocket
def wrap_socket(sock, *a, **kw):
@@ -294,8 +294,8 @@ if hasattr(__ssl, 'sslwrap_simple'):
for compability with Python 2.5 and earlier. Will disappear in
Python 3.0."""
ssl_sock = GreenSSLSocket(sock, keyfile=keyfile, certfile=certfile,
- server_side=False,
- cert_reqs=CERT_NONE,
- ssl_version=PROTOCOL_SSLv23,
+ server_side=False,
+ cert_reqs=CERT_NONE,
+ ssl_version=PROTOCOL_SSLv23,
ca_certs=None)
return ssl_sock
diff --git a/eventlet/green/subprocess.py b/eventlet/green/subprocess.py
index a7196e9..a0fbe7c 100644
--- a/eventlet/green/subprocess.py
+++ b/eventlet/green/subprocess.py
@@ -77,29 +77,19 @@ class Popen(subprocess_orig.Popen):
# don't want to rewrite the original _communicate() method, we
# just want a version that uses eventlet.green.select.select()
# instead of select.select().
+ _communicate = new.function(subprocess_orig.Popen._communicate.im_func.func_code,
+ globals())
try:
- _communicate = new.function(subprocess_orig.Popen._communicate.im_func.func_code,
- globals())
- try:
- _communicate_with_select = new.function(
- subprocess_orig.Popen._communicate_with_select.im_func.func_code,
- globals())
- _communicate_with_poll = new.function(
- subprocess_orig.Popen._communicate_with_poll.im_func.func_code,
- globals())
- except AttributeError:
- pass
+ _communicate_with_select = new.function(
+ subprocess_orig.Popen._communicate_with_select.im_func.func_code,
+ globals())
+ _communicate_with_poll = new.function(
+ subprocess_orig.Popen._communicate_with_poll.im_func.func_code,
+ globals())
except AttributeError:
- # 2.4 only has communicate
- _communicate = new.function(subprocess_orig.Popen.communicate.im_func.func_code,
- globals())
- def communicate(self, input=None):
- return self._communicate(input)
+ pass
# Borrow subprocess.call() and check_call(), but patch them so they reference
# OUR Popen class rather than subprocess.Popen.
call = new.function(subprocess_orig.call.func_code, globals())
-try:
- check_call = new.function(subprocess_orig.check_call.func_code, globals())
-except AttributeError:
- pass # check_call added in 2.5
+check_call = new.function(subprocess_orig.check_call.func_code, globals())