diff options
author | Petr Viktorin <pviktori@redhat.com> | 2015-08-10 18:29:33 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2015-09-01 11:42:01 +0200 |
commit | dd16cc98b0d67f1448bf9de25f8adce512b1431c (patch) | |
tree | e9fa6c41da6894b16a366b02d61c29b15c5a9b4a /ipapython | |
parent | 404177f7a322ced4e05cfc6b2ed330b6fcce0c04 (diff) | |
download | freeipa-dd16cc98b0d67f1448bf9de25f8adce512b1431c.tar.gz freeipa-dd16cc98b0d67f1448bf9de25f8adce512b1431c.tar.xz freeipa-dd16cc98b0d67f1448bf9de25f8adce512b1431c.zip |
Use six.string_types instead of "basestring"
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipapython')
-rw-r--r-- | ipapython/cookie.py | 7 | ||||
-rw-r--r-- | ipapython/dn.py | 24 | ||||
-rw-r--r-- | ipapython/ipaldap.py | 3 | ||||
-rw-r--r-- | ipapython/ipautil.py | 12 | ||||
-rw-r--r-- | ipapython/log_manager.py | 20 |
5 files changed, 38 insertions, 28 deletions
diff --git a/ipapython/cookie.py b/ipapython/cookie.py index c12e0a127..8b91457d9 100644 --- a/ipapython/cookie.py +++ b/ipapython/cookie.py @@ -23,6 +23,9 @@ import datetime import email.utils from urllib2 import urlparse from calendar import timegm + +import six + from ipapython.ipa_log_manager import log_mgr ''' @@ -390,7 +393,7 @@ class Cookie(object): self._timestamp = value elif isinstance(value, (int, long, float)): self._timestamp = datetime.datetime.utcfromtimestamp(value) - elif isinstance(value, basestring): + elif isinstance(value, six.string_types): self._timestamp = Cookie.parse_datetime(value) else: raise TypeError('value must be datetime, int, long, float, basestring or None, not %s' % \ @@ -416,7 +419,7 @@ class Cookie(object): self._expires = value elif isinstance(value, (int, long, float)): self._expires = datetime.datetime.utcfromtimestamp(value) - elif isinstance(value, basestring): + elif isinstance(value, six.string_types): self._expires = Cookie.parse_datetime(value) else: raise TypeError('value must be datetime, int, long, float, basestring or None, not %s' % \ diff --git a/ipapython/dn.py b/ipapython/dn.py index 59e9368ae..e6d9dbeb5 100644 --- a/ipapython/dn.py +++ b/ipapython/dn.py @@ -418,9 +418,11 @@ to the constructor. The result may share underlying structure. ''' +import sys + from ldap.dn import str2dn, dn2str from ldap import DECODING_ERROR -import sys +import six __all__ = 'AVA', 'RDN', 'DN' @@ -443,7 +445,7 @@ def _adjust_indices(start, end, length): def _normalize_ava_input(val): - if not isinstance(val, basestring): + if not isinstance(val, six.string_types): val = unicode(val).encode('utf-8') elif isinstance(val, unicode): val = val.encode('utf-8') @@ -490,7 +492,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, basestring): + elif isinstance(arg, six.string_types): rdn = str2rdn(arg) if len(rdn) > 1: raise TypeError("multiple AVA's specified by \"%s\"" % (arg)) @@ -651,7 +653,7 @@ class AVA(object): caseIgnoreMatch. ''' # Try coercing string to AVA, if successful compare to coerced object - if isinstance(other, basestring): + if isinstance(other, six.string_types): try: other_ava = AVA(other) return self.__eq__(other_ava) @@ -795,7 +797,7 @@ class RDN(object): if raw: # fast raw mode avas = args - elif ava_count == 1 and isinstance(args[0], basestring): + elif ava_count == 1 and isinstance(args[0], six.string_types): avas = str2rdn(args[0]) sort = 1 elif ava_count == 1 and isinstance(args[0], RDN): @@ -835,7 +837,7 @@ class RDN(object): 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, basestring): + elif isinstance(key, six.string_types): for ava in self._avas: if key == ava[0].decode('utf-8'): return ava[1].decode('utf-8') @@ -880,7 +882,7 @@ class RDN(object): def __eq__(self, other): # Try coercing string to RDN, if successful compare to coerced object - if isinstance(other, basestring): + if isinstance(other, six.string_types): try: other_rdn = RDN(other) return self.__eq__(other_rdn) @@ -910,7 +912,7 @@ class RDN(object): result._avas.append((ava[0], ava[1], ava[2])) elif isinstance(other, AVA): result._avas.append(other.to_openldap()) - elif isinstance(other, basestring): + elif isinstance(other, six.string_types): rdn = self.__class__(other) for ava in rdn._avas: result._avas.append((ava[0], ava[1], ava[2])) @@ -1080,7 +1082,7 @@ class DN(object): return [[list(a) for a in rdn] for rdn in rdns] def _rdns_from_value(self, value): - if isinstance(value, basestring): + if isinstance(value, six.string_types): try: if isinstance(value, unicode): value = value.encode('utf-8') @@ -1144,7 +1146,7 @@ class DN(object): new_dn = cls.__new__(cls) new_dn.rdns = self.rdns[key] return new_dn - elif isinstance(key, basestring): + elif isinstance(key, six.string_types): for rdn in self.rdns: for ava in rdn: if key == ava[0].decode('utf-8'): @@ -1170,7 +1172,7 @@ class DN(object): def __eq__(self, other): # Try coercing to DN, if successful compare to coerced object - if isinstance(other, (basestring, RDN, AVA)): + if isinstance(other, (six.string_types, RDN, AVA)): try: other_dn = DN(other) return self.__eq__(other_dn) diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py index 3d38d6050..124ab3c20 100644 --- a/ipapython/ipaldap.py +++ b/ipapython/ipaldap.py @@ -36,6 +36,7 @@ import ldap.filter from ldap.ldapobject import SimpleLDAPObject from ldap.controls import SimplePagedResultsControl import ldapurl +import six from ipalib import errors, _ from ipalib.constants import LDAP_GENERALIZED_TIME_FORMAT @@ -330,7 +331,7 @@ class LDAPEntry(collections.MutableMapping): self._not_list.discard(name) def _attr_name(self, name): - if not isinstance(name, basestring): + if not isinstance(name, six.string_types): raise TypeError( "attribute name must be unicode or str, got %s object %r" % ( name.__class__.__name__, name)) diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index d959bb369..80ce83506 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -37,9 +37,11 @@ import time import gssapi import pwd import grp +from contextlib import contextmanager + from dns import resolver, rdatatype from dns.exception import DNSException -from contextlib import contextmanager +import six from ipapython.ipa_log_manager import * from ipapython import ipavalidate @@ -117,7 +119,7 @@ class CheckedIPAddress(netaddr.IPAddress): # netaddr.IPAddress doesn't handle zone indices in textual # IPv6 addresses. Try removing zone index and parse the # address again. - if not isinstance(addr, basestring): + if not isinstance(addr, six.string_types): raise addr, sep, foo = addr.partition('%') if sep != '%': @@ -295,7 +297,7 @@ def run(args, stdin=None, raiseonerr=True, p_out = None p_err = None - if isinstance(nolog, basestring): + if isinstance(nolog, six.string_types): # We expect a tuple (or list, or other iterable) of nolog strings. # Passing just a single string is bad: strings are also, so this # would result in every individual character of that string being @@ -383,7 +385,7 @@ def run(args, stdin=None, raiseonerr=True, def nolog_replace(string, nolog): """Replace occurences of strings given in `nolog` with XXXXXXXX""" for value in nolog: - if not isinstance(value, basestring): + if not isinstance(value, six.string_types): continue quoted = urllib2.quote(value) @@ -761,7 +763,7 @@ def user_input(prompt, default = None, allow_empty = True): return '' raise RuntimeError("Failed to get user input") - if isinstance(default, basestring): + if isinstance(default, six.string_types): while True: try: ret = raw_input("%s [%s]: " % (prompt, default)) diff --git a/ipapython/log_manager.py b/ipapython/log_manager.py index 7e4545d14..e1ea434c5 100644 --- a/ipapython/log_manager.py +++ b/ipapython/log_manager.py @@ -509,6 +509,8 @@ import logging import re import time +import six + #------------------------------------------------------------------------------- # Default format LOGGING_DEFAULT_FORMAT = '%(levelname)s %(message)s' @@ -600,7 +602,7 @@ def parse_log_level(level): ''' # Is it a string representation of an integer? # If so convert to an int. - if isinstance(level, basestring): + if isinstance(level, six.string_types): try: level = int(level) except: @@ -608,7 +610,7 @@ def parse_log_level(level): # If it's a string lookup it's name and map to logging level # otherwise validate the integer value is in range. - if isinstance(level, basestring): + if isinstance(level, six.string_types): result = log_level_name_map.get(level.lower()) #pylint: disable=E1103 if result is None: raise ValueError('unknown log level (%s)' % level) @@ -959,7 +961,7 @@ class LogManager(object): if not isinstance(config, dict): raise TypeError('expected dict for handler config, got "%s"', type(config)) - if isinstance(logger, basestring): + if isinstance(logger, six.string_types): logger = self.get_logger(logger) else: if not isinstance(logger, logging.Logger): @@ -1167,7 +1169,7 @@ class LogManager(object): user = cfg.get('user') group = cfg.get('group') if user is not None: - if isinstance(user, basestring): + if isinstance(user, six.string_types): pw = pwd.getpwnam(user) uid = pw.pw_uid elif isinstance(user, int): @@ -1175,7 +1177,7 @@ class LogManager(object): else: raise TypeError("user (%s) is not int or basestring" % user) if group is not None: - if isinstance(group, basestring): + if isinstance(group, six.string_types): pw = pwd.getpwnam(group) gid = pw.pw_gid elif isinstance(group, int): @@ -1216,7 +1218,7 @@ class LogManager(object): datefmt = cfg.get("datefmt", None) formatter = logging.Formatter(format, datefmt) time_zone_converter = cfg.get('time_zone_converter', time.localtime) - if isinstance(time_zone_converter, basestring): + if isinstance(time_zone_converter, six.string_types): converter = {'local' : time.localtime, 'localtime' : time.localtime, 'gmt' : time.gmtime, @@ -1310,7 +1312,7 @@ class LogManager(object): List of loggers with the handler is bound to. ''' - if isinstance(handler, basestring): + if isinstance(handler, six.string_types): handler = self.get_handler(handler) elif isinstance(handler, logging.Handler): if not handler in self.handlers.values(): @@ -1344,7 +1346,7 @@ class LogManager(object): use configure_state to track the state of the log manager. ''' - if isinstance(handler, basestring): + if isinstance(handler, six.string_types): handler = self.get_handler(handler) elif not isinstance(handler, logging.Handler): raise TypeError('handler must be basestring or Handler object, got %s' % type(handler)) @@ -1522,7 +1524,7 @@ class LogManager(object): ''' is_object = False - if isinstance(who, basestring): + if isinstance(who, six.string_types): obj_name = who else: is_object = True |