Commit a7b17d41 authored by Denis Bilenko's avatar Denis Bilenko

Merge pull request #397 from surfly/pr365

py3-related fixes
parents bb11c1bb 240b5846
......@@ -11,7 +11,8 @@ from psycopg2 import extensions, OperationalError, connect
if sys.version_info[0] >= 3:
integer_types = int,
else:
integer_types = int, long
import __builtin__
integer_types = int, __builtin__.long
def gevent_wait_callback(conn, timeout=None):
......
......@@ -41,9 +41,10 @@ if PY3:
raise value
else:
string_types = basestring,
integer_types = (int, long)
xrange = xrange
import __builtin__
string_types = __builtin__.basestring,
integer_types = (int, __builtin__.long)
xrange = __builtin__.xrange
from gevent._util_py2 import reraise
......
......@@ -18,7 +18,8 @@ __all__ = ['patch_all',
if sys.version_info[0] >= 3:
string_types = str,
else:
string_types = basestring,
import __builtin__
string_types = __builtin__.basestring
# maps module name -> attribute name -> original item
......
......@@ -34,5 +34,6 @@ else:
locs = globs
exec("""exec code in globs, locs""")
xrange = xrange
string_types = basestring,
import __builtin__ as builtins
xrange = builtins.xrange
string_types = builtins.basestring,
......@@ -17,7 +17,10 @@ elif sys.argv[1:] == ['subprocess']:
gevent.monkey.patch_all(sys=True)
def printline():
line = raw_input()
try:
line = raw_input()
except NameError:
line = input()
print('%s chars.' % len(line))
gevent.spawn(printline).join()
......
import sys
import six
from os import pipe
from gevent import os
from greentest import TestCase, main
......@@ -26,12 +28,12 @@ class TestOS_tp(TestCase):
def write(self, *args):
return os.tp_write(*args)
def test_if_pipe_blocks(self):
def _test_if_pipe_blocks(self, buffer_class):
r, w = self.pipe()
# set nbytes such that for sure it is > maximum pipe buffer
nbytes = 1000000
block = 'x' * 4096
buf = buffer(block)
buf = buffer_class(block)
# Lack of "nonlocal" keyword in Python 2.x:
bytesread = [0]
byteswritten = [0]
......@@ -57,6 +59,16 @@ class TestOS_tp(TestCase):
assert bytesread[0] == nbytes
assert bytesread[0] == byteswritten[0]
if sys.version_info[0] < 3:
def test_if_pipe_blocks_buffer(self):
self._test_if_pipe_blocks(six.builtins.buffer)
if sys.version_info[:2] >= (2, 7):
def test_if_pipe_blocks_memoryview(self):
self._test_if_pipe_blocks(six.builtins.memoryview)
if hasattr(os, 'make_nonblocking'):
......
import six
import sys
import os
from gevent import select, socket
......@@ -29,14 +30,11 @@ class TestSelectTypes(greentest.TestCase):
sock = socket.socket()
select.select([int(sock.fileno())], [], [], 0.001)
try:
long
except NameError:
pass
else:
if hasattr(six.builtins, 'long'):
def test_long(self):
sock = socket.socket()
select.select([long(sock.fileno())], [], [], 0.001)
select.select(
[six.builtins.long(sock.fileno())], [], [], 0.001)
def test_string(self):
self.switch_expected = False
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment