X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=eventlet%2Feventlet%2Fgreen%2Furllib.py;fp=eventlet%2Feventlet%2Fgreen%2Furllib.py;h=f5c8f137db5a6ad9b774465743cc230565bd6751;hb=a7790d9c6e32b6ce02cf489d91c232e7b4d31161;hp=0000000000000000000000000000000000000000;hpb=70992db4bef26426213a8eae488be377cdd655ae;p=packages%2Ftrusty%2Fpython-eventlet.git diff --git a/eventlet/eventlet/green/urllib.py b/eventlet/eventlet/green/urllib.py new file mode 100644 index 0000000..f5c8f13 --- /dev/null +++ b/eventlet/eventlet/green/urllib.py @@ -0,0 +1,38 @@ +from eventlet import patcher +from eventlet.green import socket +from eventlet.green import time +from eventlet.green import httplib +from eventlet.green import ftplib + +to_patch = [('socket', socket), ('httplib', httplib), + ('time', time), ('ftplib', ftplib)] +try: + from eventlet.green import ssl + to_patch.append(('ssl', ssl)) +except ImportError: + pass + +patcher.inject('urllib', globals(), *to_patch) +try: + URLopener +except NameError: + patcher.inject('urllib.request', globals(), *to_patch) + + +# patch a bunch of things that have imports inside the +# function body; this is lame and hacky but I don't feel +# too bad because urllib is a hacky pile of junk that no +# one should be using anyhow +URLopener.open_http = patcher.patch_function(URLopener.open_http, ('httplib', httplib)) +if hasattr(URLopener, 'open_https'): + URLopener.open_https = patcher.patch_function(URLopener.open_https, ('httplib', httplib)) + +URLopener.open_ftp = patcher.patch_function(URLopener.open_ftp, ('ftplib', ftplib)) +ftpwrapper.init = patcher.patch_function(ftpwrapper.init, ('ftplib', ftplib)) +ftpwrapper.retrfile = patcher.patch_function(ftpwrapper.retrfile, ('ftplib', ftplib)) + +del patcher + +# Run test program when run as a script +if __name__ == '__main__': + main()