Esempio n. 1
0
from eventlet import patcher
from eventlet.green import os, time, select, socket, SocketServer, subprocess
from eventlet.green.http import client
from eventlet.green.urllib import parse as urllib_parse

patcher.inject('http.server', globals(), ('http.client', client), ('os', os),
               ('select', select), ('socket', socket),
               ('socketserver', SocketServer), ('time', time),
               ('urllib.parse', urllib_parse))

CGIHTTPRequestHandler.run_cgi = patcher.patch_function(
    CGIHTTPRequestHandler.run_cgi, ('subprocess', subprocess))

del urllib_parse
del client
del patcher
Esempio n. 2
0
    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()
Esempio n. 3
0
from eventlet import patcher
from eventlet.green import socket
from eventlet.green import urllib2

patcher.inject('test.test_urllib2',
    globals(),
    ('socket', socket),
    ('urllib2', urllib2))

HandlerTests.test_file = patcher.patch_function(HandlerTests.test_file, ('socket', socket))
HandlerTests.test_cookie_redirect = patcher.patch_function(HandlerTests.test_cookie_redirect, ('urllib2', urllib2))
OpenerDirectorTests.test_badly_named_methods = patcher.patch_function(OpenerDirectorTests.test_badly_named_methods, ('urllib2', urllib2))

if __name__ == "__main__":
    test_main()
Esempio n. 4
0
from eventlet import patcher
from eventlet.green import ftplib
from eventlet.green import httplib
from eventlet.green import socket
from eventlet.green import time
from eventlet.green import urllib

patcher.inject('urllib2',
    globals(),
    ('httplib', httplib),
    ('socket', socket),
    ('time', time),
    ('urllib', urllib))

FTPHandler.ftp_open = patcher.patch_function(FTPHandler.ftp_open, ('ftplib', ftplib))

del patcher
Esempio n. 5
0
]

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
Esempio n. 6
0
from eventlet import patcher
from eventlet.green import ftplib
from eventlet.green import httplib
from eventlet.green import socket
from eventlet.green import time
from eventlet.green import urllib

patcher.inject('urllib2', globals(), ('httplib', httplib), ('socket', socket),
               ('time', time), ('urllib', urllib))

FTPHandler.ftp_open = patcher.patch_function(FTPHandler.ftp_open,
                                             ('ftplib', ftplib))

del patcher
Esempio n. 7
0
from eventlet import patcher
from eventlet.green import time

patcher.inject('http.cookies', globals())
_getdate = patcher.patch_function(_getdate, ('time', time))

del patcher
Esempio n. 8
0
    ('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
Esempio n. 9
0
    if resource == 'network':
        return True
    else:
        return i_r_e(resource)


test.test_support.is_resource_enabled = is_resource_enabled

try:
    socket.ssl
    socket.sslerror
except AttributeError:
    raise ImportError("Socket module doesn't support ssl")

patcher.inject('test.test_socket_ssl', globals())

test_basic = patcher.patch_function(test_basic)
test_rude_shutdown = patcher.patch_function(test_rude_shutdown)


def test_main():
    if not hasattr(socket, "ssl"):
        raise test_support.TestSkipped("socket module has no ssl support")
    test_rude_shutdown()
    test_basic()
    test_timeout()


if __name__ == "__main__":
    test_main()
Esempio n. 10
0
import test.test_support
i_r_e = test.test_support.is_resource_enabled
def is_resource_enabled(resource):
    if resource == 'network':
        return True
    else:
        return i_r_e(resource)
test.test_support.is_resource_enabled = is_resource_enabled

try:
    socket.ssl
    socket.sslerror
except AttributeError:
    raise ImportError("Socket module doesn't support ssl")

patcher.inject('test.test_socket_ssl', globals())

test_basic = patcher.patch_function(test_basic)
test_rude_shutdown = patcher.patch_function(test_rude_shutdown)

def test_main():
    if not hasattr(socket, "ssl"):
        raise test_support.TestSkipped("socket module has no ssl support")
    test_rude_shutdown()
    test_basic()
    test_timeout()


if __name__ == "__main__":
    test_main()
Esempio n. 11
0
from eventlet import patcher
from eventlet.green import os, time, select, socket, SocketServer, subprocess
from eventlet.green.http import client
from eventlet.green.urllib import parse as urllib_parse

patcher.inject('http.server', globals(),
               ('http.client', client), ('os', os), ('select', select),
               ('socket', socket), ('socketserver', SocketServer), ('time', time),
               ('urllib.parse', urllib_parse))


CGIHTTPRequestHandler.run_cgi = patcher.patch_function(
    CGIHTTPRequestHandler.run_cgi, ('subprocess', subprocess))

del urllib_parse
del client
del patcher