summaryrefslogtreecommitdiff
path: root/logilab
diff options
context:
space:
mode:
authorPhilippe Pepiot <philippe.pepiot@logilab.fr>2019-11-08 14:48:57 +0100
committerPhilippe Pepiot <philippe.pepiot@logilab.fr>2019-11-08 14:48:57 +0100
commit52082ad6424aaece561f50ade2f739103c177496 (patch)
tree8e6e4d2f06c74d45f3ca5966be5c88b8cd9bbb8a /logilab
parentb78546d50cac911caeaf170612bbd8bde3d9f485 (diff)
downloadlogilab-common-52082ad6424aaece561f50ade2f739103c177496.tar.gz
Nearly drop dependency on six
Diffstat (limited to 'logilab')
-rw-r--r--logilab/common/__init__.py1
-rw-r--r--logilab/common/changelog.py4
-rw-r--r--logilab/common/configuration.py7
-rw-r--r--logilab/common/daemon.py1
-rw-r--r--logilab/common/date.py2
-rw-r--r--logilab/common/decorators.py7
-rw-r--r--logilab/common/logging_ext.py4
-rw-r--r--logilab/common/modutils.py12
-rw-r--r--logilab/common/optik_ext.py4
-rw-r--r--logilab/common/registry.py9
-rw-r--r--logilab/common/shellutils.py7
-rw-r--r--logilab/common/table.py1
-rw-r--r--logilab/common/tasksqueue.py2
-rw-r--r--logilab/common/testlib.py12
-rw-r--r--logilab/common/umessage.py16
-rw-r--r--logilab/common/ureports/docbook_writer.py2
-rw-r--r--logilab/common/ureports/html_writer.py2
-rw-r--r--logilab/common/ureports/nodes.py4
-rw-r--r--logilab/common/ureports/text_writer.py2
19 files changed, 26 insertions, 73 deletions
diff --git a/logilab/common/__init__.py b/logilab/common/__init__.py
index 796831a..bf35711 100644
--- a/logilab/common/__init__.py
+++ b/logilab/common/__init__.py
@@ -150,7 +150,6 @@ def make_domains(lists):
>>> make_domains(['a', 'b'], ['c','d', 'e'])
[['a', 'b', 'a', 'b', 'a', 'b'], ['c', 'c', 'd', 'd', 'e', 'e']]
"""
- from six.moves import range
domains = []
for iterable in lists:
new_domain = iterable[:]
diff --git a/logilab/common/changelog.py b/logilab/common/changelog.py
index 3f62bd4..6eb8432 100644
--- a/logilab/common/changelog.py
+++ b/logilab/common/changelog.py
@@ -50,8 +50,6 @@ import sys
from stat import S_IWRITE
import codecs
-from six import string_types
-
BULLET = '*'
SUBBULLET = '-'
INDENT = ' ' * 4
@@ -70,7 +68,7 @@ class Version(tuple):
correctly printing it as X.Y.Z
"""
def __new__(cls, versionstr):
- if isinstance(versionstr, string_types):
+ if isinstance(versionstr, str):
versionstr = versionstr.strip(' :') # XXX (syt) duh?
parsed = cls.parse(versionstr)
else:
diff --git a/logilab/common/configuration.py b/logilab/common/configuration.py
index 7f4299c..8489de5 100644
--- a/logilab/common/configuration.py
+++ b/logilab/common/configuration.py
@@ -122,8 +122,7 @@ from os.path import exists, expanduser
from copy import copy
from warnings import warn
-from six import integer_types, string_types
-from six.moves import range, configparser as cp, input
+import configparser as cp
from logilab.common.compat import str_encode as _encode
from logilab.common.deprecation import deprecated
@@ -370,9 +369,9 @@ def format_option_value(optdict, value):
value = value.pattern
elif optdict.get('type') == 'yn':
value = value and 'yes' or 'no'
- elif isinstance(value, string_types) and value.isspace():
+ elif isinstance(value, str) and value.isspace():
value = "'%s'" % value
- elif optdict.get('type') == 'time' and isinstance(value, (float, ) + integer_types):
+ elif optdict.get('type') == 'time' and isinstance(value, (float, int)):
value = format_time(value)
elif optdict.get('type') == 'bytes' and hasattr(value, '__int__'):
value = format_bytes(value)
diff --git a/logilab/common/daemon.py b/logilab/common/daemon.py
index 40319a4..78e4743 100644
--- a/logilab/common/daemon.py
+++ b/logilab/common/daemon.py
@@ -26,7 +26,6 @@ import sys
import time
import warnings
-from six.moves import range
def setugid(user):
"""Change process user and group ID
diff --git a/logilab/common/date.py b/logilab/common/date.py
index 1d13a77..cdf2317 100644
--- a/logilab/common/date.py
+++ b/logilab/common/date.py
@@ -28,8 +28,6 @@ from datetime import date, time, datetime, timedelta
from time import strptime as time_strptime
from calendar import monthrange, timegm
-from six.moves import range
-
try:
from mx.DateTime import RelativeDateTime, Date, DateTimeType
except ImportError:
diff --git a/logilab/common/decorators.py b/logilab/common/decorators.py
index 9ec1b5f..8dd2e7f 100644
--- a/logilab/common/decorators.py
+++ b/logilab/common/decorators.py
@@ -26,12 +26,7 @@ import types
from time import process_time, time
from inspect import isgeneratorfunction
-import six
-
-if six.PY3:
- from inspect import getfullargspec
-else:
- from inspect import getargspec as getfullargspec
+from inspect import getfullargspec
from logilab.common.compat import method_type
diff --git a/logilab/common/logging_ext.py b/logilab/common/logging_ext.py
index 3b6a580..9657581 100644
--- a/logilab/common/logging_ext.py
+++ b/logilab/common/logging_ext.py
@@ -24,8 +24,6 @@ import os
import sys
import logging
-from six import string_types
-
from logilab.common.textutils import colorize_ansi
@@ -133,7 +131,7 @@ def get_threshold(debug=False, logthreshold=None):
logthreshold = logging.DEBUG
else:
logthreshold = logging.ERROR
- elif isinstance(logthreshold, string_types):
+ elif isinstance(logthreshold, str):
logthreshold = getattr(logging, THRESHOLD_MAP.get(logthreshold,
logthreshold))
return logthreshold
diff --git a/logilab/common/modutils.py b/logilab/common/modutils.py
index 030cfa3..34419bd 100644
--- a/logilab/common/modutils.py
+++ b/logilab/common/modutils.py
@@ -38,9 +38,6 @@ from imp import find_module, load_module, C_BUILTIN, PY_COMPILED, PKG_DIRECTORY
from distutils.sysconfig import get_config_var, get_python_lib, get_python_version
from distutils.errors import DistutilsPlatformError
-from six import PY3
-from six.moves import map, range
-
try:
import zipimport
except ImportError:
@@ -226,14 +223,6 @@ def _canonicalize_path(path):
return realpath(expanduser(path))
-def _path_from_filename(filename):
- if PY3:
- return filename
- else:
- if filename.endswith(".pyc"):
- return filename[:-1]
- return filename
-
@deprecated('you should avoid using modpath_from_file()')
def modpath_from_file(filename, extrapath=None):
@@ -258,7 +247,6 @@ def modpath_from_file(filename, extrapath=None):
:rtype: list(str)
:return: the corresponding splitted module's name
"""
- filename = _path_from_filename(filename)
filename = _canonicalize_path(filename)
base = os.path.splitext(filename)[0]
diff --git a/logilab/common/optik_ext.py b/logilab/common/optik_ext.py
index 95489c2..07365a7 100644
--- a/logilab/common/optik_ext.py
+++ b/logilab/common/optik_ext.py
@@ -56,8 +56,6 @@ import time
from copy import copy
from os.path import exists
-from six import integer_types
-
# python >= 2.3
from optparse import OptionParser as BaseParser, Option as BaseOption, \
OptionGroup, OptionContainer, OptionValueError, OptionError, \
@@ -171,7 +169,7 @@ def check_color(option, opt, value):
raise OptionValueError(msg % (opt, value))
def check_time(option, opt, value):
- if isinstance(value, integer_types + (float,)):
+ if isinstance(value, (int, float)):
return value
return apply_units(value, TIME_UNITS)
diff --git a/logilab/common/registry.py b/logilab/common/registry.py
index 07d4353..2a8a1c0 100644
--- a/logilab/common/registry.py
+++ b/logilab/common/registry.py
@@ -90,8 +90,6 @@ from os.path import join, isdir, exists
from logging import getLogger
from warnings import warn
-from six import string_types, add_metaclass
-
from logilab.common.modutils import modpath_from_file
from logilab.common.logging_ext import set_log_methods
from logilab.common.decorators import classproperty
@@ -317,7 +315,7 @@ class Registry(dict):
# XXXFIXME this is a duplication of unregister()
# remove register_and_replace in favor of unregister + register
# or simplify by calling unregister then register here
- if not isinstance(replaced, string_types):
+ if not isinstance(replaced, str):
replaced = self.objid(replaced)
# prevent from misspelling
assert obj is not replaced, 'replacing an object by itself: %s' % obj
@@ -623,7 +621,7 @@ class RegistryStore(dict):
:meth:`~logilab.common.registry.RegistryStore.register_and_replace` for
instance).
"""
- assert isinstance(modname, string_types), \
+ assert isinstance(modname, str), \
'modname expected to be a module name (ie string), got %r' % modname
for obj in objects:
if self.is_registrable(obj) and obj.__module__ == modname and not obj in butclasses:
@@ -985,8 +983,7 @@ class PredicateMetaClass(type):
return inst
-@add_metaclass(PredicateMetaClass)
-class Predicate(object):
+class Predicate(object, metaclass=PredicateMetaClass):
"""base class for selector classes providing implementation
for operators ``&``, ``|`` and ``~``
diff --git a/logilab/common/shellutils.py b/logilab/common/shellutils.py
index b9d5fa6..44f34ef 100644
--- a/logilab/common/shellutils.py
+++ b/logilab/common/shellutils.py
@@ -37,9 +37,6 @@ import random
import subprocess
from os.path import exists, isdir, islink, basename, join
-from six import string_types
-from six.moves import range, input as raw_input
-
from logilab.common import STD_BLACKLIST, _handle_blacklist
from logilab.common.compat import str_to_bytes
from logilab.common.deprecation import deprecated
@@ -157,7 +154,7 @@ def find(directory, exts, exclude=False, blacklist=STD_BLACKLIST):
:return:
the list of all matching files
"""
- if isinstance(exts, string_types):
+ if isinstance(exts, str):
exts = (exts,)
if exclude:
def match(filename, exts):
@@ -342,7 +339,7 @@ class progress(object):
class RawInput(object):
def __init__(self, input=None, printer=None):
- self._input = input or raw_input
+ self._input = input
self._print = printer
def ask(self, question, options, default):
diff --git a/logilab/common/table.py b/logilab/common/table.py
index 6e22c65..1f1101c 100644
--- a/logilab/common/table.py
+++ b/logilab/common/table.py
@@ -21,7 +21,6 @@ from __future__ import print_function
__docformat__ = "restructuredtext en"
-from six.moves import range
class Table(object):
"""Table defines a data table with column and row names.
diff --git a/logilab/common/tasksqueue.py b/logilab/common/tasksqueue.py
index ed74cf5..7d561ca 100644
--- a/logilab/common/tasksqueue.py
+++ b/logilab/common/tasksqueue.py
@@ -21,7 +21,7 @@ __docformat__ = "restructuredtext en"
from bisect import insort_left
-from six.moves import queue
+import queue
LOW = 0
MEDIUM = 10
diff --git a/logilab/common/testlib.py b/logilab/common/testlib.py
index fa3e36e..dae1ff5 100644
--- a/logilab/common/testlib.py
+++ b/logilab/common/testlib.py
@@ -56,8 +56,8 @@ from shutil import rmtree
from operator import itemgetter
from inspect import isgeneratorfunction
-from six import PY2, add_metaclass, string_types
-from six.moves import builtins, range, configparser, input
+import builtins
+import configparser
from logilab.common.deprecation import class_deprecated, deprecated
@@ -90,8 +90,7 @@ is_generator = deprecated('[lgc 0.63] use inspect.isgeneratorfunction')(isgenera
__unittest = 1
-@deprecated('with_tempdir is deprecated, use {0}.TemporaryDirectory.'.format(
- 'tempfile' if not PY2 else 'backports.tempfile'))
+@deprecated('with_tempdir is deprecated, use tempfile.TemporaryDirectory.')
def with_tempdir(callable):
"""A decorator ensuring no temporary file left when the function return
Work only for temporary file created with the tempfile module"""
@@ -304,7 +303,7 @@ class Tags(set):
if kwargs:
raise TypeError("%s are an invalid keyword argument for this function" % kwargs.keys())
- if len(tags) == 1 and not isinstance(tags[0], string_types):
+ if len(tags) == 1 and not isinstance(tags[0], str):
tags = tags[0]
super(Tags, self).__init__(tags, **kwargs)
@@ -550,8 +549,7 @@ class DocTestFinder(doctest.DocTestFinder):
globs, source_lines)
-@add_metaclass(class_deprecated)
-class DocTest(TestCase):
+class DocTest(TestCase, metaclass=class_deprecated):
"""trigger module doctest
I don't know how to make unittest.main consider the DocTestSuite instance
without this hack
diff --git a/logilab/common/umessage.py b/logilab/common/umessage.py
index a0394bc..e5a7f4e 100644
--- a/logilab/common/umessage.py
+++ b/logilab/common/umessage.py
@@ -27,8 +27,6 @@ from email.header import decode_header
from datetime import datetime
-from six import text_type, binary_type
-
try:
from mx.DateTime import DateTime
except ImportError:
@@ -46,9 +44,9 @@ def decode_QP(string):
# the 'official' fix is to use the new 'policy' APIs
# https://bugs.python.org/issue24797
# let's just handle this bug ourselves for now
- if isinstance(decoded, binary_type):
+ if isinstance(decoded, bytes):
decoded = decoded.decode(charset, 'replace')
- assert isinstance(decoded, text_type)
+ assert isinstance(decoded, str)
parts.append(decoded)
if sys.version_info < (3, 3):
@@ -109,29 +107,29 @@ class UMessage:
return [UMessage(msg) for msg in payload]
if message.get_content_maintype() != 'text':
return payload
- if isinstance(payload, text_type):
+ if isinstance(payload, str):
return payload
charset = message.get_content_charset() or 'iso-8859-1'
if search_function(charset) is None:
charset = 'iso-8859-1'
- return text_type(payload or b'', charset, "replace")
+ return str(payload or b'', charset, "replace")
else:
payload = UMessage(message.get_payload(index, decode))
return payload
def get_content_maintype(self):
- return text_type(self.message.get_content_maintype())
+ return str(self.message.get_content_maintype())
def get_content_type(self):
- return text_type(self.message.get_content_type())
+ return str(self.message.get_content_type())
def get_filename(self, failobj=None):
value = self.message.get_filename(failobj)
if value is failobj:
return value
try:
- return text_type(value)
+ return str(value)
except UnicodeDecodeError:
return u'error decoding filename'
diff --git a/logilab/common/ureports/docbook_writer.py b/logilab/common/ureports/docbook_writer.py
index 857068c..a520364 100644
--- a/logilab/common/ureports/docbook_writer.py
+++ b/logilab/common/ureports/docbook_writer.py
@@ -18,8 +18,6 @@
"""HTML formatting drivers for ureports"""
__docformat__ = "restructuredtext en"
-from six.moves import range
-
from logilab.common.ureports import HTMLWriter
class DocbookWriter(HTMLWriter):
diff --git a/logilab/common/ureports/html_writer.py b/logilab/common/ureports/html_writer.py
index eba34ea..02d0816 100644
--- a/logilab/common/ureports/html_writer.py
+++ b/logilab/common/ureports/html_writer.py
@@ -20,8 +20,6 @@ __docformat__ = "restructuredtext en"
from cgi import escape
-from six.moves import range
-
from logilab.common.ureports import BaseWriter
diff --git a/logilab/common/ureports/nodes.py b/logilab/common/ureports/nodes.py
index a9585b3..b90de74 100644
--- a/logilab/common/ureports/nodes.py
+++ b/logilab/common/ureports/nodes.py
@@ -23,8 +23,6 @@ __docformat__ = "restructuredtext en"
from logilab.common.tree import VNode
-from six import string_types
-
class BaseComponent(VNode):
"""base report component
@@ -81,7 +79,7 @@ class Text(BaseComponent):
super(Text, self).__init__(**kwargs)
#if isinstance(data, unicode):
# data = data.encode('ascii')
- assert isinstance(data, string_types), data.__class__
+ assert isinstance(data, str), data.__class__
self.escaped = escaped
self.data = data
diff --git a/logilab/common/ureports/text_writer.py b/logilab/common/ureports/text_writer.py
index c87613c..b894c09 100644
--- a/logilab/common/ureports/text_writer.py
+++ b/logilab/common/ureports/text_writer.py
@@ -21,8 +21,6 @@ from __future__ import print_function
__docformat__ = "restructuredtext en"
-from six.moves import range
-
from logilab.common.textutils import linesep
from logilab.common.ureports import BaseWriter