patcher: Eliminate some redundancy
All those code blocks do the same thing so I decided to extract the logic into a one place.
This commit is contained in:
parent
1de32fa6f0
commit
ed6f39de2c
|
@ -251,27 +251,19 @@ def monkey_patch(**on):
|
|||
on.setdefault(modname, default_on)
|
||||
|
||||
modules_to_patch = []
|
||||
if on['os'] and not already_patched.get('os'):
|
||||
modules_to_patch += _green_os_modules()
|
||||
already_patched['os'] = True
|
||||
if on['select'] and not already_patched.get('select'):
|
||||
modules_to_patch += _green_select_modules()
|
||||
already_patched['select'] = True
|
||||
if on['socket'] and not already_patched.get('socket'):
|
||||
modules_to_patch += _green_socket_modules()
|
||||
already_patched['socket'] = True
|
||||
if on['thread'] and not already_patched.get('thread'):
|
||||
modules_to_patch += _green_thread_modules()
|
||||
already_patched['thread'] = True
|
||||
if on['time'] and not already_patched.get('time'):
|
||||
modules_to_patch += _green_time_modules()
|
||||
already_patched['time'] = True
|
||||
if on.get('MySQLdb') and not already_patched.get('MySQLdb'):
|
||||
modules_to_patch += _green_MySQLdb()
|
||||
already_patched['MySQLdb'] = True
|
||||
if on.get('builtins') and not already_patched.get('builtins'):
|
||||
modules_to_patch += _green_builtins()
|
||||
already_patched['builtins'] = True
|
||||
for name, modules_function in [
|
||||
('os', _green_os_modules),
|
||||
('select', _green_select_modules),
|
||||
('socket', _green_socket_modules),
|
||||
('thread', _green_thread_modules),
|
||||
('time', _green_time_modules),
|
||||
('MySQLdb', _green_MySQLdb),
|
||||
('builtins', _green_builtins),
|
||||
]:
|
||||
if on[name] and not already_patched.get(name):
|
||||
modules_to_patch += modules_function()
|
||||
already_patched[name] = True
|
||||
|
||||
if on['psycopg'] and not already_patched.get('psycopg'):
|
||||
try:
|
||||
from eventlet.support import psycopg2_patcher
|
||||
|
|
Loading…
Reference in New Issue