Use six.string_types instead of "basestring"

Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
This commit is contained in:
Petr Viktorin
2015-08-10 18:29:33 +02:00
committed by Jan Cholasta
parent 404177f7a3
commit dd16cc98b0
22 changed files with 114 additions and 71 deletions

View File

@@ -28,6 +28,8 @@ import os
import json
import collections
import six
from ipapython import ipautil
from ipatests.test_integration.config import Config, Domain
@@ -128,7 +130,7 @@ def config_from_env(env):
kwargs['domains'] = []
# $IPv6SETUP needs to be 'TRUE' to enable ipv6
if isinstance(kwargs['ipv6'], basestring):
if isinstance(kwargs['ipv6'], six.string_types):
kwargs['ipv6'] = (kwargs['ipv6'].upper() == 'TRUE')
config = Config(**kwargs)

View File

@@ -25,6 +25,7 @@ import datetime
import nose
import contextlib
import six
from ipatests.util import assert_deepequal, Fuzzy
from ipalib import api, request, errors
@@ -35,7 +36,7 @@ from ipapython.version import API_VERSION
# Matches a gidnumber like '1391016742'
# FIXME: Does it make more sense to return gidnumber, uidnumber, etc. as `int`
# or `long`? If not, we still need to return them as `unicode` instead of `str`.
fuzzy_digits = Fuzzy('^\d+$', type=basestring)
fuzzy_digits = Fuzzy('^\d+$', type=six.string_types)
uuid_re = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
@@ -76,14 +77,14 @@ fuzzy_sudocmddn = Fuzzy(
)
# Matches a hash signature, not enforcing length
fuzzy_hash = Fuzzy('^([a-f0-9][a-f0-9]:)+[a-f0-9][a-f0-9]$', type=basestring)
fuzzy_hash = Fuzzy('^([a-f0-9][a-f0-9]:)+[a-f0-9][a-f0-9]$', type=six.string_types)
# Matches a date, like Tue Apr 26 17:45:35 2016 UTC
fuzzy_date = Fuzzy('^[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} UTC$')
fuzzy_issuer = Fuzzy(type=basestring, test=lambda issuer: valid_issuer(issuer))
fuzzy_issuer = Fuzzy(type=six.string_types, test=lambda issuer: valid_issuer(issuer))
fuzzy_hex = Fuzzy('^0x[0-9a-fA-F]+$', type=basestring)
fuzzy_hex = Fuzzy('^0x[0-9a-fA-F]+$', type=six.string_types)
# Matches password - password consists of all printable characters without whitespaces
# The only exception is space, but space cannot be at the beggingin or end of the pwd
@@ -93,7 +94,7 @@ fuzzy_password = Fuzzy('^\S([\S ]*\S)*$')
fuzzy_dergeneralizedtime = Fuzzy(type=datetime.datetime)
# match any string
fuzzy_string = Fuzzy(type=basestring)
fuzzy_string = Fuzzy(type=six.string_types)
# case insensitive match of sets
def fuzzy_set_ci(s):

View File

@@ -24,12 +24,15 @@ Common utility functions and classes for unit tests.
import inspect
import os
from os import path
import ldap
import ldap.sasl
import ldap.modlist
import tempfile
import shutil
import re
import six
import ldap
import ldap.sasl
import ldap.modlist
import ipalib
from ipalib.plugable import Plugin
from ipalib.request import context
@@ -213,7 +216,7 @@ class Fuzzy(object):
:param test: A callable used to perform equality test, e.g.
``lambda other: other >= 18``
"""
assert regex is None or isinstance(regex, basestring)
assert regex is None or isinstance(regex, six.string_types)
assert test is None or callable(test)
if regex is None:
self.re = None
@@ -221,7 +224,7 @@ class Fuzzy(object):
self.re = re.compile(regex)
if type is None:
type = unicode
assert type in (unicode, str, basestring)
assert type in (unicode, str, six.string_types)
self.regex = regex
self.type = type
self.test = test
@@ -309,7 +312,7 @@ def assert_deepequal(expected, got, doc='', stack=tuple()):
if isinstance(got, tuple):
got = list(got)
if isinstance(expected, DN):
if isinstance(got, basestring):
if isinstance(got, six.string_types):
got = DN(got)
if not (isinstance(expected, Fuzzy) or callable(expected) or type(expected) is type(got)):
raise AssertionError(