Esempio n. 1
0
from evy import patcher
from evy.patched import socket
from evy.patched 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))
try:
    OpenerDirectorTests.test_badly_named_methods = patcher.patch_function(
        OpenerDirectorTests.test_badly_named_methods, ('urllib2', urllib2))
except AttributeError:
    pass  # 2.4 doesn't have this test method

if __name__ == "__main__":
    test_main()
Esempio n. 2
0
from evy import patcher
from evy.patched import socket
from evy.patched 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))
try:
    OpenerDirectorTests.test_badly_named_methods = patcher.patch_function(
        OpenerDirectorTests.test_badly_named_methods, ('urllib2', urllib2))
except AttributeError:
    pass  # 2.4 doesn't have this test method

if __name__ == "__main__":
    test_main()
Esempio n. 3
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. 4
0
to_patch = [('socket', socket), ('httplib', httplib), ('time', time),
            ('ftplib', ftplib)]
try:
    from evy.patched import ssl

    to_patch.append(('ssl', ssl))
except ImportError:
    pass

patcher.inject('urllib', 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. 5
0
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

from evy import patcher
from evy.patched import ftplib
from evy.patched import httplib
from evy.patched import socket
from evy.patched import time
from evy.patched 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. 6
0
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#


from evy import patcher
from evy.patched import ftplib
from evy.patched import httplib
from evy.patched import socket
from evy.patched import time
from evy.patched 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 evy.patched import ftplib

to_patch = [('socket', socket), ('httplib', httplib),
    ('time', time), ('ftplib', ftplib)]
try:
    from evy.patched import ssl

    to_patch.append(('ssl', ssl))
except ImportError:
    pass

patcher.inject('urllib', 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. 8
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()