summaryrefslogtreecommitdiff
path: root/pylint/utils.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2015-07-26 10:52:05 +0200
committerFlorian Bruhin <me@the-compiler.org>2015-07-26 10:52:05 +0200
commit4f67ba0b84ad47ed47559b6a2c9e9edfa002ef57 (patch)
treea36a776d65de3d99c8b73e669340d29c656eb4ad /pylint/utils.py
parent7fe9ab5b254ecf606601f9c3c9034e6118f5d66e (diff)
downloadpylint-4f67ba0b84ad47ed47559b6a2c9e9edfa002ef57.tar.gz
Get rid of logilab.common.optik_ext and logilab.common.textutils.
Diffstat (limited to 'pylint/utils.py')
-rw-r--r--pylint/utils.py61
1 files changed, 60 insertions, 1 deletions
diff --git a/pylint/utils.py b/pylint/utils.py
index d2c9ed8..c573409 100644
--- a/pylint/utils.py
+++ b/pylint/utils.py
@@ -24,13 +24,13 @@ import re
import sys
import tokenize
import warnings
+import textwrap
from os.path import dirname, basename, splitext, exists, isdir, join, normpath
import six
from six.moves import zip # pylint: disable=redefined-builtin
from logilab.common.interface import implements
-from logilab.common.textutils import normalize_text
from logilab.common.configuration import rest_format_section
from logilab.common.ureports import Section
@@ -941,3 +941,62 @@ def deprecated_option(shortname=None, opt_type=None, help_msg=None):
if shortname:
option['shortname'] = shortname
return option
+
+
+def splitstrip(string, sep=','):
+ """return a list of stripped string by splitting the string given as
+ argument on `sep` (',' by default). Empty string are discarded.
+
+ >>> splitstrip('a, b, c , 4,,')
+ ['a', 'b', 'c', '4']
+ >>> splitstrip('a')
+ ['a']
+ >>>
+
+ :type string: str or unicode
+ :param string: a csv line
+
+ :type sep: str or unicode
+ :param sep: field separator, default to the comma (',')
+
+ :rtype: str or unicode
+ :return: the unquoted string (or the input string if it wasn't quoted)
+ """
+ return [word.strip() for word in string.split(sep) if word.strip()]
+
+
+def unquote(string):
+ """remove optional quotes (simple or double) from the string
+
+ :type string: str or unicode
+ :param string: an optionally quoted string
+
+ :rtype: str or unicode
+ :return: the unquoted string (or the input string if it wasn't quoted)
+ """
+ if not string:
+ return string
+ if string[0] in '"\'':
+ string = string[1:]
+ if string[-1] in '"\'':
+ string = string[:-1]
+ return string
+
+
+def normalize_text(text, line_len=80, indent=''):
+ """Wrap the text on the given line length."""
+ return '\n'.join(textwrap.wrap(text, width=line_len, initial_indent=indent,
+ subsequent_indent=indent))
+
+
+def check_csv(option, opt, value):
+ """check a csv value by trying to split it
+ return the list of separated values
+ """
+ if isinstance(value, (list, tuple)):
+ return value
+ try:
+ return splitstrip(value)
+ except ValueError:
+ raise OptionValueError(
+ "option %s: invalid csv value: %r" % (opt, value))