Skip to content

Commit

Permalink
Fix metaclass var binding
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Sep 2, 2018
1 parent dd09e30 commit 2eb2abe
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cheroot/ssl/pyopenssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,22 @@ def __new__(mcl, name, bases, nmspc):
proxy_no_args = (
'shutdown',
)
for m in proxy_methods:

def lock_decorator(method):
"""Create a proxy method for a new class."""
def proxy_wrapper(self, *args):
self._lock.acquire()
try:
new_args = args[:] if m not in proxy_no_args else []
return getattr(self._ssl_conn, m)(*new_args)
new_args = (
args[:] if method not in proxy_no_args else []
)
return getattr(self._ssl_conn, method)(*new_args)
finally:
self._lock.release()
proxy_wrapper.__name__ = m
nmspc[m] = proxy_wrapper
return proxy_wrapper
for m in proxy_methods:
nmspc[m] = lock_decorator(m)
nmspc[m].__name__ = m

# Doesn't work via super() for some reason.
# Falling back to type() instead:
Expand Down

0 comments on commit 2eb2abe

Please sign in to comment.