mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Py3: Replace six.string_types with str
In Python 3, six.string_types is just an alias for str. See: https://pagure.io/freeipa/issue/7715 Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
This commit is contained in:
@@ -165,7 +165,7 @@ class ACI:
|
|||||||
raise SyntaxError("invalid permission: '%s'" % p)
|
raise SyntaxError("invalid permission: '%s'" % p)
|
||||||
if not self.name:
|
if not self.name:
|
||||||
raise SyntaxError("name must be set")
|
raise SyntaxError("name must be set")
|
||||||
if not isinstance(self.name, six.string_types):
|
if not isinstance(self.name, str):
|
||||||
raise SyntaxError("name must be a string")
|
raise SyntaxError("name must be a string")
|
||||||
if not isinstance(self.target, dict) or len(self.target) == 0:
|
if not isinstance(self.target, dict) or len(self.target) == 0:
|
||||||
raise SyntaxError("target must be a non-empty dictionary")
|
raise SyntaxError("target must be a non-empty dictionary")
|
||||||
|
@@ -23,8 +23,6 @@ Foundational classes and functions.
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from ipalib.constants import NAME_REGEX, NAME_ERROR
|
from ipalib.constants import NAME_REGEX, NAME_ERROR
|
||||||
from ipalib.constants import TYPE_ERROR, SET_ERROR, DEL_ERROR, OVERRIDE_ERROR
|
from ipalib.constants import TYPE_ERROR, SET_ERROR, DEL_ERROR, OVERRIDE_ERROR
|
||||||
|
|
||||||
@@ -468,7 +466,7 @@ class NameSpace(ReadOnly):
|
|||||||
:param key: The name or index of a member, or a slice object.
|
:param key: The name or index of a member, or a slice object.
|
||||||
"""
|
"""
|
||||||
key = getattr(key, '__name__', key)
|
key = getattr(key, '__name__', key)
|
||||||
if isinstance(key, six.string_types):
|
if isinstance(key, str):
|
||||||
return self.__map[key]
|
return self.__map[key]
|
||||||
if type(key) in (int, slice):
|
if type(key) in (int, slice):
|
||||||
return self.__members[key]
|
return self.__members[key]
|
||||||
|
@@ -311,7 +311,7 @@ class textui(backend.Backend):
|
|||||||
objectClass: top
|
objectClass: top
|
||||||
objectClass: someClass
|
objectClass: someClass
|
||||||
"""
|
"""
|
||||||
assert isinstance(attr, six.string_types)
|
assert isinstance(attr, str)
|
||||||
if not isinstance(value, (list, tuple)):
|
if not isinstance(value, (list, tuple)):
|
||||||
# single-value attribute
|
# single-value attribute
|
||||||
self.print_indented(format % (attr, self.encode_binary(value)), indent)
|
self.print_indented(format % (attr, self.encode_binary(value)), indent)
|
||||||
@@ -450,7 +450,7 @@ class textui(backend.Backend):
|
|||||||
------------------
|
------------------
|
||||||
Only dashed above.
|
Only dashed above.
|
||||||
"""
|
"""
|
||||||
assert isinstance(dash, six.string_types)
|
assert isinstance(dash, str)
|
||||||
assert len(dash) == 1
|
assert len(dash) == 1
|
||||||
dashes = dash * len(string)
|
dashes = dash * len(string)
|
||||||
if above:
|
if above:
|
||||||
|
@@ -253,7 +253,7 @@ class Env:
|
|||||||
)
|
)
|
||||||
# pylint: enable=no-member
|
# pylint: enable=no-member
|
||||||
assert not hasattr(self, key)
|
assert not hasattr(self, key)
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
if isinstance(value, bytes):
|
if isinstance(value, bytes):
|
||||||
value = value.decode('utf-8')
|
value = value.decode('utf-8')
|
||||||
|
@@ -71,7 +71,7 @@ def process_message_arguments(obj, format=None, message=None, **kw):
|
|||||||
obj.format = format
|
obj.format = format
|
||||||
obj.forwarded = False
|
obj.forwarded = False
|
||||||
obj.msg = obj.format % kw
|
obj.msg = obj.format % kw
|
||||||
if isinstance(obj.format, six.string_types):
|
if isinstance(obj.format, str):
|
||||||
obj.strerror = ugettext(obj.format) % kw
|
obj.strerror = ugettext(obj.format) % kw
|
||||||
else:
|
else:
|
||||||
obj.strerror = obj.format % kw
|
obj.strerror = obj.format % kw
|
||||||
|
@@ -415,8 +415,8 @@ class Param(ReadOnly):
|
|||||||
('cli_name', str, None),
|
('cli_name', str, None),
|
||||||
('cli_short_name', str, None),
|
('cli_short_name', str, None),
|
||||||
('deprecated_cli_aliases', frozenset, frozenset()),
|
('deprecated_cli_aliases', frozenset, frozenset()),
|
||||||
('label', (six.string_types, Gettext), None),
|
('label', (str, Gettext), None),
|
||||||
('doc', (six.string_types, Gettext), None),
|
('doc', (str, Gettext), None),
|
||||||
('required', bool, True),
|
('required', bool, True),
|
||||||
('multivalue', bool, False),
|
('multivalue', bool, False),
|
||||||
('primary_key', bool, False),
|
('primary_key', bool, False),
|
||||||
@@ -1007,7 +1007,7 @@ class Bool(Param):
|
|||||||
"""
|
"""
|
||||||
if type(value) in self.allowed_types:
|
if type(value) in self.allowed_types:
|
||||||
return value
|
return value
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
value = value.lower()
|
value = value.lower()
|
||||||
if value in self.truths:
|
if value in self.truths:
|
||||||
return True
|
return True
|
||||||
@@ -1188,7 +1188,7 @@ class Decimal(Number):
|
|||||||
value = kw.get(kwparam)
|
value = kw.get(kwparam)
|
||||||
if value is None:
|
if value is None:
|
||||||
continue
|
continue
|
||||||
if isinstance(value, (six.string_types, float)):
|
if isinstance(value, (str, float)):
|
||||||
try:
|
try:
|
||||||
value = decimal.Decimal(value)
|
value = decimal.Decimal(value)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -1282,7 +1282,7 @@ class Decimal(Number):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
def _convert_scalar(self, value, index=None):
|
def _convert_scalar(self, value, index=None):
|
||||||
if isinstance(value, (six.string_types, float)):
|
if isinstance(value, (str, float)):
|
||||||
try:
|
try:
|
||||||
value = decimal.Decimal(value)
|
value = decimal.Decimal(value)
|
||||||
except decimal.DecimalException as e:
|
except decimal.DecimalException as e:
|
||||||
@@ -1313,7 +1313,7 @@ class Data(Param):
|
|||||||
('minlength', int, None),
|
('minlength', int, None),
|
||||||
('maxlength', int, None),
|
('maxlength', int, None),
|
||||||
('length', int, None),
|
('length', int, None),
|
||||||
('pattern_errmsg', (six.string_types,), None),
|
('pattern_errmsg', (str,), None),
|
||||||
)
|
)
|
||||||
|
|
||||||
re = None
|
re = None
|
||||||
@@ -1542,7 +1542,7 @@ class Str(Data):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
kwargs = Data.kwargs + (
|
kwargs = Data.kwargs + (
|
||||||
('pattern', (six.string_types,), None),
|
('pattern', (str,), None),
|
||||||
('noextrawhitespace', bool, True),
|
('noextrawhitespace', bool, True),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1630,7 +1630,7 @@ class IA5Str(Str):
|
|||||||
super(IA5Str, self).__init__(name, *rules, **kw)
|
super(IA5Str, self).__init__(name, *rules, **kw)
|
||||||
|
|
||||||
def _convert_scalar(self, value, index=None):
|
def _convert_scalar(self, value, index=None):
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
for char in value:
|
for char in value:
|
||||||
if ord(char) > 127:
|
if ord(char) > 127:
|
||||||
raise ConversionError(name=self.get_param_name(),
|
raise ConversionError(name=self.get_param_name(),
|
||||||
@@ -1805,7 +1805,7 @@ class DateTime(Param):
|
|||||||
type_error = _('must be datetime value')
|
type_error = _('must be datetime value')
|
||||||
|
|
||||||
def _convert_scalar(self, value, index=None):
|
def _convert_scalar(self, value, index=None):
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
if value == u'now':
|
if value == u'now':
|
||||||
time = datetime.datetime.utcnow()
|
time = datetime.datetime.utcnow()
|
||||||
return time
|
return time
|
||||||
|
@@ -214,7 +214,7 @@ def check_writable_file(filename):
|
|||||||
raise errors.FileError(reason=str(e))
|
raise errors.FileError(reason=str(e))
|
||||||
|
|
||||||
def normalize_zonemgr(zonemgr):
|
def normalize_zonemgr(zonemgr):
|
||||||
if not zonemgr or not isinstance(zonemgr, six.string_types):
|
if not zonemgr or not isinstance(zonemgr, str):
|
||||||
return zonemgr
|
return zonemgr
|
||||||
if '@' in zonemgr:
|
if '@' in zonemgr:
|
||||||
# local-part needs to be normalized
|
# local-part needs to be normalized
|
||||||
@@ -763,8 +763,8 @@ def _resolve_record(owner, rtype, nameserver_ip=None, edns0=False,
|
|||||||
:param flag_cd: requires dnssec=True, adds flag CD
|
:param flag_cd: requires dnssec=True, adds flag CD
|
||||||
:raise DNSException: if error occurs
|
:raise DNSException: if error occurs
|
||||||
"""
|
"""
|
||||||
assert isinstance(nameserver_ip, six.string_types) or nameserver_ip is None
|
assert isinstance(nameserver_ip, str) or nameserver_ip is None
|
||||||
assert isinstance(rtype, six.string_types)
|
assert isinstance(rtype, str)
|
||||||
|
|
||||||
res = dns.resolver.Resolver()
|
res = dns.resolver.Resolver()
|
||||||
if nameserver_ip:
|
if nameserver_ip:
|
||||||
|
@@ -394,7 +394,7 @@ class Cookie:
|
|||||||
self._timestamp = value
|
self._timestamp = value
|
||||||
elif isinstance(value, (six.integer_types, float)):
|
elif isinstance(value, (six.integer_types, float)):
|
||||||
self._timestamp = datetime.datetime.utcfromtimestamp(value)
|
self._timestamp = datetime.datetime.utcfromtimestamp(value)
|
||||||
elif isinstance(value, six.string_types):
|
elif isinstance(value, str):
|
||||||
self._timestamp = Cookie.parse_datetime(value)
|
self._timestamp = Cookie.parse_datetime(value)
|
||||||
else:
|
else:
|
||||||
raise TypeError('value must be datetime, int, long, float, basestring or None, not %s' % \
|
raise TypeError('value must be datetime, int, long, float, basestring or None, not %s' % \
|
||||||
@@ -420,7 +420,7 @@ class Cookie:
|
|||||||
self._expires = value
|
self._expires = value
|
||||||
elif isinstance(value, (six.integer_types, float)):
|
elif isinstance(value, (six.integer_types, float)):
|
||||||
self._expires = datetime.datetime.utcfromtimestamp(value)
|
self._expires = datetime.datetime.utcfromtimestamp(value)
|
||||||
elif isinstance(value, six.string_types):
|
elif isinstance(value, str):
|
||||||
self._expires = Cookie.parse_datetime(value)
|
self._expires = Cookie.parse_datetime(value)
|
||||||
else:
|
else:
|
||||||
raise TypeError('value must be datetime, int, long, float, basestring or None, not %s' % \
|
raise TypeError('value must be datetime, int, long, float, basestring or None, not %s' % \
|
||||||
|
@@ -453,7 +453,7 @@ def _adjust_indices(start, end, length):
|
|||||||
def _normalize_ava_input(val):
|
def _normalize_ava_input(val):
|
||||||
if six.PY3 and isinstance(val, bytes):
|
if six.PY3 and isinstance(val, bytes):
|
||||||
raise TypeError('expected str, got bytes: %r' % val)
|
raise TypeError('expected str, got bytes: %r' % val)
|
||||||
elif not isinstance(val, six.string_types):
|
elif not isinstance(val, str):
|
||||||
val = val_encode(six.text_type(val))
|
val = val_encode(six.text_type(val))
|
||||||
elif six.PY2 and isinstance(val, unicode):
|
elif six.PY2 and isinstance(val, unicode):
|
||||||
val = val.encode('utf-8')
|
val = val.encode('utf-8')
|
||||||
@@ -500,7 +500,7 @@ def get_ava(*args):
|
|||||||
if len(arg) != 2:
|
if len(arg) != 2:
|
||||||
raise ValueError("tuple or list must be 2-valued, not \"%s\"" % (arg))
|
raise ValueError("tuple or list must be 2-valued, not \"%s\"" % (arg))
|
||||||
ava = [_normalize_ava_input(arg[0]), _normalize_ava_input(arg[1]), 0]
|
ava = [_normalize_ava_input(arg[0]), _normalize_ava_input(arg[1]), 0]
|
||||||
elif isinstance(arg, six.string_types):
|
elif isinstance(arg, str):
|
||||||
rdn = str2rdn(arg)
|
rdn = str2rdn(arg)
|
||||||
if len(rdn) > 1:
|
if len(rdn) > 1:
|
||||||
raise TypeError("multiple AVA's specified by \"%s\"" % (arg))
|
raise TypeError("multiple AVA's specified by \"%s\"" % (arg))
|
||||||
@@ -679,7 +679,7 @@ class AVA:
|
|||||||
caseIgnoreMatch.
|
caseIgnoreMatch.
|
||||||
'''
|
'''
|
||||||
# Try coercing string to AVA, if successful compare to coerced object
|
# Try coercing string to AVA, if successful compare to coerced object
|
||||||
if isinstance(other, six.string_types):
|
if isinstance(other, str):
|
||||||
try:
|
try:
|
||||||
other_ava = AVA(other)
|
other_ava = AVA(other)
|
||||||
return self.__eq__(other_ava)
|
return self.__eq__(other_ava)
|
||||||
@@ -824,7 +824,7 @@ class RDN:
|
|||||||
|
|
||||||
if raw: # fast raw mode
|
if raw: # fast raw mode
|
||||||
avas = args
|
avas = args
|
||||||
elif ava_count == 1 and isinstance(args[0], six.string_types):
|
elif ava_count == 1 and isinstance(args[0], str):
|
||||||
avas = str2rdn(args[0])
|
avas = str2rdn(args[0])
|
||||||
sort = 1
|
sort = 1
|
||||||
elif ava_count == 1 and isinstance(args[0], RDN):
|
elif ava_count == 1 and isinstance(args[0], RDN):
|
||||||
@@ -864,7 +864,7 @@ class RDN:
|
|||||||
return self._get_ava(self._avas[key])
|
return self._get_ava(self._avas[key])
|
||||||
if isinstance(key, slice):
|
if isinstance(key, slice):
|
||||||
return [self._get_ava(ava) for ava in self._avas[key]]
|
return [self._get_ava(ava) for ava in self._avas[key]]
|
||||||
elif isinstance(key, six.string_types):
|
elif isinstance(key, str):
|
||||||
for ava in self._avas:
|
for ava in self._avas:
|
||||||
if key == val_decode(ava[0]):
|
if key == val_decode(ava[0]):
|
||||||
return val_decode(ava[1])
|
return val_decode(ava[1])
|
||||||
@@ -909,7 +909,7 @@ class RDN:
|
|||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
# Try coercing string to RDN, if successful compare to coerced object
|
# Try coercing string to RDN, if successful compare to coerced object
|
||||||
if isinstance(other, six.string_types):
|
if isinstance(other, str):
|
||||||
try:
|
try:
|
||||||
other_rdn = RDN(other)
|
other_rdn = RDN(other)
|
||||||
return self.__eq__(other_rdn)
|
return self.__eq__(other_rdn)
|
||||||
@@ -939,7 +939,7 @@ class RDN:
|
|||||||
result._avas.append((ava[0], ava[1], ava[2]))
|
result._avas.append((ava[0], ava[1], ava[2]))
|
||||||
elif isinstance(other, AVA):
|
elif isinstance(other, AVA):
|
||||||
result._avas.append(other.to_openldap())
|
result._avas.append(other.to_openldap())
|
||||||
elif isinstance(other, six.string_types):
|
elif isinstance(other, str):
|
||||||
rdn = self.__class__(other)
|
rdn = self.__class__(other)
|
||||||
for ava in rdn._avas:
|
for ava in rdn._avas:
|
||||||
result._avas.append((ava[0], ava[1], ava[2]))
|
result._avas.append((ava[0], ava[1], ava[2]))
|
||||||
@@ -1112,7 +1112,7 @@ class DN:
|
|||||||
return [[list(a) for a in rdn] for rdn in rdns]
|
return [[list(a) for a in rdn] for rdn in rdns]
|
||||||
|
|
||||||
def _rdns_from_value(self, value):
|
def _rdns_from_value(self, value):
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
try:
|
try:
|
||||||
if isinstance(value, six.text_type):
|
if isinstance(value, six.text_type):
|
||||||
value = val_encode(value)
|
value = val_encode(value)
|
||||||
@@ -1185,7 +1185,7 @@ class DN:
|
|||||||
new_dn = cls.__new__(cls)
|
new_dn = cls.__new__(cls)
|
||||||
new_dn.rdns = self.rdns[key]
|
new_dn.rdns = self.rdns[key]
|
||||||
return new_dn
|
return new_dn
|
||||||
elif isinstance(key, six.string_types):
|
elif isinstance(key, str):
|
||||||
for rdn in self.rdns:
|
for rdn in self.rdns:
|
||||||
for ava in rdn:
|
for ava in rdn:
|
||||||
if key == val_decode(ava[0]):
|
if key == val_decode(ava[0]):
|
||||||
@@ -1212,7 +1212,7 @@ class DN:
|
|||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
# Try coercing to DN, if successful compare to coerced object
|
# Try coercing to DN, if successful compare to coerced object
|
||||||
if isinstance(other, (six.string_types, RDN, AVA)):
|
if isinstance(other, (str, RDN, AVA)):
|
||||||
try:
|
try:
|
||||||
other_dn = DN(other)
|
other_dn = DN(other)
|
||||||
return self.__eq__(other_dn)
|
return self.__eq__(other_dn)
|
||||||
|
@@ -49,7 +49,7 @@ class DNSName(dns.name.Name):
|
|||||||
|
|
||||||
def __init__(self, labels, origin=None):
|
def __init__(self, labels, origin=None):
|
||||||
try:
|
try:
|
||||||
if isinstance(labels, six.string_types):
|
if isinstance(labels, str):
|
||||||
#pylint: disable=E1101
|
#pylint: disable=E1101
|
||||||
labels = dns.name.from_text(unicode(labels), origin).labels
|
labels = dns.name.from_text(unicode(labels), origin).labels
|
||||||
elif isinstance(labels, dns.name.Name):
|
elif isinstance(labels, dns.name.Name):
|
||||||
|
@@ -23,8 +23,6 @@ import time
|
|||||||
import warnings
|
import warnings
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
# Module exports
|
# Module exports
|
||||||
__all__ = ['log_mgr', 'root_logger', 'standard_logging_setup',
|
__all__ = ['log_mgr', 'root_logger', 'standard_logging_setup',
|
||||||
'ISO8601_UTC_DATETIME_FMT',
|
'ISO8601_UTC_DATETIME_FMT',
|
||||||
@@ -93,7 +91,7 @@ class _DeprecatedLogger:
|
|||||||
|
|
||||||
|
|
||||||
def get_logger(who, bind_logger_names=False):
|
def get_logger(who, bind_logger_names=False):
|
||||||
if isinstance(who, six.string_types):
|
if isinstance(who, str):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"{}.log_mgr.get_logger is deprecated, use "
|
"{}.log_mgr.get_logger is deprecated, use "
|
||||||
"logging.getLogger".format(__name__),
|
"logging.getLogger".format(__name__),
|
||||||
@@ -109,7 +107,7 @@ def get_logger(who, bind_logger_names=False):
|
|||||||
|
|
||||||
logger = logging.getLogger(logger_name)
|
logger = logging.getLogger(logger_name)
|
||||||
|
|
||||||
if not isinstance(who, six.string_types):
|
if not isinstance(who, str):
|
||||||
obj_name = '%s.%s' % (who.__module__, who.__class__.__name__)
|
obj_name = '%s.%s' % (who.__module__, who.__class__.__name__)
|
||||||
logger = _DeprecatedLogger(logger, obj_name)
|
logger = _DeprecatedLogger(logger, obj_name)
|
||||||
|
|
||||||
|
@@ -372,7 +372,7 @@ class LDAPEntry(MutableMapping):
|
|||||||
self._not_list.discard(name)
|
self._not_list.discard(name)
|
||||||
|
|
||||||
def _attr_name(self, name):
|
def _attr_name(self, name):
|
||||||
if not isinstance(name, six.string_types):
|
if not isinstance(name, str):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
"attribute name must be unicode or str, got %s object %r" % (
|
"attribute name must be unicode or str, got %s object %r" % (
|
||||||
name.__class__.__name__, name))
|
name.__class__.__name__, name))
|
||||||
|
@@ -447,7 +447,7 @@ def run(args, stdin=None, raiseonerr=True, nolog=(), env=None,
|
|||||||
p_out = None
|
p_out = None
|
||||||
p_err = None
|
p_err = None
|
||||||
|
|
||||||
if isinstance(nolog, six.string_types):
|
if isinstance(nolog, str):
|
||||||
# We expect a tuple (or list, or other iterable) of nolog strings.
|
# We expect a tuple (or list, or other iterable) of nolog strings.
|
||||||
# Passing just a single string is bad: strings are iterable, so this
|
# Passing just a single string is bad: strings are iterable, so this
|
||||||
# would result in every individual character of that string being
|
# would result in every individual character of that string being
|
||||||
@@ -585,7 +585,7 @@ def run(args, stdin=None, raiseonerr=True, nolog=(), env=None,
|
|||||||
def nolog_replace(string, nolog):
|
def nolog_replace(string, nolog):
|
||||||
"""Replace occurences of strings given in `nolog` with XXXXXXXX"""
|
"""Replace occurences of strings given in `nolog` with XXXXXXXX"""
|
||||||
for value in nolog:
|
for value in nolog:
|
||||||
if not value or not isinstance(value, six.string_types):
|
if not value or not isinstance(value, str):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
quoted = urllib.parse.quote(value)
|
quoted = urllib.parse.quote(value)
|
||||||
@@ -954,7 +954,7 @@ def user_input(prompt, default = None, allow_empty = True):
|
|||||||
return ''
|
return ''
|
||||||
raise RuntimeError("Failed to get user input")
|
raise RuntimeError("Failed to get user input")
|
||||||
|
|
||||||
if isinstance(default, six.string_types):
|
if isinstance(default, str):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
ret = input("%s [%s]: " % (prompt, default))
|
ret = input("%s [%s]: " % (prompt, default))
|
||||||
|
@@ -71,7 +71,7 @@ class Principal:
|
|||||||
"Cannot create a principal object from bytes: {!r}".format(
|
"Cannot create a principal object from bytes: {!r}".format(
|
||||||
components)
|
components)
|
||||||
)
|
)
|
||||||
elif isinstance(components, six.string_types):
|
elif isinstance(components, str):
|
||||||
# parse principal components from realm
|
# parse principal components from realm
|
||||||
self.components, self.realm = self._parse_from_text(
|
self.components, self.realm = self._parse_from_text(
|
||||||
components, realm)
|
components, realm)
|
||||||
|
@@ -20,7 +20,6 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import six
|
|
||||||
|
|
||||||
from ipapython.ipautil import run
|
from ipapython.ipautil import run
|
||||||
from ipaplatform.paths import paths
|
from ipaplatform.paths import paths
|
||||||
@@ -51,7 +50,7 @@ def get_real_key(key):
|
|||||||
One cannot request a key based on the description it was created with
|
One cannot request a key based on the description it was created with
|
||||||
so find the one we're looking for.
|
so find the one we're looking for.
|
||||||
"""
|
"""
|
||||||
assert isinstance(key, six.string_types)
|
assert isinstance(key, str)
|
||||||
result = run([paths.KEYCTL, 'search', KEYRING, KEYTYPE, key],
|
result = run([paths.KEYCTL, 'search', KEYRING, KEYTYPE, key],
|
||||||
raiseonerr=False, capture_output=True)
|
raiseonerr=False, capture_output=True)
|
||||||
if result.returncode:
|
if result.returncode:
|
||||||
@@ -66,7 +65,7 @@ def get_persistent_key(key):
|
|||||||
|
|
||||||
Assert when key is not a string-type.
|
Assert when key is not a string-type.
|
||||||
"""
|
"""
|
||||||
assert isinstance(key, six.string_types)
|
assert isinstance(key, str)
|
||||||
result = run([paths.KEYCTL, 'get_persistent', KEYRING, key],
|
result = run([paths.KEYCTL, 'get_persistent', KEYRING, key],
|
||||||
raiseonerr=False, capture_output=True)
|
raiseonerr=False, capture_output=True)
|
||||||
if result.returncode:
|
if result.returncode:
|
||||||
@@ -91,7 +90,7 @@ def has_key(key):
|
|||||||
"""
|
"""
|
||||||
Returns True/False whether the key exists in the keyring.
|
Returns True/False whether the key exists in the keyring.
|
||||||
"""
|
"""
|
||||||
assert isinstance(key, six.string_types)
|
assert isinstance(key, str)
|
||||||
try:
|
try:
|
||||||
get_real_key(key)
|
get_real_key(key)
|
||||||
return True
|
return True
|
||||||
@@ -105,7 +104,7 @@ def read_key(key):
|
|||||||
|
|
||||||
Use pipe instead of print here to ensure we always get the raw data.
|
Use pipe instead of print here to ensure we always get the raw data.
|
||||||
"""
|
"""
|
||||||
assert isinstance(key, six.string_types)
|
assert isinstance(key, str)
|
||||||
real_key = get_real_key(key)
|
real_key = get_real_key(key)
|
||||||
result = run([paths.KEYCTL, 'pipe', real_key], raiseonerr=False,
|
result = run([paths.KEYCTL, 'pipe', real_key], raiseonerr=False,
|
||||||
capture_output=True)
|
capture_output=True)
|
||||||
@@ -119,7 +118,7 @@ def update_key(key, value):
|
|||||||
"""
|
"""
|
||||||
Update the keyring data. If they key doesn't exist it is created.
|
Update the keyring data. If they key doesn't exist it is created.
|
||||||
"""
|
"""
|
||||||
assert isinstance(key, six.string_types)
|
assert isinstance(key, str)
|
||||||
assert isinstance(value, bytes)
|
assert isinstance(value, bytes)
|
||||||
if has_key(key):
|
if has_key(key):
|
||||||
real_key = get_real_key(key)
|
real_key = get_real_key(key)
|
||||||
@@ -135,7 +134,7 @@ def add_key(key, value):
|
|||||||
"""
|
"""
|
||||||
Add a key to the kernel keyring.
|
Add a key to the kernel keyring.
|
||||||
"""
|
"""
|
||||||
assert isinstance(key, six.string_types)
|
assert isinstance(key, str)
|
||||||
assert isinstance(value, bytes)
|
assert isinstance(value, bytes)
|
||||||
if has_key(key):
|
if has_key(key):
|
||||||
raise ValueError('key %s already exists' % key)
|
raise ValueError('key %s already exists' % key)
|
||||||
@@ -149,7 +148,7 @@ def del_key(key):
|
|||||||
"""
|
"""
|
||||||
Remove a key from the keyring
|
Remove a key from the keyring
|
||||||
"""
|
"""
|
||||||
assert isinstance(key, six.string_types)
|
assert isinstance(key, str)
|
||||||
real_key = get_real_key(key)
|
real_key = get_real_key(key)
|
||||||
result = run([paths.KEYCTL, 'unlink', real_key, KEYRING],
|
result = run([paths.KEYCTL, 'unlink', real_key, KEYRING],
|
||||||
raiseonerr=False)
|
raiseonerr=False)
|
||||||
|
@@ -201,7 +201,7 @@ def named_conf_set_directive(name, value, section=NAMED_SECTION_IPA,
|
|||||||
if name == match.group('name'):
|
if name == match.group('name'):
|
||||||
matched = True
|
matched = True
|
||||||
if value is not None:
|
if value is not None:
|
||||||
if not isinstance(value, six.string_types):
|
if not isinstance(value, str):
|
||||||
value = str(value)
|
value = str(value)
|
||||||
new_conf = named_conf_arg_template \
|
new_conf = named_conf_arg_template \
|
||||||
% dict(indent=last_indent,
|
% dict(indent=last_indent,
|
||||||
|
@@ -830,7 +830,7 @@ def _check_single_value_attrs(params, entry_attrs):
|
|||||||
# required, make sure we enforce that.
|
# required, make sure we enforce that.
|
||||||
def _check_empty_attrs(params, entry_attrs):
|
def _check_empty_attrs(params, entry_attrs):
|
||||||
for (a, v) in entry_attrs.items():
|
for (a, v) in entry_attrs.items():
|
||||||
if v is None or (isinstance(v, six.string_types) and len(v) == 0):
|
if v is None or (isinstance(v, str) and len(v) == 0):
|
||||||
if a in params and params[a].required:
|
if a in params and params[a].required:
|
||||||
raise errors.RequirementError(name=a)
|
raise errors.RequirementError(name=a)
|
||||||
|
|
||||||
@@ -1973,7 +1973,7 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
|
|||||||
config_attrs = config.get(
|
config_attrs = config.get(
|
||||||
self.obj.search_attributes_config, [])
|
self.obj.search_attributes_config, [])
|
||||||
if len(config_attrs) == 1 and (
|
if len(config_attrs) == 1 and (
|
||||||
isinstance(config_attrs[0], six.string_types)):
|
isinstance(config_attrs[0], str)):
|
||||||
search_attrs = config_attrs[0].split(',')
|
search_attrs = config_attrs[0].split(',')
|
||||||
|
|
||||||
search_kw = {}
|
search_kw = {}
|
||||||
|
@@ -80,7 +80,7 @@ def validate_nsaccountlock(entry_attrs):
|
|||||||
if 'nsaccountlock' in entry_attrs:
|
if 'nsaccountlock' in entry_attrs:
|
||||||
nsaccountlock = entry_attrs['nsaccountlock']
|
nsaccountlock = entry_attrs['nsaccountlock']
|
||||||
if not isinstance(nsaccountlock, (bool, Bool)):
|
if not isinstance(nsaccountlock, (bool, Bool)):
|
||||||
if not isinstance(nsaccountlock, six.string_types):
|
if not isinstance(nsaccountlock, str):
|
||||||
raise errors.OnlyOneValueAllowed(attr='nsaccountlock')
|
raise errors.OnlyOneValueAllowed(attr='nsaccountlock')
|
||||||
if nsaccountlock.lower() not in ('true', 'false'):
|
if nsaccountlock.lower() not in ('true', 'false'):
|
||||||
raise errors.ValidationError(name='nsaccountlock',
|
raise errors.ValidationError(name='nsaccountlock',
|
||||||
@@ -391,7 +391,7 @@ class baseuser(LDAPObject):
|
|||||||
if not isinstance(email, (list, tuple)):
|
if not isinstance(email, (list, tuple)):
|
||||||
email = [email]
|
email = [email]
|
||||||
for m in email:
|
for m in email:
|
||||||
if isinstance(m, six.string_types):
|
if isinstance(m, str):
|
||||||
if '@' not in m and defaultdomain:
|
if '@' not in m and defaultdomain:
|
||||||
m = m + u'@' + defaultdomain
|
m = m + u'@' + defaultdomain
|
||||||
if not Email(m):
|
if not Email(m):
|
||||||
|
@@ -1687,7 +1687,7 @@ def _create_idn_filter(cmd, ldap, term=None, **options):
|
|||||||
config = ldap.get_ipa_config()
|
config = ldap.get_ipa_config()
|
||||||
config_attrs = config.get(cmd.obj.search_attributes_config, [])
|
config_attrs = config.get(cmd.obj.search_attributes_config, [])
|
||||||
if len(config_attrs) == 1 and (isinstance(config_attrs[0],
|
if len(config_attrs) == 1 and (isinstance(config_attrs[0],
|
||||||
six.string_types)):
|
str)):
|
||||||
search_attrs = config_attrs[0].split(',')
|
search_attrs = config_attrs[0].split(',')
|
||||||
|
|
||||||
search_kw['objectclass'] = cmd.obj.object_class
|
search_kw['objectclass'] = cmd.obj.object_class
|
||||||
|
@@ -521,7 +521,7 @@ class group_find(LDAPSearch):
|
|||||||
search_kw = {}
|
search_kw = {}
|
||||||
config = ldap.get_ipa_config()
|
config = ldap.get_ipa_config()
|
||||||
attrs = config.get(self.obj.search_attributes_config, [])
|
attrs = config.get(self.obj.search_attributes_config, [])
|
||||||
if len(attrs) == 1 and isinstance(attrs[0], six.string_types):
|
if len(attrs) == 1 and isinstance(attrs[0], str):
|
||||||
search_attrs = attrs[0].split(',')
|
search_attrs = attrs[0].split(',')
|
||||||
for a in search_attrs:
|
for a in search_attrs:
|
||||||
search_kw[a] = criteria
|
search_kw[a] = criteria
|
||||||
|
@@ -137,7 +137,7 @@ class DNOrURL(DNParam):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def _convert_scalar(self, value, index=None):
|
def _convert_scalar(self, value, index=None):
|
||||||
if isinstance(value, six.string_types) and value.startswith('ldap:///'):
|
if isinstance(value, str) and value.startswith('ldap:///'):
|
||||||
value = strip_ldap_prefix(value)
|
value = strip_ldap_prefix(value)
|
||||||
return super(DNOrURL, self)._convert_scalar(value)
|
return super(DNOrURL, self)._convert_scalar(value)
|
||||||
|
|
||||||
|
@@ -28,8 +28,6 @@ import os
|
|||||||
import json
|
import json
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from ipapython import ipautil
|
from ipapython import ipautil
|
||||||
from ipatests.pytest_ipa.integration.config import Config, Domain
|
from ipatests.pytest_ipa.integration.config import Config, Domain
|
||||||
from ipalib.constants import MAX_DOMAIN_LEVEL
|
from ipalib.constants import MAX_DOMAIN_LEVEL
|
||||||
@@ -134,7 +132,7 @@ def config_from_env(env):
|
|||||||
kwargs['domains'] = []
|
kwargs['domains'] = []
|
||||||
|
|
||||||
# $IPv6SETUP needs to be 'TRUE' to enable ipv6
|
# $IPv6SETUP needs to be 'TRUE' to enable ipv6
|
||||||
if isinstance(kwargs['ipv6'], six.string_types):
|
if isinstance(kwargs['ipv6'], str):
|
||||||
kwargs['ipv6'] = (kwargs['ipv6'].upper() == 'TRUE')
|
kwargs['ipv6'] = (kwargs['ipv6'].upper() == 'TRUE')
|
||||||
|
|
||||||
config = Config(**kwargs)
|
config = Config(**kwargs)
|
||||||
|
@@ -66,11 +66,11 @@ class StageUserTracker(KerberosAliasMixin, Tracker):
|
|||||||
""" Check for non-empty unicode string for the required attributes
|
""" Check for non-empty unicode string for the required attributes
|
||||||
in the init method """
|
in the init method """
|
||||||
|
|
||||||
if not (isinstance(givenname, six.string_types) and givenname):
|
if not (isinstance(givenname, str) and givenname):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Invalid first name provided: {!r}".format(givenname)
|
"Invalid first name provided: {!r}".format(givenname)
|
||||||
)
|
)
|
||||||
if not (isinstance(sn, six.string_types) and sn):
|
if not (isinstance(sn, str) and sn):
|
||||||
raise ValueError("Invalid second name provided: {!r}".format(sn))
|
raise ValueError("Invalid second name provided: {!r}".format(sn))
|
||||||
|
|
||||||
super(StageUserTracker, self).__init__(default_version=None)
|
super(StageUserTracker, self).__init__(default_version=None)
|
||||||
|
@@ -67,11 +67,11 @@ class UserTracker(CertmapdataMixin, KerberosAliasMixin, Tracker):
|
|||||||
""" Check for non-empty unicode string for the required attributes
|
""" Check for non-empty unicode string for the required attributes
|
||||||
in the init method """
|
in the init method """
|
||||||
|
|
||||||
if not (isinstance(givenname, six.string_types) and givenname):
|
if not (isinstance(givenname, str) and givenname):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Invalid first name provided: {!r}".format(givenname)
|
"Invalid first name provided: {!r}".format(givenname)
|
||||||
)
|
)
|
||||||
if not (isinstance(sn, six.string_types) and sn):
|
if not (isinstance(sn, str) and sn):
|
||||||
raise ValueError("Invalid second name provided: {!r}".format(sn))
|
raise ValueError("Invalid second name provided: {!r}".format(sn))
|
||||||
|
|
||||||
super(UserTracker, self).__init__(default_version=None)
|
super(UserTracker, self).__init__(default_version=None)
|
||||||
|
@@ -43,7 +43,7 @@ else:
|
|||||||
# Matches a gidnumber like '1391016742'
|
# Matches a gidnumber like '1391016742'
|
||||||
# FIXME: Does it make more sense to return gidnumber, uidnumber, etc. as `int`
|
# 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`.
|
# or `long`? If not, we still need to return them as `unicode` instead of `str`.
|
||||||
fuzzy_digits = Fuzzy(r'^\d+$', type=six.string_types)
|
fuzzy_digits = Fuzzy(r'^\d+$', type=str)
|
||||||
|
|
||||||
uuid_re = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
|
uuid_re = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
|
||||||
|
|
||||||
@@ -109,18 +109,16 @@ fuzzy_caid = fuzzy_uuid
|
|||||||
fuzzy_ipauniqueid = Fuzzy('(?i)ipauniqueid=%s' % uuid_re)
|
fuzzy_ipauniqueid = Fuzzy('(?i)ipauniqueid=%s' % uuid_re)
|
||||||
|
|
||||||
# Matches a hash signature, not enforcing length
|
# Matches a hash signature, not enforcing length
|
||||||
fuzzy_hash = Fuzzy(
|
fuzzy_hash = Fuzzy(r'^([a-f0-9][a-f0-9]:)+[a-f0-9][a-f0-9]$', type=str)
|
||||||
r'^([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
|
# Matches a date, like Tue Apr 26 17:45:35 2016 UTC
|
||||||
fuzzy_date = Fuzzy(
|
fuzzy_date = Fuzzy(
|
||||||
r'^[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} UTC$'
|
r'^[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} UTC$'
|
||||||
)
|
)
|
||||||
|
|
||||||
fuzzy_issuer = Fuzzy(type=six.string_types)
|
fuzzy_issuer = Fuzzy(type=str)
|
||||||
|
|
||||||
fuzzy_hex = Fuzzy(r'^0x[0-9a-fA-F]+$', type=six.string_types)
|
fuzzy_hex = Fuzzy(r'^0x[0-9a-fA-F]+$', type=str)
|
||||||
|
|
||||||
# Matches password - password consists of all printable characters without
|
# Matches password - password consists of all printable characters without
|
||||||
# whitespaces. The only exception is space, but space cannot be at the
|
# whitespaces. The only exception is space, but space cannot be at the
|
||||||
@@ -131,7 +129,7 @@ fuzzy_password = Fuzzy(r'^\S([\S ]*\S)*$')
|
|||||||
fuzzy_dergeneralizedtime = Fuzzy(type=datetime.datetime)
|
fuzzy_dergeneralizedtime = Fuzzy(type=datetime.datetime)
|
||||||
|
|
||||||
# match any string
|
# match any string
|
||||||
fuzzy_string = Fuzzy(type=six.string_types)
|
fuzzy_string = Fuzzy(type=str)
|
||||||
|
|
||||||
fuzzy_bytes = Fuzzy(type=bytes)
|
fuzzy_bytes = Fuzzy(type=bytes)
|
||||||
|
|
||||||
|
@@ -278,7 +278,7 @@ class Fuzzy:
|
|||||||
:param test: A callable used to perform equality test, e.g.
|
:param test: A callable used to perform equality test, e.g.
|
||||||
``lambda other: other >= 18``
|
``lambda other: other >= 18``
|
||||||
"""
|
"""
|
||||||
assert regex is None or isinstance(regex, six.string_types)
|
assert regex is None or isinstance(regex, str)
|
||||||
assert test is None or callable(test)
|
assert test is None or callable(test)
|
||||||
if regex is None:
|
if regex is None:
|
||||||
self.re = None
|
self.re = None
|
||||||
@@ -286,7 +286,7 @@ class Fuzzy:
|
|||||||
self.re = re.compile(regex)
|
self.re = re.compile(regex)
|
||||||
if type is None:
|
if type is None:
|
||||||
type = unicode
|
type = unicode
|
||||||
assert type in (unicode, bytes, six.string_types)
|
assert type in (unicode, bytes, str)
|
||||||
self.regex = regex
|
self.regex = regex
|
||||||
self.type = type
|
self.type = type
|
||||||
self.test = test
|
self.test = test
|
||||||
@@ -398,7 +398,7 @@ def assert_deepequal(expected, got, doc='', stack=tuple()):
|
|||||||
if isinstance(got, tuple):
|
if isinstance(got, tuple):
|
||||||
got = list(got)
|
got = list(got)
|
||||||
if isinstance(expected, DN):
|
if isinstance(expected, DN):
|
||||||
if isinstance(got, six.string_types):
|
if isinstance(got, str):
|
||||||
got = DN(got)
|
got = DN(got)
|
||||||
if (
|
if (
|
||||||
not (isinstance(expected, Fuzzy)
|
not (isinstance(expected, Fuzzy)
|
||||||
|
Reference in New Issue
Block a user