Commit ac7a87fe authored by Fantix King's avatar Fantix King Committed by Denis Bilenko

Replace basestring with string_types (mostly), refs #38.

parent e997754e
...@@ -8,6 +8,11 @@ from _socket import gaierror ...@@ -8,6 +8,11 @@ from _socket import gaierror
__all__ = ['channel'] __all__ = ['channel']
if sys.version_info[0] >= 3:
basestring = (bytes, str)
else:
basestring = __builtins__.basestring
TIMEOUT = 1 TIMEOUT = 1
DEF EV_READ = 1 DEF EV_READ = 1
......
...@@ -15,6 +15,12 @@ __all__ = ['patch_all', ...@@ -15,6 +15,12 @@ __all__ = ['patch_all',
'patch_sys'] 'patch_sys']
if sys.version_info[0] >= 3:
string_types = str,
else:
string_types = basestring,
# maps module name -> attribute name -> original item # maps module name -> attribute name -> original item
# e.g. "time" -> "sleep" -> built-in function sleep # e.g. "time" -> "sleep" -> built-in function sleep
saved = {} saved = {}
...@@ -35,7 +41,7 @@ def _get_original(name, items): ...@@ -35,7 +41,7 @@ def _get_original(name, items):
def get_original(name, item): def get_original(name, item):
if isinstance(item, basestring): if isinstance(item, string_types):
return _get_original(name, [item])[0] return _get_original(name, [item])[0]
else: else:
return _get_original(name, item) return _get_original(name, item)
......
...@@ -19,6 +19,7 @@ if PY3: ...@@ -19,6 +19,7 @@ if PY3:
del builtins del builtins
xrange = range xrange = range
string_types = str,
else: else:
def exec_(code, globs=None, locs=None): def exec_(code, globs=None, locs=None):
...@@ -34,3 +35,4 @@ else: ...@@ -34,3 +35,4 @@ else:
exec("""exec code in globs, locs""") exec("""exec code in globs, locs""")
xrange = xrange xrange = xrange
string_types = basestring,
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import six
import re import re
import greentest import greentest
import socket import socket
...@@ -122,7 +123,7 @@ def relaxed_is_equal(a, b): ...@@ -122,7 +123,7 @@ def relaxed_is_equal(a, b):
return False return False
if a == b: if a == b:
return True return True
if isinstance(a, basestring): if isinstance(a, six.string_types):
return compare_relaxed(a, b) return compare_relaxed(a, b)
if len(a) != len(b): if len(a) != len(b):
return False return False
...@@ -306,7 +307,7 @@ class TestFamily(TestCase): ...@@ -306,7 +307,7 @@ class TestFamily(TestCase):
result = function(*args) result = function(*args)
raise AssertionError('%s: Expected to raise %s, instead returned %r' % (function, error, result)) raise AssertionError('%s: Expected to raise %s, instead returned %r' % (function, error, result))
except Exception as ex: except Exception as ex:
if isinstance(error, basestring): if isinstance(error, six.string_types):
repr_error = error repr_error = error
else: else:
repr_error = repr(error) repr_error = repr(error)
......
...@@ -3,6 +3,7 @@ from __future__ import print_function ...@@ -3,6 +3,7 @@ from __future__ import print_function
import gevent import gevent
gevent.get_hub('select') # this is just to make sure we don't pass any fds to children gevent.get_hub('select') # this is just to make sure we don't pass any fds to children
from gevent import monkey; monkey.patch_all() from gevent import monkey; monkey.patch_all()
import six
import sys import sys
import os import os
import glob import glob
...@@ -84,7 +85,7 @@ def run_many(tests, expected=None, failfast=False): ...@@ -84,7 +85,7 @@ def run_many(tests, expected=None, failfast=False):
def discover(tests=None, ignore=None): def discover(tests=None, ignore=None):
if isinstance(ignore, basestring): if isinstance(ignore, six.string_types):
ignore = load_list_from_file(ignore) ignore = load_list_from_file(ignore)
ignore = set(ignore or []) ignore = set(ignore or [])
......
import sys import sys
import os import os
import re import re
import six
import traceback import traceback
import unittest import unittest
import threading import threading
...@@ -108,7 +109,7 @@ def getname(command, env=None, setenv=None): ...@@ -108,7 +109,7 @@ def getname(command, env=None, setenv=None):
if key.startswith('GEVENT_') or key.startswith('GEVENTARES_'): if key.startswith('GEVENT_') or key.startswith('GEVENTARES_'):
result.append('%s=%s' % (key, value)) result.append('%s=%s' % (key, value))
if isinstance(command, basestring): if isinstance(command, six.string_types):
result.append(command) result.append(command)
else: else:
result.extend(command) result.extend(command)
...@@ -197,7 +198,7 @@ def run(command, **kwargs): ...@@ -197,7 +198,7 @@ def run(command, **kwargs):
def parse_command(parts): def parse_command(parts):
if isinstance(parts, basestring): if isinstance(parts, six.string_types):
parts = parts.split() parts = parts.split()
environ = [] environ = []
if parts[0] == '-': if parts[0] == '-':
...@@ -259,9 +260,9 @@ def match_environ(expected_environ, actual_environ): ...@@ -259,9 +260,9 @@ def match_environ(expected_environ, actual_environ):
""" """
if expected_environ is None: if expected_environ is None:
return True return True
if isinstance(expected_environ, basestring): if isinstance(expected_environ, six.string_types):
expected_environ = expected_environ.split() expected_environ = expected_environ.split()
if isinstance(actual_environ, basestring): if isinstance(actual_environ, six.string_types):
actual_environ = actual_environ.split() actual_environ = actual_environ.split()
expected_environ = dict(x.split('=') for x in expected_environ) expected_environ = dict(x.split('=') for x in expected_environ)
actual_environ = dict(x.split('=') for x in actual_environ) actual_environ = dict(x.split('=') for x in actual_environ)
......
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