Code import
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
from eventlet import patcher
|
||||
from eventlet.green import socket
|
||||
from eventlet.green import time
|
||||
from eventlet.green import httplib
|
||||
from eventlet.green import ftplib
|
||||
from eventlet.support import six
|
||||
|
||||
if six.PY2:
|
||||
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()
|
||||
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
from eventlet import patcher
|
||||
from eventlet.green.urllib import response
|
||||
patcher.inject('urllib.error', globals(), ('urllib.response', response))
|
||||
del patcher
|
||||
BIN
venv/lib/python2.7/site-packages/eventlet/green/urllib/error.pyc
Normal file
BIN
venv/lib/python2.7/site-packages/eventlet/green/urllib/error.pyc
Normal file
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
from eventlet import patcher
|
||||
patcher.inject('urllib.parse', globals())
|
||||
del patcher
|
||||
BIN
venv/lib/python2.7/site-packages/eventlet/green/urllib/parse.pyc
Normal file
BIN
venv/lib/python2.7/site-packages/eventlet/green/urllib/parse.pyc
Normal file
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
from eventlet import patcher
|
||||
from eventlet.green import ftplib, http, os, socket, time
|
||||
from eventlet.green.http import client as http_client
|
||||
from eventlet.green.urllib import error, parse, response
|
||||
|
||||
# TODO should we also have green email version?
|
||||
# import email
|
||||
|
||||
|
||||
to_patch = [
|
||||
# This (http module) is needed here, otherwise test__greenness hangs
|
||||
# forever on Python 3 because parts of non-green http (including
|
||||
# http.client) leak into our patched urllib.request. There may be a nicer
|
||||
# way to handle this (I didn't dig too deep) but this does the job. Jakub
|
||||
('http', http),
|
||||
|
||||
('http.client', http_client),
|
||||
('os', os),
|
||||
('socket', socket),
|
||||
('time', time),
|
||||
('urllib.error', error),
|
||||
('urllib.parse', parse),
|
||||
('urllib.response', response),
|
||||
]
|
||||
|
||||
try:
|
||||
from eventlet.green import ssl
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
to_patch.append(('ssl', ssl))
|
||||
|
||||
patcher.inject('urllib.request', globals(), *to_patch)
|
||||
del to_patch
|
||||
|
||||
to_patch_in_functions = [('ftplib', ftplib)]
|
||||
del ftplib
|
||||
|
||||
FTPHandler.ftp_open = patcher.patch_function(FTPHandler.ftp_open, *to_patch_in_functions)
|
||||
URLopener.open_ftp = patcher.patch_function(URLopener.open_ftp, *to_patch_in_functions)
|
||||
|
||||
ftperrors = patcher.patch_function(ftperrors, *to_patch_in_functions)
|
||||
|
||||
ftpwrapper.init = patcher.patch_function(ftpwrapper.init, *to_patch_in_functions)
|
||||
ftpwrapper.retrfile = patcher.patch_function(ftpwrapper.retrfile, *to_patch_in_functions)
|
||||
|
||||
del error
|
||||
del parse
|
||||
del response
|
||||
del to_patch_in_functions
|
||||
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
from eventlet import patcher
|
||||
patcher.inject('urllib.response', globals())
|
||||
del patcher
|
||||
Binary file not shown.
Reference in New Issue
Block a user