コード例 #1
0
ファイル: ftplib.py プロジェクト: PlumpMath/evy
# in the Software without restriction, including without limitation the rights
# 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

# *NOTE: there might be some funny business with the "SOCKS" module
# if it even still exists
from evy.patched import socket

patcher.inject('ftplib', globals(), ('socket', socket))

del patcher

# Run test program when run as a script
if __name__ == '__main__':
    test()
コード例 #2
0
ファイル: urllib.py プロジェクト: inercia/evy
from evy import patcher
from evy.patched import socket
from evy.patched import time
from evy.patched import httplib
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
コード例 #3
0
ファイル: test_socketserver.py プロジェクト: PlumpMath/evy
#!/usr/bin/env python

from evy import patcher
from evy.patched import SocketServer
from evy.patched import socket
from evy.patched import select
from evy.patched import time
from evy.patched import threading

# to get past the silly 'requires' check
from test import test_support

test_support.use_resources = ['network']

patcher.inject('test.test_socketserver', globals(),
               ('SocketServer', SocketServer), ('socket', socket),
               ('select', select), ('time', time), ('threading', threading))

# only a problem with pyevent
from evy import tests

if tests.using_pyevent():
    try:
        SocketServerTest.test_ForkingUDPServer = lambda *a, **kw: None
        SocketServerTest.test_ForkingTCPServer = lambda *a, **kw: None
        SocketServerTest.test_ForkingUnixStreamServer = lambda *a, **kw: None
    except (NameError, AttributeError):
        pass

if __name__ == "__main__":
    test_main()
コード例 #4
0
ファイル: test_subprocess.py プロジェクト: inercia/evy
from evy import patcher
from evy.patched import subprocess
from evy.patched import time

patcher.inject('test.test_subprocess',
               globals(),
               ('subprocess', subprocess),
               ('time', time))

if __name__ == "__main__":
    test_main()
コード例 #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 BaseHTTPServer
from evy.patched import urllib

patcher.inject('SimpleHTTPServer',
               globals(),
    ('BaseHTTPServer', BaseHTTPServer),
    ('urllib', urllib))

del patcher

if __name__ == '__main__':
    test()
コード例 #6
0
# in the Software without restriction, including without limitation the rights
# 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 socket
from evy.patched import select
from evy.patched import threading

patcher.inject('SocketServer',
               globals(),
    ('socket', socket),
    ('select', select),
    ('threading', threading))

# QQQ ForkingMixIn should be fixed to use green waitpid?
コード例 #7
0
ファイル: test_subprocess.py プロジェクト: PlumpMath/evy
from evy import patcher
from evy.patched import subprocess
from evy.patched import time

patcher.inject('test.test_subprocess', globals(), ('subprocess', subprocess),
               ('time', time))

if __name__ == "__main__":
    test_main()
コード例 #8
0
ファイル: asynchat.py プロジェクト: inercia/evy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# 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 asyncore
from evy.patched import socket

patcher.inject('asynchat',
               globals(),
    ('asyncore', asyncore),
    ('socket', socket))

del patcher
コード例 #9
0
ファイル: test_httplib.py プロジェクト: inercia/evy
from evy import patcher
from evy.patched import httplib
from evy.patched import socket

patcher.inject("test.test_httplib", globals(), ("httplib", httplib), ("socket", socket))

if __name__ == "__main__":
    test_main()
コード例 #10
0
from evy import patcher
from evy.patched import asyncore
from evy.patched import asynchat
from evy.patched import socket
from evy.patched import thread
from evy.patched import threading
from evy.patched import time

patcher.inject("test.test_asynchat", globals(), ('asyncore', asyncore),
               ('asynchat', asynchat), ('socket', socket), ('thread', thread),
               ('threading', threading), ('time', time))

if __name__ == "__main__":
    test_main()
コード例 #11
0
ファイル: test_ftplib.py プロジェクト: inercia/evy
from evy import patcher
from evy.patched import asyncore
from evy.patched import ftplib
from evy.patched import threading
from evy.patched import socket

patcher.inject("test.test_ftplib", globals())

# this test only fails on python2.7/pyevent/--with-xunit; screw that
try:
    TestTLS_FTPClass.test_data_connection = lambda *a, **kw: None
except (AttributeError, NameError):
    pass

if __name__ == "__main__":
    test_main()
コード例 #12
0
ファイル: urllib2.py プロジェクト: inercia/evy
# 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
コード例 #13
0
ファイル: test_ssl.py プロジェクト: inercia/evy

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

patcher.inject('test.test_ssl',
               globals(),
               ('asyncore', asyncore),
               ('BaseHTTPServer', BaseHTTPServer),
               ('select', select),
               ('socket', socket),
               ('SocketServer', SocketServer),
               ('ssl', ssl),
               ('threading', threading),
               ('urllib', urllib))


# TODO svn.python.org stopped serving up the cert that these tests expect; 
# presumably they've updated svn trunk but the tests in released versions will
# probably break forever. This is why you don't write tests that connect to 
# external servers.
NetworkedTests.testConnect = lambda s: None
NetworkedTests.testFetchServerCert = lambda s: None
NetworkedTests.test_algorithms = lambda s: None

# these don't pass because nonblocking ssl sockets don't report
コード例 #14
0
from evy import patcher

from evy.patched import BaseHTTPServer
from evy.patched import threading
from evy.patched import socket
from evy.patched import urllib2

patcher.inject('test.test_urllib2_localnet', globals(),
               ('BaseHTTPServer', BaseHTTPServer), ('threading', threading),
               ('socket', socket), ('urllib2', urllib2))

if __name__ == "__main__":
    test_main()
コード例 #15
0
ファイル: test_select.py プロジェクト: inercia/evy
from evy import patcher
from evy.patched import select

patcher.inject('test.test_select',
               globals(),
               ('select', select))

if __name__ == "__main__":
    try:
        test_main()
    except NameError:
        pass # 2.5
コード例 #16
0
# 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 BaseHTTPServer
from evy.patched import SimpleHTTPServer
from evy.patched import urllib
from evy.patched import select

test = None # bind prior to patcher.inject to silence pyflakes warning below
patcher.inject('CGIHTTPServer',
               globals(),
    ('BaseHTTPServer', BaseHTTPServer),
    ('SimpleHTTPServer', SimpleHTTPServer),
    ('urllib', urllib),
    ('select', select))

del patcher

if __name__ == '__main__':
    test() # pyflakes false alarm here unless test = None above
コード例 #17
0
ファイル: test_httplib.py プロジェクト: PlumpMath/evy
from evy import patcher
from evy.patched import httplib
from evy.patched import socket

patcher.inject('test.test_httplib',
               globals(),
               ('httplib', httplib),
               ('socket', socket))

if __name__ == "__main__":
    test_main()
コード例 #18
0
ファイル: test_queue.py プロジェクト: inercia/evy
from evy import patcher
from evy.patched import Queue
from evy.patched import threading
from evy.patched import time

patcher.inject('test.test_queue',
               globals(),
               ('Queue', Queue),
               ('threading', threading),
               ('time', time))

if __name__ == "__main__":
    test_main()
コード例 #19
0
ファイル: threading.py プロジェクト: inercia/evy
    "_allocate_lock",
    "_get_ident",
    "_sleep",
    "local",
    "stack_size",
    "Lock",
    "currentThread",
    "current_thread",
    "_after_fork",
    "_shutdown",
]

__orig_threading = patcher.original("threading")
__threadlocal = __orig_threading.local()

patcher.inject("threading", globals(), ("thread", thread), ("time", time))

del patcher

_count = 1


class _GreenThread(object):
    """Wrapper for GreenThread objects to provide Thread-like attributes
    and methods"""

    def __init__(self, g):
        global _count
        self._g = g
        self._name = "GreenThread-%d" % _count
        _count += 1
コード例 #20
0
ファイル: test_SimpleHTTPServer.py プロジェクト: inercia/evy
from evy import patcher
from evy.patched import SimpleHTTPServer

patcher.inject('test.test_SimpleHTTPServer',
               globals(),
               ('SimpleHTTPServer', SimpleHTTPServer))

if __name__ == "__main__":
    test_main()
コード例 #21
0
ファイル: test_timeout.py プロジェクト: PlumpMath/evy
from evy import patcher
from evy.patched import socket
from evy.patched import time

patcher.inject('test.test_timeout', globals(), ('socket', socket),
               ('time', time))

# to get past the silly 'requires' check
from test import test_support

test_support.use_resources = ['network']

if __name__ == "__main__":
    test_main()
コード例 #22
0
ファイル: urllib2.py プロジェクト: PlumpMath/evy
# 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
コード例 #23
0
from evy import patcher
from evy.patched import thread
from evy.patched import threading
from evy.patched import time

# hub requires initialization before test can run
from evy import hubs

hubs.get_hub()

patcher.inject('test.test_threading_local', globals(), ('time', time),
               ('thread', thread), ('threading', threading))

if __name__ == '__main__':
    test_main()
コード例 #24
0
ファイル: httplib.py プロジェクト: inercia/evy
# 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 socket

to_patch = [('socket', socket)]

try:
    from evy.patched import ssl

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

patcher.inject('httplib',
               globals(),
               *to_patch)

if __name__ == '__main__':
    test()
コード例 #25
0
ファイル: test_urllib2.py プロジェクト: PlumpMath/evy
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()
コード例 #26
0
ファイル: urllib.py プロジェクト: PlumpMath/evy
from evy import patcher
from evy.patched import socket
from evy.patched import time
from evy.patched import httplib
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,
コード例 #27
0
ファイル: asyncore.py プロジェクト: PlumpMath/evy
# Copyright (c) 2005-2006, Bob Ippolito
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# 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 select
from evy.patched import socket
from evy.patched import time

patcher.inject("asyncore", globals(), ('select', select), ('socket', socket),
               ('time', time))

del patcher
コード例 #28
0
ファイル: test_timeout.py プロジェクト: inercia/evy
from evy import patcher
from evy.patched import socket
from evy.patched import time

patcher.inject('test.test_timeout',
               globals(),
               ('socket', socket),
               ('time', time))

# to get past the silly 'requires' check
from test import test_support

test_support.use_resources = ['network']

if __name__ == "__main__":
    test_main()
コード例 #29
0
# Copyright (c) 2007-2010, Linden Research, Inc.
# Copyright (c) 2005-2006, Bob Ippolito
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# 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 asyncore
from evy.patched import socket

patcher.inject('asynchat', globals(), ('asyncore', asyncore),
               ('socket', socket))

del patcher
コード例 #30
0
# 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.
#


import errno
import new

import evy
from evy.io.pipes import GreenPipe
from evy import patcher
from evy.patched import os
from evy.patched import select

patcher.inject('subprocess', globals(), ('select', select))
subprocess_orig = __import__("subprocess")


# This is the meat of this module, the green version of Popen.
class Popen(subprocess_orig.Popen):
    """
    evy-friendly version of subprocess.Popen
    """

    # We do not believe that Windows pipes support non-blocking I/O. At least,
    # the Python file objects stored on our base-class object have no
    # setblocking() method, and the Python fcntl module doesn't exist on
    # Windows. (see evy.io.sockets.set_nonblocking()) As the sole purpose of
    # this __init__() override is to wrap the pipes for evy-friendly
    # non-blocking I/O, don't even bother overriding it on Windows.
コード例 #31
0
ファイル: test_thread.py プロジェクト: PlumpMath/evy
from evy import patcher
from evy.patched import thread
from evy.patched import time

# necessary to initialize the hub before running on 2.5
from evy import hubs

hubs.get_hub()

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

try:
    # this is a new test in 2.7 that we don't support yet
    TestForkInThread.test_forkinthread = lambda *a, **kw: None
except NameError:
    pass

if __name__ == "__main__":
    try:
        test_main()
    except NameError:
        pass  # 2.5
コード例 #32
0
ファイル: test_urllib.py プロジェクト: PlumpMath/evy
from evy import patcher
from evy.patched import httplib
from evy.patched import urllib

patcher.inject('test.test_urllib', globals(), ('httplib', httplib),
               ('urllib', urllib))

if __name__ == "__main__":
    test_main()
コード例 #33
0
ファイル: test_urllib2_localnet.py プロジェクト: inercia/evy
from evy import patcher

from evy.patched import BaseHTTPServer
from evy.patched import threading
from evy.patched import socket
from evy.patched import urllib2

patcher.inject('test.test_urllib2_localnet',
               globals(),
               ('BaseHTTPServer', BaseHTTPServer),
               ('threading', threading),
               ('socket', socket),
               ('urllib2', urllib2))

if __name__ == "__main__":
    test_main()
コード例 #34
0
ファイル: test_threading_local.py プロジェクト: inercia/evy
from evy import patcher
from evy.patched import thread
from evy.patched import threading
from evy.patched import time

# hub requires initialization before test can run
from evy import hubs

hubs.get_hub()

patcher.inject('test.test_threading_local',
               globals(),
               ('time', time),
               ('thread', thread),
               ('threading', threading))

if __name__ == '__main__':
    test_main()
コード例 #35
0
from evy import patcher
from evy.patched import os

patcher.inject('test.test_os', globals(), ('os', os))

if __name__ == "__main__":
    test_main()
コード例 #36
0
from evy import patcher
from evy.patched import thread
from evy.patched import time
from evy.support import greenlets as greenlet

__patched__ = [
    '_start_new_thread', '_allocate_lock', '_get_ident', '_sleep', 'local',
    'stack_size', 'Lock', 'currentThread', 'current_thread', '_after_fork',
    '_shutdown'
]

__orig_threading = patcher.original('threading')
__threadlocal = __orig_threading.local()

patcher.inject('threading', globals(), ('thread', thread), ('time', time))

del patcher

_count = 1


class _GreenThread(object):
    """Wrapper for GreenThread objects to provide Thread-like attributes
    and methods"""
    def __init__(self, g):
        global _count
        self._g = g
        self._name = 'GreenThread-%d' % _count
        _count += 1
コード例 #37
0
ファイル: test_ftplib.py プロジェクト: PlumpMath/evy
from evy import patcher
from evy.patched import asyncore
from evy.patched import ftplib
from evy.patched import threading
from evy.patched import socket

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

# this test only fails on python2.7/pyevent/--with-xunit; screw that
try:
    TestTLS_FTPClass.test_data_connection = lambda *a, **kw: None
except (AttributeError, NameError):
    pass

if __name__ == "__main__":
    test_main()
コード例 #38
0
ファイル: test_socketserver.py プロジェクト: inercia/evy
from evy import patcher
from evy.patched import SocketServer
from evy.patched import socket
from evy.patched import select
from evy.patched import time
from evy.patched import threading

# to get past the silly 'requires' check
from test import test_support

test_support.use_resources = ['network']

patcher.inject('test.test_socketserver',
               globals(),
               ('SocketServer', SocketServer),
               ('socket', socket),
               ('select', select),
               ('time', time),
               ('threading', threading))

# only a problem with pyevent
from evy import tests

if tests.using_pyevent():
    try:
        SocketServerTest.test_ForkingUDPServer = lambda *a, **kw: None
        SocketServerTest.test_ForkingTCPServer = lambda *a, **kw: None
        SocketServerTest.test_ForkingUnixStreamServer = lambda *a, **kw: None
    except (NameError, AttributeError):
        pass
コード例 #39
0
from evy import patcher
from evy.patched import Queue
from evy.patched import threading
from evy.patched import time

patcher.inject('test.test_queue', globals(), ('Queue', Queue),
               ('threading', threading), ('time', time))

if __name__ == "__main__":
    test_main()
コード例 #40
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

patcher.inject('test.test_ssl', globals(), ('asyncore', asyncore),
               ('BaseHTTPServer', BaseHTTPServer), ('select', select),
               ('socket', socket), ('SocketServer', SocketServer),
               ('ssl', ssl), ('threading', threading), ('urllib', urllib))

# TODO svn.python.org stopped serving up the cert that these tests expect;
# presumably they've updated svn trunk but the tests in released versions will
# probably break forever. This is why you don't write tests that connect to
# external servers.
NetworkedTests.testConnect = lambda s: None
NetworkedTests.testFetchServerCert = lambda s: None
NetworkedTests.test_algorithms = lambda s: None

# these don't pass because nonblocking ssl sockets don't report
# when the socket is closed uncleanly, per the docstring on
# evy.green.GreenSSLSocket
# *TODO: fix and restore these tests
ThreadedTests.testProtocolSSL2 = lambda s: None
コード例 #41
0
ファイル: ftplib.py プロジェクト: inercia/evy
# 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

# *NOTE: there might be some funny business with the "SOCKS" module
# if it even still exists
from evy.patched import socket

patcher.inject('ftplib', globals(), ('socket', socket))

del patcher

# Run test program when run as a script
if __name__ == '__main__':
    test()
コード例 #42
0
ファイル: test_select.py プロジェクト: PlumpMath/evy
from evy import patcher
from evy.patched import select

patcher.inject('test.test_select', globals(), ('select', select))

if __name__ == "__main__":
    try:
        test_main()
    except NameError:
        pass  # 2.5
コード例 #43
0
ファイル: test_httpservers.py プロジェクト: inercia/evy
from evy import patcher

from evy.patched import BaseHTTPServer
from evy.patched import SimpleHTTPServer
from evy.patched import CGIHTTPServer
from evy.patched import urllib
from evy.patched import httplib
from evy.patched import threading

patcher.inject('test.test_httpservers',
               globals(),
               ('BaseHTTPServer', BaseHTTPServer),
               ('SimpleHTTPServer', SimpleHTTPServer),
               ('CGIHTTPServer', CGIHTTPServer),
               ('urllib', urllib),
               ('httplib', httplib),
               ('threading', threading))

if __name__ == "__main__":
    test_main()
コード例 #44
0
ファイル: test_urllib2.py プロジェクト: inercia/evy
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()
コード例 #45
0
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# 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 socket
from evy.patched import SocketServer

patcher.inject('BaseHTTPServer', globals(), ('socket', socket),
               ('SocketServer', SocketServer))

del patcher

if __name__ == '__main__':
    test()
コード例 #46
0
#!/usr/bin/env python

from evy import patcher
from evy.patched import socket
from evy.patched import select
from evy.patched import time
from evy.patched import thread
from evy.patched import threading

patcher.inject('test.test_socket',
               globals(),
               ('socket', socket),
               ('select', select),
               ('time', time),
               ('thread', thread),
               ('threading', threading))

# TODO: fix
TCPTimeoutTest.testInterruptedTimeout = lambda *a: None

if __name__ == "__main__":
    test_main()
コード例 #47
0
from evy import patcher
from evy.patched import asyncore
from evy.patched import select
from evy.patched import socket
from evy.patched import threading
from evy.patched import time

patcher.inject("test.test_asyncore", globals())


def new_closeall_check (self, usedefault):
    # Check that close_all() closes everything in a given map

    l = []
    testmap = {}
    for i in range(10):
        c = dummychannel()
        l.append(c)
        self.assertEqual(c.socket.closed, False)
        testmap[i] = c

    if usedefault:
        # the only change we make is to not assign to asyncore.socket_map
        # because doing so fails to assign to the real asyncore's socket_map
        # and thus the test fails
        socketmap = asyncore.socket_map.copy()
        try:
            asyncore.socket_map.clear()
            asyncore.socket_map.update(testmap)
            asyncore.close_all()
        finally:
コード例 #48
0
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()
コード例 #49
0
ファイル: BaseHTTPServer.py プロジェクト: inercia/evy
# 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 socket
from evy.patched import SocketServer

patcher.inject('BaseHTTPServer',
               globals(),
    ('socket', socket),
    ('SocketServer', SocketServer))

del patcher

if __name__ == '__main__':
    test()
コード例 #50
0
from evy import patcher
from evy.patched import SimpleHTTPServer

patcher.inject('test.test_SimpleHTTPServer', globals(),
               ('SimpleHTTPServer', SimpleHTTPServer))

if __name__ == "__main__":
    test_main()
コード例 #51
0
ファイル: test_os.py プロジェクト: inercia/evy
from evy import patcher
from evy.patched import os

patcher.inject('test.test_os',
               globals(),
               ('os', os))

if __name__ == "__main__":
    test_main()
コード例 #52
0
ファイル: test_socket_ssl.py プロジェクト: inercia/evy
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()