File: 0014-Fix-for-Python-3.7.patch

package info (click to toggle)
python-eventlet 0.20.0-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 3,376 kB
  • sloc: python: 31,120; sh: 208; makefile: 90
file content (169 lines) | stat: -rw-r--r-- 6,234 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
From cf47cb518db3e0dbdd48473fb40cf9f6ecd50e07 Mon Sep 17 00:00:00 2001
From: Marcel Plch <mplch@redhat.com>
Date: Fri, 28 Sep 2018 17:08:59 +0200
Subject: [PATCH] Fix for Python 3.7 (#506)
Origin: https://github.com/eventlet/eventlet/commit/cf47cb518db3e0dbdd48473fb40cf9f6ecd50e07

* Fix for Python 3.7

* Remove redundant piece of code.

* Put back do_handshake_on_connect kwarg

* Use Python 3.7 instead of 3.7-dev

* Fix buildbot failing permissions with 3.7

* tests: env_tpool_zero assert details

* setup: Python 3.7 classificator
---
 .travis.yml                      |  6 ++---
 eventlet/green/ssl.py            | 46 +++++++++++++++++++++++++++-----
 setup.py                         |  1 +
 tests/debug_test.py              | 14 ++++++++--
 tests/isolated/env_tpool_zero.py |  5 ++--
 5 files changed, 59 insertions(+), 13 deletions(-)

--- a/eventlet/green/ssl.py
+++ b/eventlet/green/ssl.py
@@ -28,6 +28,7 @@
     'create_default_context', '_create_default_https_context']
 
 _original_sslsocket = __ssl.SSLSocket
+_original_wrap_socket = __ssl.wrap_socket
 
 
 class GreenSSLSocket(_original_sslsocket):
@@ -61,11 +62,41 @@
             # this assignment
             self._timeout = sock.gettimeout()
 
-        # nonblocking socket handshaking on connect got disabled so let's pretend it's disabled
-        # even when it's on
-        super(GreenSSLSocket, self).__init__(
-            sock.fd, keyfile, certfile, server_side, cert_reqs, ssl_version,
-            ca_certs, do_handshake_on_connect and six.PY2, *args, **kw)
+        if sys.version_info >= (3, 7):
+            # Monkey-patch the sslsocket so our modified self gets
+            # injected into its _create method.
+            def fake_new(self, cls, *args, **kwargs):
+                return self
+
+            orig_new = _original_sslsocket.__new__
+            try:
+                _original_sslsocket.__new__ = fake_new.__get__(self, GreenSSLSocket)
+
+                self = _original_wrap_socket(
+                    sock=sock.fd,
+                    keyfile=keyfile,
+                    certfile=certfile,
+                    server_side=server_side,
+                    cert_reqs=cert_reqs,
+                    ssl_version=ssl_version,
+                    ca_certs=ca_certs,
+                    do_handshake_on_connect=False,
+                    *args, **kw
+                )
+                self.keyfile = keyfile
+                self.certfile = certfile
+                self.cert_reqs = cert_reqs
+                self.ssl_version = ssl_version
+                self.ca_certs = ca_certs
+            finally:
+                # Unpatch
+                _original_sslsocket.__new__ = orig_new
+        else:
+            # nonblocking socket handshaking on connect got disabled so let's pretend it's disabled
+            # even when it's on
+            super(GreenSSLSocket, self).__init__(
+                sock.fd, keyfile, certfile, server_side, cert_reqs, ssl_version,
+                ca_certs, do_handshake_on_connect and six.PY2, *args, **kw)
 
         # the superclass initializer trashes the methods so we remove
         # the local-object versions of them and let the actual class
@@ -333,7 +364,10 @@
         except NameError:
             self._sslobj = sslobj
         else:
-            self._sslobj = SSLObject(sslobj, owner=self)
+            if sys.version_info < (3, 7):
+                self._sslobj = SSLObject(sslobj, owner=self)
+            else:
+                self._sslobj = sslobj
 
         if self.do_handshake_on_connect:
             self.do_handshake()
--- a/setup.py
+++ b/setup.py
@@ -34,6 +34,9 @@
         "Programming Language :: Python :: 2.7",
         "Programming Language :: Python :: 3.3",
         "Programming Language :: Python :: 3.4",
+        "Programming Language :: Python :: 3.5",
+        "Programming Language :: Python :: 3.6",
+        "Programming Language :: Python :: 3.7",
         "Topic :: Internet",
         "Topic :: Software Development :: Libraries :: Python Modules",
         "Intended Audience :: Developers",
--- a/tests/debug_test.py
+++ b/tests/debug_test.py
@@ -30,6 +30,11 @@
         assert self.tracer is None
 
     def test_line(self):
+        if sys.version_info >= (3, 7):
+            frame_str = "f=<frame at"
+        else:
+            frame_str = "f=<frame object at"
+
         sys.stdout = six.StringIO()
         s = debug.Spew()
         f = sys._getframe()
@@ -37,7 +42,7 @@
         lineno = f.f_lineno - 1  # -1 here since we called with frame f in the line above
         output = sys.stdout.getvalue()
         assert "%s:%i" % (__name__, lineno) in output, "Didn't find line %i in %s" % (lineno, output)
-        assert "f=<frame object at" in output
+        assert frame_str in output
 
     def test_line_nofile(self):
         sys.stdout = six.StringIO()
@@ -52,6 +57,11 @@
         assert "VM instruction #" in output, output
 
     def test_line_global(self):
+        if sys.version_info >= (3, 7):
+            frame_str = "f=<frame at"
+        else:
+            frame_str = "f=<frame object at"
+
         global GLOBAL_VAR
         sys.stdout = six.StringIO()
         GLOBAL_VAR = debug.Spew()
@@ -60,7 +70,7 @@
         lineno = f.f_lineno - 1  # -1 here since we called with frame f in the line above
         output = sys.stdout.getvalue()
         assert "%s:%i" % (__name__, lineno) in output, "Didn't find line %i in %s" % (lineno, output)
-        assert "f=<frame object at" in output
+        assert frame_str in output
         assert "GLOBAL_VAR" in f.f_globals
         assert "GLOBAL_VAR=<eventlet.debug.Spew object at" in output
         del GLOBAL_VAR
--- a/tests/isolated/env_tpool_zero.py
+++ b/tests/isolated/env_tpool_zero.py
@@ -9,11 +9,12 @@
         g[0] = True
 
     with warnings.catch_warnings(record=True) as ws:
-        warnings.simplefilter('always')
+        warnings.simplefilter('always', category=RuntimeWarning)
 
         tpool.execute(do)
 
-        assert len(ws) == 1
+        msgs = [str(w) for w in ws]
+        assert len(ws) == 1, msgs
         msg = str(ws[0].message)
         assert 'Zero threads in tpool' in msg
         assert 'EVENTLET_THREADPOOL_SIZE' in msg