Renamed wrappedfd.py to greenio.py.

This commit is contained in:
rdw
2008-03-18 14:23:38 -05:00
parent 9d270ae6cc
commit 91dee30ebd
8 changed files with 22 additions and 23 deletions

View File

@@ -68,8 +68,8 @@ def tcp_listener(address):
which accepts connections forever and spawns greenlets for which accepts connections forever and spawns greenlets for
each incoming connection. each incoming connection.
""" """
from eventlet import wrappedfd, util from eventlet import greenio, util
socket = wrappedfd.GreenSocket(util.tcp_socket()) socket = greenio.GreenSocket(util.tcp_socket())
util.socket_bind_and_listen(socket, address) util.socket_bind_and_listen(socket, address)
return socket return socket
@@ -94,8 +94,8 @@ def connect_tcp(address):
""" """
Create a TCP connection to address (host, port) and return the socket. Create a TCP connection to address (host, port) and return the socket.
""" """
from eventlet import wrappedfd, util from eventlet import greenio, util
desc = wrappedfd.GreenSocket(util.tcp_socket()) desc = greenio.GreenSocket(util.tcp_socket())
desc.connect(address) desc.connect(address)
return desc return desc

View File

@@ -23,7 +23,7 @@ THE SOFTWARE.
""" """
from eventlet import tests from eventlet import tests
from eventlet import api, wrappedfd, util from eventlet import api, greenio, util
import socket import socket
@@ -101,7 +101,7 @@ class TestApi(tests.TestCase):
bound_port = server.getsockname()[1] bound_port = server.getsockname()[1]
try: try:
desc = wrappedfd.GreenSocket(util.tcp_socket()) desc = greenio.GreenSocket(util.tcp_socket())
api.trampoline(desc, read=True, write=True, timeout=0.1) api.trampoline(desc, read=True, write=True, timeout=0.1)
except api.TimeoutError: except api.TimeoutError:
pass # test passed pass # test passed
@@ -120,7 +120,7 @@ class TestApi(tests.TestCase):
def go(): def go():
client = util.tcp_socket() client = util.tcp_socket()
desc = wrappedfd.GreenSocket(client) desc = greenio.GreenSocket(client)
desc.connect(('127.0.0.1', bound_port)) desc.connect(('127.0.0.1', bound_port))
try: try:
api.trampoline(desc, read=True, write=True, timeout=0.1) api.trampoline(desc, read=True, write=True, timeout=0.1)

View File

@@ -1,6 +1,5 @@
"""\ """\
@file wrappedfd.py @file greenio.py
@author Bob Ippolito
Copyright (c) 2005-2006, Bob Ippolito Copyright (c) 2005-2006, Bob Ippolito
Copyright (c) 2007, Linden Research, Inc. Copyright (c) 2007, Linden Research, Inc.

View File

@@ -1,5 +1,5 @@
"""\ """\
@file wrappedfd_test.py @file greenio_test.py
Copyright (c) 2006-2007, Linden Research, Inc. Copyright (c) 2006-2007, Linden Research, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -22,12 +22,12 @@ THE SOFTWARE.
""" """
from eventlet import tests from eventlet import tests
from eventlet import api, wrappedfd, util from eventlet import api, greenio, util
import socket import socket
# TODO try and reuse unit tests from within Python itself # TODO try and reuse unit tests from within Python itself
class TestWrappedFd(tests.TestCase): class TestGreenIo(tests.TestCase):
def test_close_with_makefile(self): def test_close_with_makefile(self):
def accept_close_early(listener): def accept_close_early(listener):
# verify that the makefile and the socket are truly independent # verify that the makefile and the socket are truly independent
@@ -100,6 +100,6 @@ class TestWrappedFd(tests.TestCase):
assert fd.read() == '' assert fd.read() == ''
timer.cancel() timer.cancel()
if __name__ == '__main__': if __name__ == '__main__':
tests.main() tests.main()

View File

@@ -125,7 +125,7 @@ class TestHttpd(tests.TestCase):
fd.close() fd.close()
def test_003_passing_non_int_to_read(self): def test_003_passing_non_int_to_read(self):
# This should go in test_wrappedfd # This should go in greenio_test
sock = api.connect_tcp( sock = api.connect_tcp(
('127.0.0.1', 12346)) ('127.0.0.1', 12346))

View File

@@ -28,7 +28,7 @@ import signal
from eventlet import util, pools from eventlet import util, pools
from eventlet import wrappedfd from eventlet import greenio
class DeadProcess(RuntimeError): class DeadProcess(RuntimeError):
pass pass
@@ -55,9 +55,9 @@ class Process(object):
child_stdin = self.popen4.tochild child_stdin = self.popen4.tochild
util.set_nonblocking(child_stdout_stderr) util.set_nonblocking(child_stdout_stderr)
util.set_nonblocking(child_stdin) util.set_nonblocking(child_stdin)
self.child_stdout_stderr = wrappedfd.GreenPipe(child_stdout_stderr) self.child_stdout_stderr = greenio.GreenPipe(child_stdout_stderr)
self.child_stdout_stderr.newlines = '\n' # the default is \r\n, which aren't sent over pipes self.child_stdout_stderr.newlines = '\n' # the default is \r\n, which aren't sent over pipes
self.child_stdin = wrappedfd.GreenPipe(child_stdin) self.child_stdin = greenio.GreenPipe(child_stdin)
self.child_stdin.newlines = '\n' self.child_stdin.newlines = '\n'
self.sendall = self.child_stdin.write self.sendall = self.child_stdin.write

View File

@@ -23,12 +23,12 @@ import Queue
from sys import stdout from sys import stdout
from Queue import Empty, Queue from Queue import Empty, Queue
from eventlet import api, coros, httpc, httpd, util, wrappedfd from eventlet import api, coros, httpc, httpd, util, greenio
from eventlet.api import trampoline, get_hub from eventlet.api import trampoline, get_hub
_rpipe, _wpipe = os.pipe() _rpipe, _wpipe = os.pipe()
_rfile = os.fdopen(_rpipe,"r",0) _rfile = os.fdopen(_rpipe,"r",0)
_wrap_rfile = wrappedfd.GreenPipe(_rfile) _wrap_rfile = greenio.GreenPipe(_rfile)
util.set_nonblocking(_rfile) util.set_nonblocking(_rfile)
def _signal_t2e(): def _signal_t2e():

View File

@@ -76,7 +76,7 @@ __original_ssl__ = socket.ssl
def wrap_ssl(sock, certificate=None, private_key=None): def wrap_ssl(sock, certificate=None, private_key=None):
from OpenSSL import SSL from OpenSSL import SSL
from eventlet import wrappedfd, util from eventlet import greenio, util
context = SSL.Context(SSL.SSLv23_METHOD) context = SSL.Context(SSL.SSLv23_METHOD)
print certificate, private_key print certificate, private_key
if certificate is not None: if certificate is not None:
@@ -88,15 +88,15 @@ def wrap_ssl(sock, certificate=None, private_key=None):
## TODO only do this on client sockets? how? ## TODO only do this on client sockets? how?
connection = SSL.Connection(context, sock) connection = SSL.Connection(context, sock)
connection.set_connect_state() connection.set_connect_state()
return wrappedfd.GreenSocket(connection) return greenio.GreenSocket(connection)
def wrap_socket_with_coroutine_socket(): def wrap_socket_with_coroutine_socket():
def new_socket(*args, **kw): def new_socket(*args, **kw):
from eventlet import wrappedfd from eventlet import greenio
s = __original_socket__(*args, **kw) s = __original_socket__(*args, **kw)
set_nonblocking(s) set_nonblocking(s)
return wrappedfd.GreenSocket(s) return greenio.GreenSocket(s)
socket.socket = new_socket socket.socket = new_socket
socket.ssl = wrap_ssl socket.ssl = wrap_ssl