Merge in amajorek-py3k

This commit is contained in:
Ryan Williams
2010-03-12 16:09:58 -08:00
27 changed files with 84 additions and 74 deletions

View File

@@ -6,8 +6,7 @@ import linecache
import inspect import inspect
import warnings import warnings
from eventlet.common import BaseException from eventlet.support import greenlets as greenlet, BaseException
from eventlet.support import greenlets as greenlet
from eventlet import hubs from eventlet import hubs
from eventlet import greenthread from eventlet import greenthread
from eventlet import debug from eventlet import debug

View File

@@ -5,8 +5,7 @@ from code import InteractiveConsole
import eventlet import eventlet
from eventlet import hubs from eventlet import hubs
from eventlet.common import get_errno from eventlet.support import greenlets, get_errno
from eventlet.support import greenlets
#FIXME no testcases for bckdor module #FIXME no testcases for bckdor module
try: try:

View File

@@ -1,36 +0,0 @@
import sys
def get_errno(exc):
""" Get the error code out of socket.error objects.
socket.error in <2.5 does not have errno attribute
socket.error in 3.x does not allow indexing access
e.args[0] works for all.
There are cases when args[0] is not errno.
i.e. http://bugs.python.org/issue6471
Maybe there are cases when errno is set, but it is not the first argument?
"""
try:
if exc.errno is not None: return exc.errno
except AttributeError:
pass
try:
return exc.args[0]
except IndexError:
return None
if sys.version_info[0]<3:
from sys import exc_clear as clear_sys_exc_info
else:
def clear_sys_exc_info():
"""No-op In py3k.
Exception information is not visible outside of except statements.
sys.exc_clear became obsolete and removed."""
pass
if sys.version_info[0]==2 and sys.version_info[1]<5:
class BaseException: # pylint: disable-msg=W0622
# not subclassing from object() intentionally, because in
# that case "raise Timeout" fails with TypeError.
pass
else:
from __builtin__ import BaseException

View File

@@ -1,6 +1,6 @@
from OpenSSL import SSL as orig_SSL from OpenSSL import SSL as orig_SSL
from OpenSSL.SSL import * from OpenSSL.SSL import *
from eventlet.common import get_errno from eventlet.support import get_errno
from eventlet import greenio from eventlet import greenio
from eventlet.hubs import trampoline from eventlet.hubs import trampoline
import socket import socket

View File

@@ -3,7 +3,7 @@ import errno
socket = __import__("socket") socket = __import__("socket")
from eventlet import greenio from eventlet import greenio
from eventlet.common import get_errno from eventlet.support import get_errno
from eventlet import greenthread from eventlet import greenthread
from eventlet import hubs from eventlet import hubs

View File

@@ -6,7 +6,7 @@ for attr in dir(__ssl):
import errno import errno
time = __import__('time') time = __import__('time')
from eventlet.common import get_errno from eventlet.support import get_errno
from eventlet.hubs import trampoline from eventlet.hubs import trampoline
from eventlet.greenio import set_nonblocking, GreenSocket, SOCKET_CLOSED, CONNECT_ERR, CONNECT_SUCCESS from eventlet.greenio import set_nonblocking, GreenSocket, SOCKET_CLOSED, CONNECT_ERR, CONNECT_SUCCESS
orig_socket = __import__('socket') orig_socket = __import__('socket')

View File

@@ -1,4 +1,4 @@
from eventlet.common import get_errno from eventlet.support import get_errno
from eventlet.hubs import trampoline from eventlet.hubs import trampoline
BUFFER_SIZE = 4096 BUFFER_SIZE = 4096

View File

@@ -2,8 +2,7 @@ import heapq
import sys import sys
import traceback import traceback
from eventlet.common import clear_sys_exc_info from eventlet.support import greenlets as greenlet, clear_sys_exc_info
from eventlet.support import greenlets as greenlet
from eventlet.hubs import timer from eventlet.hubs import timer
from eventlet import patcher from eventlet import patcher
time = patcher.original('time') time = patcher.original('time')

View File

@@ -5,7 +5,7 @@ select = patcher.original('select')
time = patcher.original('time') time = patcher.original('time')
sleep = time.sleep sleep = time.sleep
from eventlet.common import get_errno, clear_sys_exc_info from eventlet.support import get_errno, clear_sys_exc_info
from eventlet.hubs.hub import BaseHub, READ, WRITE from eventlet.hubs.hub import BaseHub, READ, WRITE
EXC_MASK = select.POLLERR | select.POLLHUP EXC_MASK = select.POLLERR | select.POLLHUP

View File

@@ -1,7 +1,7 @@
import sys import sys
import errno import errno
from eventlet import patcher from eventlet import patcher
from eventlet.common import get_errno, clear_sys_exc_info from eventlet.support import get_errno, clear_sys_exc_info
select = patcher.original('select') select = patcher.original('select')
time = patcher.original('time') time = patcher.original('time')

View File

@@ -117,7 +117,7 @@ def _read_response(id, attribute, input, cp):
"""local helper method to read respones from the rpc server.""" """local helper method to read respones from the rpc server."""
try: try:
str = _read_lp_hunk(input) str = _read_lp_hunk(input)
_prnt(`str`) _prnt(repr(str))
response = Pickle.loads(str) response = Pickle.loads(str)
except (AttributeError, DeadProcess, Pickle.UnpicklingError), e: except (AttributeError, DeadProcess, Pickle.UnpicklingError), e:
raise UnrecoverableError(e) raise UnrecoverableError(e)
@@ -577,7 +577,7 @@ class Server(object):
_log("responding with: %s" % body) _log("responding with: %s" % body)
#_log("objects: %s" % self._objects) #_log("objects: %s" % self._objects)
s = Pickle.dumps(body) s = Pickle.dumps(body)
_log(`s`) _log(repr(s))
_write_lp_hunk(self._out, s) _write_lp_hunk(self._out, s)
def write_exception(self, e): def write_exception(self, e):

View File

@@ -0,0 +1,36 @@
import sys
def get_errno(exc):
""" Get the error code out of socket.error objects.
socket.error in <2.5 does not have errno attribute
socket.error in 3.x does not allow indexing access
e.args[0] works for all.
There are cases when args[0] is not errno.
i.e. http://bugs.python.org/issue6471
Maybe there are cases when errno is set, but it is not the first argument?
"""
try:
if exc.errno is not None: return exc.errno
except AttributeError:
pass
try:
return exc.args[0]
except IndexError:
return None
if sys.version_info[0]<3:
from sys import exc_clear as clear_sys_exc_info
else:
def clear_sys_exc_info():
"""No-op In py3k.
Exception information is not visible outside of except statements.
sys.exc_clear became obsolete and removed."""
pass
if sys.version_info[0]==2 and sys.version_info[1]<5:
class BaseException: # pylint: disable-msg=W0622
# not subclassing from object() intentionally, because in
# that case "raise Timeout" fails with TypeError.
pass
else:
from __builtin__ import BaseException

View File

@@ -20,8 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.from eventlet.support import greenlets as greenlet # THE SOFTWARE.from eventlet.support import greenlets as greenlet
from eventlet.common import BaseException from eventlet.support import greenlets as greenlet, BaseException
from eventlet.support import greenlets as greenlet
from eventlet.hubs import get_hub from eventlet.hubs import get_hub
__all__ = ['Timeout', __all__ = ['Timeout',

View File

@@ -169,7 +169,7 @@ class Proxy(object):
def __getattr__(self,attr_name): def __getattr__(self,attr_name):
f = getattr(self._obj,attr_name) f = getattr(self._obj,attr_name)
if not callable(f): if not hasattr(f, '__call__'):
if (isinstance(f, self._autowrap) or if (isinstance(f, self._autowrap) or
attr_name in self._autowrap_names): attr_name in self._autowrap_names):
return Proxy(f, self._autowrap) return Proxy(f, self._autowrap)
@@ -199,6 +199,8 @@ class Proxy(object):
# wrapped object in such a way that they would block # wrapped object in such a way that they would block
def __eq__(self, rhs): def __eq__(self, rhs):
return self._obj.__eq__(rhs) return self._obj.__eq__(rhs)
def __hash__(self):
return self._obj.__hash__()
def __repr__(self): def __repr__(self):
return self._obj.__repr__() return self._obj.__repr__()
def __str__(self): def __str__(self):

View File

@@ -10,7 +10,7 @@ from eventlet.green import socket
from eventlet.green import BaseHTTPServer from eventlet.green import BaseHTTPServer
from eventlet import greenpool from eventlet import greenpool
from eventlet import greenio from eventlet import greenio
from eventlet.common import get_errno from eventlet.support import get_errno
DEFAULT_MAX_SIMULTANEOUS_REQUESTS = 1024 DEFAULT_MAX_SIMULTANEOUS_REQUESTS = 1024
DEFAULT_MAX_HTTP_VERSION = 'HTTP/1.1' DEFAULT_MAX_HTTP_VERSION = 'HTTP/1.1'

View File

@@ -30,7 +30,7 @@ class TestServe(LimitedTestCase):
# tests that the server closes the client sock on handle() exception # tests that the server closes the client sock on handle() exception
def crasher(sock,addr): def crasher(sock,addr):
sock.recv(1024) sock.recv(1024)
0/0 0//0
l = eventlet.listen(('localhost', 0)) l = eventlet.listen(('localhost', 0))
gt = eventlet.spawn(eventlet.serve, l, crasher) gt = eventlet.spawn(eventlet.serve, l, crasher)
@@ -44,7 +44,7 @@ class TestServe(LimitedTestCase):
def crasher(sock,addr): def crasher(sock,addr):
sock.recv(1024) sock.recv(1024)
sock.close() sock.close()
0/0 0//0
l = eventlet.listen(('localhost', 0)) l = eventlet.listen(('localhost', 0))
gt = eventlet.spawn(eventlet.serve, l, crasher) gt = eventlet.spawn(eventlet.serve, l, crasher)

View File

@@ -3,7 +3,7 @@ from tests import LimitedTestCase, skip_with_pyevent, main, skipped, s2b
from eventlet import event from eventlet import event
from eventlet import greenio from eventlet import greenio
from eventlet import debug from eventlet import debug
from eventlet.common import get_errno from eventlet.support import get_errno
from eventlet.green import socket from eventlet.green import socket
from eventlet.green import time from eventlet.green import time
from eventlet.green.socket import GreenSSLObject from eventlet.green.socket import GreenSSLObject

View File

@@ -51,7 +51,7 @@ class TestExceptionInMainloop(LimitedTestCase):
assert delay >= DELAY*0.9, 'sleep returned after %s seconds (was scheduled for %s)' % (delay, DELAY) assert delay >= DELAY*0.9, 'sleep returned after %s seconds (was scheduled for %s)' % (delay, DELAY)
def fail(): def fail():
1/0 1//0
hubs.get_hub().schedule_call_global(0, fail) hubs.get_hub().schedule_call_global(0, fail)

View File

@@ -46,7 +46,7 @@ def parse_unittest_output(s):
fail = int(fail or '0') fail = int(fail or '0')
error = int(error or '0') error = int(error or '0')
else: else:
assert ok_match, `s` assert ok_match, repr(s)
timeout_match = re.search('^===disabled because of timeout: (\d+)$', s, re.M) timeout_match = re.search('^===disabled because of timeout: (\d+)$', s, re.M)
if timeout_match: if timeout_match:
timeout = int(timeout_match.group(1)) timeout = int(timeout_match.group(1))

View File

@@ -82,7 +82,6 @@ class TestSaranwrap(LimitedTestCase):
self.assertEqual(1, prox['a']) self.assertEqual(1, prox['a'])
self.assertEqual(str(my_object), str(prox)) self.assertEqual(str(my_object), str(prox))
self.assertEqual('saran:' + repr(my_object), repr(prox)) self.assertEqual('saran:' + repr(my_object), repr(prox))
self.assertEqual('saran:' + `my_object`, `prox`)
@skip_on_windows @skip_on_windows
@skip_with_pyevent @skip_with_pyevent

View File

@@ -40,7 +40,7 @@ class TestGreenness(unittest.TestCase):
urllib2.urlopen('http://127.0.0.1:%s' % self.port) urllib2.urlopen('http://127.0.0.1:%s' % self.port)
assert False, 'should not get there' assert False, 'should not get there'
except urllib2.HTTPError, ex: except urllib2.HTTPError, ex:
assert ex.code == 501, `ex` assert ex.code == 501, repr(ex)
self.assertEqual(self.server.request_count, 1) self.assertEqual(self.server.request_count, 1)
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -4,7 +4,7 @@ are not leaked by the hub.
import sys import sys
import unittest import unittest
from pprint import pformat from pprint import pformat
from eventlet.common import clear_sys_exc_info from eventlet.support import clear_sys_exc_info
from eventlet.green import socket from eventlet.green import socket
from eventlet.green.thread import start_new_thread from eventlet.green.thread import start_new_thread
from eventlet.green.time import sleep from eventlet.green.time import sleep
@@ -31,7 +31,7 @@ def handle_request(s, raise_on_timeout):
return return
#print 'handle_request - accepted' #print 'handle_request - accepted'
res = conn.recv(100) res = conn.recv(100)
assert res == 'hello', `res` assert res == 'hello', repr(res)
#print 'handle_request - recvd %r' % res #print 'handle_request - recvd %r' % res
res = conn.send('bye') res = conn.send('bye')
#print 'handle_request - sent %r' % res #print 'handle_request - sent %r' % res
@@ -46,7 +46,7 @@ def make_request(port):
res = s.send('hello') res = s.send('hello')
#print 'make_request - sent %s' % res #print 'make_request - sent %s' % res
res = s.recv(100) res = s.recv(100)
assert res == 'bye', `res` assert res == 'bye', repr(res)
#print 'make_request - recvd %r' % res #print 'make_request - recvd %r' % res
#s.close() #s.close()

View File

@@ -29,7 +29,7 @@ class Test(unittest.TestCase):
def test_block_on_already_succeed(self): def test_block_on_already_succeed(self):
d = defer.succeed('hey corotwine') d = defer.succeed('hey corotwine')
res = block_on(d) res = block_on(d)
assert res == 'hey corotwine', `res` assert res == 'hey corotwine', repr(res)
@requires_twisted @requires_twisted
def test_block_on_already_failed(self): def test_block_on_already_failed(self):

View File

@@ -160,7 +160,7 @@ class TestGreenTransport_bufsize1(TestGreenTransport):
# self.conn.write('hello\r\n') # self.conn.write('hello\r\n')
# sleep(DELAY*1.5) # make sure the rest of data arrives # sleep(DELAY*1.5) # make sure the rest of data arrives
# try: # try:
# 1/0 # 1//0
# except: # except:
# #self.conn.loseConnection(failure.Failure()) # does not work, why? # #self.conn.loseConnection(failure.Failure()) # does not work, why?
# spawn(self.conn._queue.send_exception, *sys.exc_info()) # spawn(self.conn._queue.send_exception, *sys.exc_info())
@@ -176,7 +176,7 @@ class TestGreenTransport_bufsize1(TestGreenTransport):
# self.assertEqual('you said hello. ', self.conn.recv()) # self.assertEqual('you said hello. ', self.conn.recv())
# sleep(DELAY*1.5) # make sure the rest of data arrives # sleep(DELAY*1.5) # make sure the rest of data arrives
# try: # try:
# 1/0 # 1//0
# except: # except:
# #self.conn.loseConnection(failure.Failure()) # does not work, why? # #self.conn.loseConnection(failure.Failure()) # does not work, why?
# spawn(self.conn._queue.send_exception, *sys.exc_info()) # spawn(self.conn._queue.send_exception, *sys.exc_info())

View File

@@ -51,7 +51,7 @@ class Test(LimitedTestCase):
pass pass
try: try:
1/0 1//0
except: except:
try: try:
with Timeout(DELAY, sys.exc_info()[0]): with Timeout(DELAY, sys.exc_info()[0]):

View File

@@ -74,7 +74,6 @@ class TestTpool(LimitedTestCase):
self.assertEqual(1, prox['a']) self.assertEqual(1, prox['a'])
self.assertEqual(str(my_object), str(prox)) self.assertEqual(str(my_object), str(prox))
self.assertEqual(repr(my_object), repr(prox)) self.assertEqual(repr(my_object), repr(prox))
self.assertEqual(`my_object`, `prox`)
@skip_with_pyevent @skip_with_pyevent
def test_wrap_module_class(self): def test_wrap_module_class(self):
@@ -93,6 +92,17 @@ class TestTpool(LimitedTestCase):
exp3 = prox.compile('/') exp3 = prox.compile('/')
self.assert_(exp1 != exp3) self.assert_(exp1 != exp3)
@skip_with_pyevent
def test_wrap_hash(self):
prox1 = tpool.Proxy(''+'A')
prox2 = tpool.Proxy('A'+'')
self.assert_(prox1=='A')
self.assert_('A'==prox2)
#self.assert_(prox1==prox2) FIXME - could __eq__ unwrap rhs if it is other proxy?
self.assertEqual(hash(prox1), hash(prox2))
proxList = tpool.Proxy([])
self.assertRaises(TypeError, hash, proxList)
@skip_with_pyevent @skip_with_pyevent
def test_wrap_nonzero(self): def test_wrap_nonzero(self):
prox = tpool.Proxy(re) prox = tpool.Proxy(re)

View File

@@ -14,7 +14,7 @@ from eventlet import greenio
from eventlet.green import socket as greensocket from eventlet.green import socket as greensocket
from eventlet import wsgi from eventlet import wsgi
from eventlet import processes from eventlet import processes
from eventlet.common import get_errno from eventlet.support import get_errno
from tests import find_command from tests import find_command
@@ -137,9 +137,9 @@ class TestHttpd(LimitedTestCase):
self.spawn_server() self.spawn_server()
def tearDown(self): def tearDown(self):
super(TestHttpd, self).tearDown()
greenthread.kill(self.killer) greenthread.kill(self.killer)
eventlet.sleep(0) eventlet.sleep(0)
super(TestHttpd, self).tearDown()
def spawn_server(self, **kwargs): def spawn_server(self, **kwargs):
"""Spawns a new wsgi server with the given arguments. """Spawns a new wsgi server with the given arguments.
@@ -147,8 +147,10 @@ class TestHttpd(LimitedTestCase):
running it. running it.
Kills any previously-running server.""" Kills any previously-running server."""
eventlet.sleep(0) # give previous server a chance to start
if self.killer: if self.killer:
greenthread.kill(self.killer) greenthread.kill(self.killer)
eventlet.sleep(0) # give killer a chance to kill
new_kwargs = dict(max_size=128, new_kwargs = dict(max_size=128,
log=self.logfile, log=self.logfile,
@@ -252,6 +254,7 @@ class TestHttpd(LimitedTestCase):
a = cgi.parse_qs(body).get('a', [1])[0] a = cgi.parse_qs(body).get('a', [1])[0]
start_response('200 OK', [('Content-type', 'text/plain')]) start_response('200 OK', [('Content-type', 'text/plain')])
return ['a is %s, body is %s' % (a, body)] return ['a is %s, body is %s' % (a, body)]
self.site.application = new_app self.site.application = new_app
sock = eventlet.connect( sock = eventlet.connect(
('localhost', self.port)) ('localhost', self.port))
@@ -559,7 +562,7 @@ class TestHttpd(LimitedTestCase):
# shut down the server and verify the server_socket fd is still open, # shut down the server and verify the server_socket fd is still open,
# but the actual socketobject passed in to wsgi.server is closed # but the actual socketobject passed in to wsgi.server is closed
greenthread.kill(self.killer) greenthread.kill(self.killer)
api.sleep(0.001) # make the kill go through eventlet.sleep(0) # make the kill go through
try: try:
server_sock_2.accept() server_sock_2.accept()
# shouldn't be able to use this one anymore # shouldn't be able to use this one anymore
@@ -676,7 +679,7 @@ class TestHttpd(LimitedTestCase):
old_stderr = sys.stderr old_stderr = sys.stderr
try: try:
sys.stderr = self.logfile sys.stderr = self.logfile
api.sleep(0) # need to enter server loop eventlet.sleep(0) # need to enter server loop
try: try:
eventlet.connect(('localhost', self.port)) eventlet.connect(('localhost', self.port))
self.fail("Didn't expect to connect") self.fail("Didn't expect to connect")
@@ -758,7 +761,7 @@ class TestHttpd(LimitedTestCase):
client.sendall(data) client.sendall(data)
else: # close sock prematurely else: # close sock prematurely
client.close() client.close()
api.sleep(0) # let context switch back to server eventlet.sleep(0) # let context switch back to server
self.assert_(not errored[0], errored[0]) self.assert_(not errored[0], errored[0])
# make another request to ensure the server's still alive # make another request to ensure the server's still alive
try: try: