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:
@@ -251,27 +251,19 @@ def monkey_patch(**on):
|
|||||||
on.setdefault(modname, default_on)
|
on.setdefault(modname, default_on)
|
||||||
|
|
||||||
modules_to_patch = []
|
modules_to_patch = []
|
||||||
if on['os'] and not already_patched.get('os'):
|
for name, modules_function in [
|
||||||
modules_to_patch += _green_os_modules()
|
('os', _green_os_modules),
|
||||||
already_patched['os'] = True
|
('select', _green_select_modules),
|
||||||
if on['select'] and not already_patched.get('select'):
|
('socket', _green_socket_modules),
|
||||||
modules_to_patch += _green_select_modules()
|
('thread', _green_thread_modules),
|
||||||
already_patched['select'] = True
|
('time', _green_time_modules),
|
||||||
if on['socket'] and not already_patched.get('socket'):
|
('MySQLdb', _green_MySQLdb),
|
||||||
modules_to_patch += _green_socket_modules()
|
('builtins', _green_builtins),
|
||||||
already_patched['socket'] = True
|
]:
|
||||||
if on['thread'] and not already_patched.get('thread'):
|
if on[name] and not already_patched.get(name):
|
||||||
modules_to_patch += _green_thread_modules()
|
modules_to_patch += modules_function()
|
||||||
already_patched['thread'] = True
|
already_patched[name] = 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
|
|
||||||
if on['psycopg'] and not already_patched.get('psycopg'):
|
if on['psycopg'] and not already_patched.get('psycopg'):
|
||||||
try:
|
try:
|
||||||
from eventlet.support import psycopg2_patcher
|
from eventlet.support import psycopg2_patcher
|
||||||
|
Reference in New Issue
Block a user