1from eventlet import patcher
2from eventlet.green import ftplib, http, os, socket, time
3from eventlet.green.http import client as http_client
4from eventlet.green.urllib import error, parse, response
5
6# TODO should we also have green email version?
7# import email
8
9
10to_patch = [
11    # This (http module) is needed here, otherwise test__greenness hangs
12    # forever on Python 3 because parts of non-green http (including
13    # http.client) leak into our patched urllib.request. There may be a nicer
14    # way to handle this (I didn't dig too deep) but this does the job. Jakub
15    ('http', http),
16
17    ('http.client', http_client),
18    ('os', os),
19    ('socket', socket),
20    ('time', time),
21    ('urllib.error', error),
22    ('urllib.parse', parse),
23    ('urllib.response', response),
24]
25
26try:
27    from eventlet.green import ssl
28except ImportError:
29    pass
30else:
31    to_patch.append(('ssl', ssl))
32
33patcher.inject('urllib.request', globals(), *to_patch)
34del to_patch
35
36to_patch_in_functions = [('ftplib', ftplib)]
37del ftplib
38
39FTPHandler.ftp_open = patcher.patch_function(FTPHandler.ftp_open, *to_patch_in_functions)
40URLopener.open_ftp = patcher.patch_function(URLopener.open_ftp, *to_patch_in_functions)
41
42ftperrors = patcher.patch_function(ftperrors, *to_patch_in_functions)
43
44ftpwrapper.init = patcher.patch_function(ftpwrapper.init, *to_patch_in_functions)
45ftpwrapper.retrfile = patcher.patch_function(ftpwrapper.retrfile, *to_patch_in_functions)
46
47del error
48del parse
49del response
50del to_patch_in_functions
51