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