Commit 97f05b3f authored by Denis Bilenko's avatar Denis Bilenko

monkey: customize patching dns with 'dns' keyword argument to patch_socket and patch_all

parent 50d2c219
...@@ -24,14 +24,19 @@ def patch_thread(): ...@@ -24,14 +24,19 @@ def patch_thread():
thread.stack_size = green_thread.stack_size thread.stack_size = green_thread.stack_size
# XXX should also patch threadlocal # XXX should also patch threadlocal
def patch_socket(): def patch_socket(dns=True):
from gevent.socket import GreenSocket, fromfd, wrap_ssl, socketpair, getaddrinfo, getnameinfo, gethostbyname from gevent.socket import GreenSocket, fromfd, wrap_ssl, socketpair
_socket = __import__('socket') _socket = __import__('socket')
_socket.socket = GreenSocket _socket.socket = GreenSocket
_socket.fromfd = fromfd _socket.fromfd = fromfd
_socket.ssl = wrap_ssl _socket.ssl = wrap_ssl
_socket.socketpair = socketpair _socket.socketpair = socketpair
# dns if dns:
patch_dns()
def patch_dns():
from gevent.socket import getaddrinfo, getnameinfo, gethostbyname
_socket = __import__('socket')
_socket.getaddrinfo = getaddrinfo _socket.getaddrinfo = getaddrinfo
_socket.getnameinfo = getnameinfo _socket.getnameinfo = getnameinfo
_socket.gethostbyname = gethostbyname _socket.gethostbyname = gethostbyname
...@@ -48,7 +53,7 @@ def patch_select(): ...@@ -48,7 +53,7 @@ def patch_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, ssl=True): def patch_all(socket=True, dns=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()
...@@ -57,12 +62,13 @@ def patch_all(socket=True, time=True, select=True, thread=True, os=True, ssl=Tru ...@@ -57,12 +62,13 @@ def patch_all(socket=True, time=True, select=True, thread=True, os=True, ssl=Tru
if thread: if thread:
patch_thread() patch_thread()
if socket: if socket:
patch_socket() patch_socket(dns=dns)
if select: if select:
patch_select() patch_select()
if ssl: if ssl:
patch_ssl() patch_ssl()
if __name__=='__main__': if __name__=='__main__':
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