From b082b38973b475e4ce37f15138766fe23342906e Mon Sep 17 00:00:00 2001 From: Eugene Oden Date: Mon, 22 Feb 2010 18:03:04 -0500 Subject: [PATCH] tweaks to remove some DeprecationWarnings when running tests --- eventlet/__init__.py | 6 +++- eventlet/api.py | 8 +++-- eventlet/coros.py | 32 ++++++++--------- eventlet/util.py | 2 +- tests/debug_test.py | 5 ++- tests/ssl_test.py | 40 +++++++++++++-------- tests/test__pool.py | 26 +++++++------- tests/test__proc.py | 17 ++++----- tests/tpool_test.py | 10 +++--- tests/wsgi_test.py | 82 ++++++++++++++++++++++---------------------- 10 files changed, 124 insertions(+), 104 deletions(-) diff --git a/eventlet/__init__.py b/eventlet/__init__.py index 7aaac7f..1434293 100644 --- a/eventlet/__init__.py +++ b/eventlet/__init__.py @@ -8,11 +8,13 @@ try: from eventlet import timeout from eventlet import patcher from eventlet import greenio + import greenlet sleep = greenthread.sleep spawn = greenthread.spawn spawn_n = greenthread.spawn_n spawn_after = greenthread.spawn_after + kill = greenthread.kill Timeout = timeout.Timeout with_timeout = timeout.with_timeout @@ -27,6 +29,8 @@ try: connect = greenio.connect listen = greenio.listen + + getcurrent = greenlet.getcurrent # deprecated TimeoutError = timeout.Timeout @@ -35,4 +39,4 @@ try: except ImportError: # this is to make Debian packaging easier import traceback - traceback.print_exc() \ No newline at end of file + traceback.print_exc() diff --git a/eventlet/api.py b/eventlet/api.py index 8100e7e..76579e2 100644 --- a/eventlet/api.py +++ b/eventlet/api.py @@ -10,6 +10,7 @@ from eventlet.support import greenlets as greenlet from eventlet import hubs from eventlet import greenthread from eventlet import debug +from eventlet import Timeout __all__ = [ 'call_after', 'exc_after', 'getcurrent', 'get_default_hub', 'get_hub', @@ -68,8 +69,11 @@ def ssl_listener(address, certificate, private_key): accept a connection on the newly bound socket. """ from eventlet import util - socket = util.wrap_ssl(util.tcp_socket(), certificate, private_key, True) - util.socket_bind_and_listen(socket, address) + import socket + + socket = util.wrap_ssl(socket.socket(), certificate, private_key, True) + socket.bind(address) + socket.listen(50) return socket def connect_tcp(address, localaddr=None): diff --git a/eventlet/coros.py b/eventlet/coros.py index 16eacff..8bbf716 100644 --- a/eventlet/coros.py +++ b/eventlet/coros.py @@ -3,7 +3,7 @@ import time import traceback import warnings -from eventlet import api +import eventlet from eventlet import event as _event from eventlet import hubs from eventlet import greenthread @@ -62,8 +62,8 @@ class metaphore(object): ... print "%s decrementing" % id ... count.dec() ... - >>> _ = api.spawn(decrementer, count, 'A') - >>> _ = api.spawn(decrementer, count, 'B') + >>> _ = eventlet.spawn(decrementer, count, 'A') + >>> _ = eventlet.spawn(decrementer, count, 'B') >>> count.inc(2) >>> count.wait() A decrementing @@ -174,17 +174,17 @@ class Queue(object): if exc is None: return result else: - api.getcurrent().throw(*exc) + eventlet.getcurrent().throw(*exc) else: - self._waiters.add(api.getcurrent()) + self._waiters.add(eventlet.getcurrent()) try: result, exc = hubs.get_hub().switch() if exc is None: return result else: - api.getcurrent().throw(*exc) + eventlet.getcurrent().throw(*exc) finally: - self._waiters.discard(api.getcurrent()) + self._waiters.discard(eventlet.getcurrent()) def ready(self): return len(self.items) > 0 @@ -227,7 +227,7 @@ class Channel(object): def send(self, result=None, exc=None): if exc is not None and not isinstance(exc, tuple): exc = (exc, ) - if api.getcurrent() is hubs.get_hub().greenlet: + if eventlet.getcurrent() is hubs.get_hub().greenlet: self.items.append((result, exc)) if self._waiters: hubs.get_hub().schedule_call_global(0, self._do_switch) @@ -238,11 +238,11 @@ class Channel(object): if self._waiters: hubs.get_hub().schedule_call_global(0, self._do_switch) if len(self.items) > self.max_size: - self._senders.add(api.getcurrent()) + self._senders.add(eventlet.getcurrent()) try: hubs.get_hub().switch() finally: - self._senders.discard(api.getcurrent()) + self._senders.discard(eventlet.getcurrent()) def send_exception(self, *args): # the arguments are the same as for greenlet.throw @@ -274,19 +274,19 @@ class Channel(object): if exc is None: return result else: - api.getcurrent().throw(*exc) + eventlet.getcurrent().throw(*exc) else: if self._senders: hubs.get_hub().schedule_call_global(0, self._do_switch) - self._waiters.add(api.getcurrent()) + self._waiters.add(eventlet.getcurrent()) try: result, exc = hubs.get_hub().switch() if exc is None: return result else: - api.getcurrent().throw(*exc) + eventlet.getcurrent().throw(*exc) finally: - self._waiters.discard(api.getcurrent()) + self._waiters.discard(eventlet.getcurrent()) def ready(self): return len(self.items) > 0 @@ -332,7 +332,7 @@ class Actor(object): self._mailbox = collections.deque() self._event = _event.Event() - self._killer = api.spawn(self.run_forever) + self._killer = eventlet.spawn(self.run_forever) from eventlet import greenpool self._pool = greenpool.GreenPool(concurrency) @@ -394,7 +394,7 @@ class Actor(object): received message 2 received message 3 - >>> api.kill(a._killer) # test cleanup + >>> eventlet.kill(a._killer) # test cleanup """ raise NotImplementedError() diff --git a/eventlet/util.py b/eventlet/util.py index a5ff43d..4c86ef2 100644 --- a/eventlet/util.py +++ b/eventlet/util.py @@ -26,7 +26,7 @@ def g_log(*args): __original_socket__ = socket.socket def tcp_socket(): - warnings.warn("eventlet.util.tcp_sockt is deprecated." + warnings.warn("eventlet.util.tcp_socket is deprecated." "Please use the standard socket technique for this instead:" "sock = socket.socket()", DeprecationWarning, stacklevel=2) diff --git a/tests/debug_test.py b/tests/debug_test.py index db5e329..40af038 100644 --- a/tests/debug_test.py +++ b/tests/debug_test.py @@ -2,7 +2,6 @@ import sys import eventlet from eventlet import debug -from eventlet import api from tests import LimitedTestCase, main from unittest import TestCase @@ -103,8 +102,8 @@ class TestDebug(LimitedTestCase): def test_hub_exceptions(self): debug.hub_exceptions(True) - server = api.tcp_listener(('0.0.0.0', 0)) - client = api.connect_tcp(('127.0.0.1', server.getsockname()[1])) + server = eventlet.listen(('0.0.0.0', 0)) + client = eventlet.connect(('127.0.0.1', server.getsockname()[1])) client_2, addr = server.accept() def hurl(s): diff --git a/tests/ssl_test.py b/tests/ssl_test.py index b2a2e27..7c5ad3d 100644 --- a/tests/ssl_test.py +++ b/tests/ssl_test.py @@ -1,23 +1,34 @@ from tests import skipped, LimitedTestCase, skip_unless from unittest import main -from eventlet import api, util, coros, greenio +import eventlet +from eventlet import util, coros, greenio import socket import os certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt') private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key') +def listen_ssl_socket(address=('127.0.0.1', 0)): + sock = util.wrap_ssl(socket.socket(), certificate_file, + private_key_file, True) + sock.bind(address) + sock.listen(50) + + return sock + + class SSLTest(LimitedTestCase): def test_duplex_response(self): def serve(listener): sock, addr = listener.accept() stuff = sock.read(8192) sock.write('response') - - sock = api.ssl_listener(('127.0.0.1', 0), certificate_file, private_key_file) - server_coro = coros.execute(serve, sock) + + sock = listen_ssl_socket() + + server_coro = eventlet.spawn(serve, sock) - client = util.wrap_ssl(api.connect_tcp(('127.0.0.1', sock.getsockname()[1]))) + client = util.wrap_ssl(eventlet.connect(('127.0.0.1', sock.getsockname()[1]))) client.write('line 1\r\nline 2\r\n\r\n') self.assertEquals(client.read(8192), 'response') server_coro.wait() @@ -31,10 +42,11 @@ class SSLTest(LimitedTestCase): except greenio.SSL.ZeroReturnError: pass - sock = api.ssl_listener(('127.0.0.1', 0), certificate_file, private_key_file) - server_coro = coros.execute(serve, sock) + sock = listen_ssl_socket() + + server_coro = eventlet.spawn(serve, sock) - raw_client = api.connect_tcp(('127.0.0.1', sock.getsockname()[1])) + raw_client = eventlet.connect(('127.0.0.1', sock.getsockname()[1])) client = util.wrap_ssl(raw_client) client.write('X') greenio.shutdown_safe(client) @@ -45,8 +57,8 @@ class SSLTest(LimitedTestCase): def serve(listener): sock, addr = listener.accept() stuff = sock.read(8192) - sock = api.ssl_listener(('127.0.0.1', 0), certificate_file, private_key_file) - server_coro = coros.execute(serve, sock) + sock = listen_ssl_socket() + server_coro = eventlet.spawn(serve, sock) raw_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ssl_client = util.wrap_ssl(raw_client) @@ -71,12 +83,10 @@ class SocketSSLTest(LimitedTestCase): sock.write('content') greenio.shutdown_safe(sock) sock.close() - listener = api.ssl_listener(('', 0), - certificate_file, - private_key_file) - killer = api.spawn(serve, listener) + listener = listen_ssl_socket(('', 0)) + killer = eventlet.spawn(serve, listener) from eventlet.green.socket import ssl - client = ssl(api.connect_tcp(('localhost', listener.getsockname()[1]))) + client = ssl(eventlet.connect(('localhost', listener.getsockname()[1]))) self.assertEquals(client.read(1024), 'content') self.assertEquals(client.read(1024), '') diff --git a/tests/test__pool.py b/tests/test__pool.py index 8b6c0e1..1f900a8 100644 --- a/tests/test__pool.py +++ b/tests/test__pool.py @@ -1,4 +1,6 @@ +import eventlet from eventlet import pool, coros, api, hubs, timeout +from eventlet import event as _event from tests import LimitedTestCase from unittest import main @@ -6,7 +8,7 @@ class TestCoroutinePool(LimitedTestCase): klass = pool.Pool def test_execute_async(self): - done = coros.Event() + done = _event.Event() def some_work(): done.send() pool = self.klass(0, 2) @@ -23,7 +25,7 @@ class TestCoroutinePool(LimitedTestCase): def test_waiting(self): pool = self.klass(0,1) - done = coros.Event() + done = _event.Event() def consume(): done.wait() def waiter(pool): @@ -31,13 +33,13 @@ class TestCoroutinePool(LimitedTestCase): evt.wait() waiters = [] - waiters.append(coros.execute(waiter, pool)) + waiters.append(eventlet.spawn(waiter, pool)) api.sleep(0) self.assertEqual(pool.waiting(), 0) - waiters.append(coros.execute(waiter, pool)) + waiters.append(eventlet.spawn(waiter, pool)) api.sleep(0) self.assertEqual(pool.waiting(), 1) - waiters.append(coros.execute(waiter, pool)) + waiters.append(eventlet.spawn(waiter, pool)) api.sleep(0) self.assertEqual(pool.waiting(), 2) done.send(None) @@ -46,7 +48,7 @@ class TestCoroutinePool(LimitedTestCase): self.assertEqual(pool.waiting(), 0) def test_multiple_coros(self): - evt = coros.Event() + evt = _event.Event() results = [] def producer(): results.append('prod') @@ -86,7 +88,7 @@ class TestCoroutinePool(LimitedTestCase): outer_waiter = pool.execute(reenter) outer_waiter.wait() - evt = coros.Event() + evt = _event.Event() def reenter_async(): pool.execute_async(lambda a: a, 'reenter') evt.send('done') @@ -97,9 +99,9 @@ class TestCoroutinePool(LimitedTestCase): def assert_pool_has_free(self, pool, num_free): def wait_long_time(e): e.wait() - timer = api.exc_after(1, api.TimeoutError) + timer = timeout.Timeout(1, api.TimeoutError) try: - evt = coros.Event() + evt = _event.Event() for x in xrange(num_free): pool.execute(wait_long_time, evt) # if the pool has fewer free than we expect, @@ -109,7 +111,7 @@ class TestCoroutinePool(LimitedTestCase): # if the runtime error is not raised it means the pool had # some unexpected free items - timer = api.exc_after(0, RuntimeError) + timer = timeout.Timeout(0, RuntimeError) self.assertRaises(RuntimeError, pool.execute, wait_long_time, evt) # clean up by causing all the wait_long_time functions to return @@ -119,7 +121,7 @@ class TestCoroutinePool(LimitedTestCase): def test_resize(self): pool = self.klass(max_size=2) - evt = coros.Event() + evt = _event.Event() def wait_long_time(e): e.wait() pool.execute(wait_long_time, evt) @@ -203,7 +205,7 @@ class TestCoroutinePool(LimitedTestCase): tp = pools.TokenPool(max_size=1) token = tp.get() # empty pool def do_receive(tp): - api.exc_after(0, RuntimeError()) + timeout.Timeout(0, RuntimeError()) try: t = tp.get() self.fail("Shouldn't have recieved anything from the pool") diff --git a/tests/test__proc.py b/tests/test__proc.py index 8ffdc0b..b244752 100644 --- a/tests/test__proc.py +++ b/tests/test__proc.py @@ -2,6 +2,7 @@ import sys import unittest from eventlet.api import sleep, with_timeout from eventlet import api, proc, coros +from eventlet import event as _event from tests import LimitedTestCase, skipped DELAY = 0.01 @@ -61,12 +62,12 @@ class TestProc(LimitedTestCase): def test_event(self): p = proc.spawn(lambda : 100) - event = coros.Event() + event = _event.Event() p.link(event) self.assertEqual(event.wait(), 100) for i in xrange(3): - event2 = coros.Event() + event2 = _event.Event() p.link(event2) self.assertEqual(event2.wait(), 100) @@ -86,7 +87,7 @@ class TestCase(LimitedTestCase): self.p.unlink() def set_links(self, p, first_time, kill_exc_type): - event = coros.Event() + event = _event.Event() self.link(p, event) proc_flag = [] @@ -111,13 +112,13 @@ class TestCase(LimitedTestCase): self.link(p, lambda *args: callback_flag.remove('initial')) for _ in range(10): - self.link(p, coros.Event()) + self.link(p, _event.Event()) self.link(p, coros.queue(1)) return event, receiver, proc_flag, queue, callback_flag def set_links_timeout(self, link): # stuff that won't be touched - event = coros.Event() + event = _event.Event() link(event) proc_finished_flag = [] @@ -259,11 +260,11 @@ class TestStuff(LimitedTestCase): y = proc.spawn(lambda : 2) z = proc.spawn(lambda : 3) self.assertEqual(proc.waitall([x, y, z]), [1, 2, 3]) - e = coros.Event() + e = _event.Event() x.link(e) self.assertEqual(e.wait(), 1) x.unlink(e) - e = coros.Event() + e = _event.Event() x.link(e) self.assertEqual(e.wait(), 1) self.assertEqual([proc.waitall([X]) for X in [x, y, z]], [[1], [2], [3]]) @@ -358,7 +359,7 @@ class TestStuff(LimitedTestCase): self._test_multiple_listeners_error_unlink(p) def test_killing_unlinked(self): - e = coros.Event() + e = _event.Event() def func(): try: raise ExpectedError('test_killing_unlinked') diff --git a/tests/tpool_test.py b/tests/tpool_test.py index 4696bed..4c9f1bb 100644 --- a/tests/tpool_test.py +++ b/tests/tpool_test.py @@ -19,7 +19,7 @@ import time import re from tests import skipped, skip_with_pyevent, LimitedTestCase, main -from eventlet import api, tpool, debug +from eventlet import tpool, debug import eventlet one = 1 @@ -156,8 +156,8 @@ class TestTpool(LimitedTestCase): @skip_with_pyevent def test_timeout(self): import time - api.exc_after(0.1, api.TimeoutError()) - self.assertRaises(api.TimeoutError, + eventlet.Timeout(0.1, eventlet.TimeoutError()) + self.assertRaises(eventlet.TimeoutError, tpool.execute, time.sleep, 0.3) @skip_with_pyevent @@ -209,12 +209,12 @@ class TpoolLongTests(LimitedTestCase): obj = tpool.Proxy(Dummy()) count = 100 for n in xrange(count): - api.sleep(random.random()/200.0) + eventlet.sleep(random.random()/200.0) now = time.time() token = loopnum * count + n rv = obj.foo(now,token=token) self.assertEquals(token, rv) - api.sleep(random.random()/200.0) + eventlet.sleep(random.random()/200.0) pile = eventlet.GreenPile(10) for i in xrange(10): diff --git a/tests/wsgi_test.py b/tests/wsgi_test.py index 168dbd1..b822199 100644 --- a/tests/wsgi_test.py +++ b/tests/wsgi_test.py @@ -138,7 +138,7 @@ class TestHttpd(LimitedTestCase): def tearDown(self): super(TestHttpd, self).tearDown() greenthread.kill(self.killer) - api.sleep(0) + eventlet.sleep(0) def spawn_server(self, **kwargs): """Spawns a new wsgi server with the given arguments. @@ -155,7 +155,7 @@ class TestHttpd(LimitedTestCase): new_kwargs.update(kwargs) if 'sock' not in new_kwargs: - new_kwargs['sock'] = api.tcp_listener(('localhost', 0)) + new_kwargs['sock'] = eventlet.listen(('localhost', 0)) self.port = new_kwargs['sock'].getsockname()[1] self.killer = eventlet.spawn_n( @@ -163,7 +163,7 @@ class TestHttpd(LimitedTestCase): **new_kwargs) def test_001_server(self): - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() @@ -176,7 +176,7 @@ class TestHttpd(LimitedTestCase): self.assert_(result.endswith('hello world')) def test_002_keepalive(self): - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() @@ -190,19 +190,19 @@ class TestHttpd(LimitedTestCase): def test_003_passing_non_int_to_read(self): # This should go in greenio_test - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') fd.flush() - cancel = api.exc_after(1, RuntimeError) + cancel = eventlet.Timeout(1, RuntimeError) self.assertRaises(TypeError, fd.read, "This shouldn't work") cancel.cancel() fd.close() def test_004_close_keepalive(self): - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() @@ -226,7 +226,7 @@ class TestHttpd(LimitedTestCase): print out.read() def test_006_reject_long_urls(self): - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) path_parts = [] for ii in range(3000): @@ -252,7 +252,7 @@ class TestHttpd(LimitedTestCase): start_response('200 OK', [('Content-type', 'text/plain')]) return ['a is %s, body is %s' % (a, body)] self.site.application = new_app - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) request = '\r\n'.join(( 'POST / HTTP/1.0', @@ -271,7 +271,7 @@ class TestHttpd(LimitedTestCase): fd.close() def test_008_correctresponse(self): - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() @@ -289,7 +289,7 @@ class TestHttpd(LimitedTestCase): def test_009_chunked_response(self): self.site.application = chunked_app - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() @@ -299,7 +299,7 @@ class TestHttpd(LimitedTestCase): def test_010_no_chunked_http_1_0(self): self.site.application = chunked_app - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() @@ -309,7 +309,7 @@ class TestHttpd(LimitedTestCase): def test_011_multiple_chunks(self): self.site.application = big_chunks - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() @@ -346,7 +346,7 @@ class TestHttpd(LimitedTestCase): server_sock = api.ssl_listener(('localhost', 0), certificate_file, private_key_file) self.spawn_server(sock=server_sock, site=wsgi_app) - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) sock = util.wrap_ssl(sock) sock.write('POST /foo HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\nContent-length:3\r\n\r\nabc') result = sock.read(8192) @@ -362,7 +362,7 @@ class TestHttpd(LimitedTestCase): server_sock = api.ssl_listener(('localhost', 0), certificate_file, private_key_file) self.spawn_server(sock=server_sock, site=wsgi_app) - sock = api.connect_tcp(('localhost', server_sock.getsockname()[1])) + sock = eventlet.connect(('localhost', server_sock.getsockname()[1])) sock = util.wrap_ssl(sock) sock.write('GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n') result = sock.read(8192) @@ -370,7 +370,7 @@ class TestHttpd(LimitedTestCase): def test_014_chunked_post(self): self.site.application = chunked_post - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile() fd.write('PUT /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n' 'Transfer-Encoding: chunked\r\n\r\n' @@ -382,7 +382,7 @@ class TestHttpd(LimitedTestCase): response = fd.read() self.assert_(response == 'oh hai', 'invalid response %s' % response) - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile() fd.write('PUT /b HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n' 'Transfer-Encoding: chunked\r\n\r\n' @@ -394,7 +394,7 @@ class TestHttpd(LimitedTestCase): response = fd.read() self.assert_(response == 'oh hai', 'invalid response %s' % response) - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile() fd.write('PUT /c HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n' 'Transfer-Encoding: chunked\r\n\r\n' @@ -408,14 +408,14 @@ class TestHttpd(LimitedTestCase): def test_015_write(self): self.site.application = use_write - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile() fd.write('GET /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n') fd.flush() response_line, headers, body = read_http(sock) self.assert_('content-length' in headers) - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile() fd.write('GET /b HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n') fd.flush() @@ -432,7 +432,7 @@ class TestHttpd(LimitedTestCase): start_response('200 OK', [('Content-Length', '7')]) return ['testing'] self.site.application = wsgi_app - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile() fd.write('GET /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n') fd.flush() @@ -470,7 +470,7 @@ class TestHttpd(LimitedTestCase): server_coro = eventlet.spawn(server, sock, wsgi_app, self.logfile) - client = api.connect_tcp(('localhost', sock.getsockname()[1])) + client = eventlet.connect(('localhost', sock.getsockname()[1])) client = util.wrap_ssl(client) client.write('X') # non-empty payload so that SSL handshake occurs greenio.shutdown_safe(client) @@ -482,7 +482,7 @@ class TestHttpd(LimitedTestCase): def test_018_http_10_keepalive(self): # verify that if an http/1.0 client sends connection: keep-alive # that we don't close the connection - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() @@ -508,7 +508,7 @@ class TestHttpd(LimitedTestCase): return ['hello!'] self.site.application = use_fieldstorage - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() @@ -522,7 +522,7 @@ class TestHttpd(LimitedTestCase): self.assert_('hello!' in fd.read()) def test_020_x_forwarded_for(self): - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) sock.sendall('GET / HTTP/1.1\r\nHost: localhost\r\nX-Forwarded-For: 1.2.3.4, 5.6.7.8\r\n\r\n') sock.recv(1024) sock.close() @@ -532,7 +532,7 @@ class TestHttpd(LimitedTestCase): self.logfile = StringIO() self.spawn_server(log_x_forwarded_for=False) - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) sock.sendall('GET / HTTP/1.1\r\nHost: localhost\r\nX-Forwarded-For: 1.2.3.4, 5.6.7.8\r\n\r\n') sock.recv(1024) sock.close() @@ -542,11 +542,11 @@ class TestHttpd(LimitedTestCase): def test_socket_remains_open(self): greenthread.kill(self.killer) - server_sock = api.tcp_listener(('localhost', 0)) + server_sock = eventlet.listen(('localhost', 0)) server_sock_2 = server_sock.dup() self.spawn_server(sock=server_sock_2) # do a single req/response to verify it's up - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile() fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n') fd.flush() @@ -565,7 +565,7 @@ class TestHttpd(LimitedTestCase): except socket.error, exc: self.assertEqual(exc[0], errno.EBADF) self.spawn_server(sock=server_sock) - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile() fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n') fd.flush() @@ -586,7 +586,7 @@ class TestHttpd(LimitedTestCase): start_response('200 OK', [('Content-type', 'text/plain')]) return [] self.site.application = clobberin_time - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile() fd.write('GET / HTTP/1.1\r\n' 'Host: localhost\r\n' @@ -604,7 +604,7 @@ class TestHttpd(LimitedTestCase): self.spawn_server(custom_pool=p) # this stuff is copied from test_001_server, could be better factored - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n') @@ -615,7 +615,7 @@ class TestHttpd(LimitedTestCase): self.assert_(result.endswith('hello world')) def test_023_bad_content_length(self): - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile() fd.write('GET / HTTP/1.0\r\nHost: localhost\r\nContent-length: argh\r\n\r\n') @@ -636,7 +636,7 @@ class TestHttpd(LimitedTestCase): start_response('200 OK', [('Content-Length', str(len(text)))]) return [text] self.site.application = wsgi_app - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile() fd.write('PUT / HTTP/1.1\r\nHost: localhost\r\nContent-length: 1025\r\nExpect: 100-continue\r\n\r\n') fd.flush() @@ -677,7 +677,7 @@ class TestHttpd(LimitedTestCase): sys.stderr = self.logfile api.sleep(0) # need to enter server loop try: - api.connect_tcp(('localhost', self.port)) + eventlet.connect(('localhost', self.port)) self.fail("Didn't expect to connect") except socket.error, exc: self.assertEquals(exc[0], errno.ECONNREFUSED) @@ -690,7 +690,7 @@ class TestHttpd(LimitedTestCase): def test_026_log_format(self): self.spawn_server(log_format="HI %(request_line)s HI") - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) sock.sendall('GET /yo! HTTP/1.1\r\nHost: localhost\r\n\r\n') sock.recv(1024) sock.close() @@ -701,7 +701,7 @@ class TestHttpd(LimitedTestCase): # and we're not speaking with a 1.1 client, that we # close the connection self.site.application = chunked_app - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) sock.sendall('GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n') @@ -714,7 +714,7 @@ class TestHttpd(LimitedTestCase): # verify that if an http/1.0 client sends connection: keep-alive # and the server doesn't accept keep-alives, we close the connection self.spawn_server(keepalive=False) - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) sock.sendall('GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n') @@ -723,7 +723,7 @@ class TestHttpd(LimitedTestCase): def test_027_keepalive_chunked(self): self.site.application = chunked_post - sock = api.connect_tcp(('localhost', self.port)) + sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile() fd.write('PUT /a HTTP/1.1\r\nHost: localhost\r\nTransfer-Encoding: chunked\r\n\r\n10\r\n0123456789abcdef\r\n0\r\n\r\n') fd.flush() @@ -752,7 +752,7 @@ class TestHttpd(LimitedTestCase): srv_sock = api.ssl_listener(('localhost', 0), certificate_file, private_key_file) port = srv_sock.getsockname()[1] g = eventlet.spawn_n(server, srv_sock) - client = api.connect_tcp(('localhost', port)) + client = eventlet.connect(('localhost', port)) if data: # send non-ssl request client.sendall(data) else: # close sock prematurely @@ -762,7 +762,7 @@ class TestHttpd(LimitedTestCase): # make another request to ensure the server's still alive try: from eventlet.green import ssl - client = ssl.wrap_socket(api.connect_tcp(('localhost', port))) + client = ssl.wrap_socket(eventlet.connect(('localhost', port))) client.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n') result = client.read() self.assert_(result.startswith('HTTP'), result) @@ -777,7 +777,7 @@ class TestHttpd(LimitedTestCase): yield "" self.site.application = zero_chunked_app - sock = api.connect_tcp( + sock = eventlet.connect( ('localhost', self.port)) fd = sock.makefile()