Add python-eventlet package to MOS 8.0 repository
[packages/trusty/python-eventlet.git] / python-eventlet / eventlet / green / urllib / __init__.py
1 from eventlet import patcher
2 from eventlet.green import socket
3 from eventlet.green import time
4 from eventlet.green import httplib
5 from eventlet.green import ftplib
6 from eventlet.support import six
7
8 if six.PY2:
9     to_patch = [('socket', socket), ('httplib', httplib),
10                 ('time', time), ('ftplib', ftplib)]
11     try:
12         from eventlet.green import ssl
13         to_patch.append(('ssl', ssl))
14     except ImportError:
15         pass
16
17     patcher.inject('urllib', globals(), *to_patch)
18     try:
19         URLopener
20     except NameError:
21         patcher.inject('urllib.request', globals(), *to_patch)
22
23
24     # patch a bunch of things that have imports inside the
25     # function body; this is lame and hacky but I don't feel
26     # too bad because urllib is a hacky pile of junk that no
27     # one should be using anyhow
28     URLopener.open_http = patcher.patch_function(URLopener.open_http, ('httplib', httplib))
29     if hasattr(URLopener, 'open_https'):
30         URLopener.open_https = patcher.patch_function(URLopener.open_https, ('httplib', httplib))
31
32     URLopener.open_ftp = patcher.patch_function(URLopener.open_ftp, ('ftplib', ftplib))
33     ftpwrapper.init = patcher.patch_function(ftpwrapper.init, ('ftplib', ftplib))
34     ftpwrapper.retrfile = patcher.patch_function(ftpwrapper.retrfile, ('ftplib', ftplib))
35
36     del patcher
37
38     # Run test program when run as a script
39     if __name__ == '__main__':
40         main()