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:
@@ -394,7 +394,7 @@ class Cookie:
|
||||
self._timestamp = value
|
||||
elif isinstance(value, (six.integer_types, float)):
|
||||
self._timestamp = datetime.datetime.utcfromtimestamp(value)
|
||||
elif isinstance(value, six.string_types):
|
||||
elif isinstance(value, str):
|
||||
self._timestamp = Cookie.parse_datetime(value)
|
||||
else:
|
||||
raise TypeError('value must be datetime, int, long, float, basestring or None, not %s' % \
|
||||
@@ -420,7 +420,7 @@ class Cookie:
|
||||
self._expires = value
|
||||
elif isinstance(value, (six.integer_types, float)):
|
||||
self._expires = datetime.datetime.utcfromtimestamp(value)
|
||||
elif isinstance(value, six.string_types):
|
||||
elif isinstance(value, str):
|
||||
self._expires = Cookie.parse_datetime(value)
|
||||
else:
|
||||
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):
|
||||
if six.PY3 and isinstance(val, bytes):
|
||||
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))
|
||||
elif six.PY2 and isinstance(val, unicode):
|
||||
val = val.encode('utf-8')
|
||||
@@ -500,7 +500,7 @@ def get_ava(*args):
|
||||
if len(arg) != 2:
|
||||
raise ValueError("tuple or list must be 2-valued, not \"%s\"" % (arg))
|
||||
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)
|
||||
if len(rdn) > 1:
|
||||
raise TypeError("multiple AVA's specified by \"%s\"" % (arg))
|
||||
@@ -679,7 +679,7 @@ class AVA:
|
||||
caseIgnoreMatch.
|
||||
'''
|
||||
# Try coercing string to AVA, if successful compare to coerced object
|
||||
if isinstance(other, six.string_types):
|
||||
if isinstance(other, str):
|
||||
try:
|
||||
other_ava = AVA(other)
|
||||
return self.__eq__(other_ava)
|
||||
@@ -824,7 +824,7 @@ class RDN:
|
||||
|
||||
if raw: # fast raw mode
|
||||
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])
|
||||
sort = 1
|
||||
elif ava_count == 1 and isinstance(args[0], RDN):
|
||||
@@ -864,7 +864,7 @@ class RDN:
|
||||
return self._get_ava(self._avas[key])
|
||||
if isinstance(key, slice):
|
||||
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:
|
||||
if key == val_decode(ava[0]):
|
||||
return val_decode(ava[1])
|
||||
@@ -909,7 +909,7 @@ class RDN:
|
||||
|
||||
def __eq__(self, other):
|
||||
# Try coercing string to RDN, if successful compare to coerced object
|
||||
if isinstance(other, six.string_types):
|
||||
if isinstance(other, str):
|
||||
try:
|
||||
other_rdn = RDN(other)
|
||||
return self.__eq__(other_rdn)
|
||||
@@ -939,7 +939,7 @@ class RDN:
|
||||
result._avas.append((ava[0], ava[1], ava[2]))
|
||||
elif isinstance(other, AVA):
|
||||
result._avas.append(other.to_openldap())
|
||||
elif isinstance(other, six.string_types):
|
||||
elif isinstance(other, str):
|
||||
rdn = self.__class__(other)
|
||||
for ava in rdn._avas:
|
||||
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]
|
||||
|
||||
def _rdns_from_value(self, value):
|
||||
if isinstance(value, six.string_types):
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
if isinstance(value, six.text_type):
|
||||
value = val_encode(value)
|
||||
@@ -1185,7 +1185,7 @@ class DN:
|
||||
new_dn = cls.__new__(cls)
|
||||
new_dn.rdns = self.rdns[key]
|
||||
return new_dn
|
||||
elif isinstance(key, six.string_types):
|
||||
elif isinstance(key, str):
|
||||
for rdn in self.rdns:
|
||||
for ava in rdn:
|
||||
if key == val_decode(ava[0]):
|
||||
@@ -1212,7 +1212,7 @@ class DN:
|
||||
|
||||
def __eq__(self, other):
|
||||
# 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:
|
||||
other_dn = DN(other)
|
||||
return self.__eq__(other_dn)
|
||||
|
||||
@@ -49,7 +49,7 @@ class DNSName(dns.name.Name):
|
||||
|
||||
def __init__(self, labels, origin=None):
|
||||
try:
|
||||
if isinstance(labels, six.string_types):
|
||||
if isinstance(labels, str):
|
||||
#pylint: disable=E1101
|
||||
labels = dns.name.from_text(unicode(labels), origin).labels
|
||||
elif isinstance(labels, dns.name.Name):
|
||||
|
||||
@@ -23,8 +23,6 @@ import time
|
||||
import warnings
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
# Module exports
|
||||
__all__ = ['log_mgr', 'root_logger', 'standard_logging_setup',
|
||||
'ISO8601_UTC_DATETIME_FMT',
|
||||
@@ -93,7 +91,7 @@ class _DeprecatedLogger:
|
||||
|
||||
|
||||
def get_logger(who, bind_logger_names=False):
|
||||
if isinstance(who, six.string_types):
|
||||
if isinstance(who, str):
|
||||
warnings.warn(
|
||||
"{}.log_mgr.get_logger is deprecated, use "
|
||||
"logging.getLogger".format(__name__),
|
||||
@@ -109,7 +107,7 @@ def get_logger(who, bind_logger_names=False):
|
||||
|
||||
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__)
|
||||
logger = _DeprecatedLogger(logger, obj_name)
|
||||
|
||||
|
||||
@@ -372,7 +372,7 @@ class LDAPEntry(MutableMapping):
|
||||
self._not_list.discard(name)
|
||||
|
||||
def _attr_name(self, name):
|
||||
if not isinstance(name, six.string_types):
|
||||
if not isinstance(name, str):
|
||||
raise TypeError(
|
||||
"attribute name must be unicode or str, got %s object %r" % (
|
||||
name.__class__.__name__, name))
|
||||
|
||||
@@ -447,7 +447,7 @@ def run(args, stdin=None, raiseonerr=True, nolog=(), env=None,
|
||||
p_out = 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.
|
||||
# Passing just a single string is bad: strings are iterable, so this
|
||||
# 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):
|
||||
"""Replace occurences of strings given in `nolog` with XXXXXXXX"""
|
||||
for value in nolog:
|
||||
if not value or not isinstance(value, six.string_types):
|
||||
if not value or not isinstance(value, str):
|
||||
continue
|
||||
|
||||
quoted = urllib.parse.quote(value)
|
||||
@@ -954,7 +954,7 @@ def user_input(prompt, default = None, allow_empty = True):
|
||||
return ''
|
||||
raise RuntimeError("Failed to get user input")
|
||||
|
||||
if isinstance(default, six.string_types):
|
||||
if isinstance(default, str):
|
||||
while True:
|
||||
try:
|
||||
ret = input("%s [%s]: " % (prompt, default))
|
||||
|
||||
@@ -71,7 +71,7 @@ class Principal:
|
||||
"Cannot create a principal object from bytes: {!r}".format(
|
||||
components)
|
||||
)
|
||||
elif isinstance(components, six.string_types):
|
||||
elif isinstance(components, str):
|
||||
# parse principal components from realm
|
||||
self.components, self.realm = self._parse_from_text(
|
||||
components, realm)
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import six
|
||||
|
||||
from ipapython.ipautil import run
|
||||
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
|
||||
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],
|
||||
raiseonerr=False, capture_output=True)
|
||||
if result.returncode:
|
||||
@@ -66,7 +65,7 @@ def get_persistent_key(key):
|
||||
|
||||
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],
|
||||
raiseonerr=False, capture_output=True)
|
||||
if result.returncode:
|
||||
@@ -91,7 +90,7 @@ def has_key(key):
|
||||
"""
|
||||
Returns True/False whether the key exists in the keyring.
|
||||
"""
|
||||
assert isinstance(key, six.string_types)
|
||||
assert isinstance(key, str)
|
||||
try:
|
||||
get_real_key(key)
|
||||
return True
|
||||
@@ -105,7 +104,7 @@ def read_key(key):
|
||||
|
||||
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)
|
||||
result = run([paths.KEYCTL, 'pipe', real_key], raiseonerr=False,
|
||||
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.
|
||||
"""
|
||||
assert isinstance(key, six.string_types)
|
||||
assert isinstance(key, str)
|
||||
assert isinstance(value, bytes)
|
||||
if has_key(key):
|
||||
real_key = get_real_key(key)
|
||||
@@ -135,7 +134,7 @@ def add_key(key, value):
|
||||
"""
|
||||
Add a key to the kernel keyring.
|
||||
"""
|
||||
assert isinstance(key, six.string_types)
|
||||
assert isinstance(key, str)
|
||||
assert isinstance(value, bytes)
|
||||
if has_key(key):
|
||||
raise ValueError('key %s already exists' % key)
|
||||
@@ -149,7 +148,7 @@ def del_key(key):
|
||||
"""
|
||||
Remove a key from the keyring
|
||||
"""
|
||||
assert isinstance(key, six.string_types)
|
||||
assert isinstance(key, str)
|
||||
real_key = get_real_key(key)
|
||||
result = run([paths.KEYCTL, 'unlink', real_key, KEYRING],
|
||||
raiseonerr=False)
|
||||
|
||||
Reference in New Issue
Block a user