Commit eaa13681 authored by Denis Bilenko's avatar Denis Bilenko

monkey: patch ssl module when on 2.6 (very limited support)

parent 5c752d98
import sys
def patch_os(): def patch_os():
from gevent import fork from gevent import fork
import os import os
...@@ -28,13 +30,19 @@ def patch_socket(): ...@@ -28,13 +30,19 @@ def patch_socket():
_socket.socketpair = socketpair _socket.socketpair = socketpair
# also gethostbyname, getaddrinfo # also gethostbyname, getaddrinfo
def patch_ssl():
if sys.version_info[:2] >= (2, 6):
from gevent.socket import wrap_ssl
import ssl
ssl.wrap_socket = wrap_ssl
def patch_select(): def patch_select():
from gevent.select import select from gevent.select import select
_select = __import__('select') _select = __import__('select')
globals()['_select_select'] = _select.select globals()['_select_select'] = _select.select
_select.select = select _select.select = select
def patch_all(socket=True, time=True, select=True, thread=True, os=True): def patch_all(socket=True, time=True, select=True, thread=True, os=True, ssl=True):
# order is important # order is important
if os: if os:
patch_os() patch_os()
...@@ -46,13 +54,10 @@ def patch_all(socket=True, time=True, select=True, thread=True, os=True): ...@@ -46,13 +54,10 @@ def patch_all(socket=True, time=True, select=True, thread=True, os=True):
patch_socket() patch_socket()
if select: if select:
patch_select() patch_select()
if ssl:
# XXX patch unittest to count switches and detect event_count and run the standard tests 2 hour patch_ssl()
# make makefile() return GreenFile. since it uses socket's buffer, while _fileobject creates a new one 2 hour
# probably make GreenSocket be also a file and makefile() just increases refcount and returns self
if __name__=='__main__': if __name__=='__main__':
import sys
modules = [x.replace('patch_', '') for x in globals().keys() if x.startswith('patch_') and x!='patch_all'] modules = [x.replace('patch_', '') for x in globals().keys() if x.startswith('patch_') and x!='patch_all']
script_help = """gevent.monkey - monkey patch the standard modules to use gevent. script_help = """gevent.monkey - monkey patch the standard modules to use gevent.
......
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