diff options
-rw-r--r-- | optik_ext.py | 4 | ||||
-rw-r--r-- | test/unittest_textutils.py | 2 | ||||
-rw-r--r-- | textutils.py | 16 |
3 files changed, 13 insertions, 9 deletions
diff --git a/optik_ext.py b/optik_ext.py index 70fe6d9..7966d36 100644 --- a/optik_ext.py +++ b/optik_ext.py @@ -69,7 +69,7 @@ except ImportError: OPTPARSE_FORMAT_DEFAULT = sys.version_info >= (2, 4) -from logilab.common.textutils import get_csv +from logilab.common.textutils import splitstrip def check_regexp(option, opt, value): """check a regexp value by trying to compile it @@ -90,7 +90,7 @@ def check_csv(option, opt, value): if isinstance(value, (list, tuple)): return value try: - return get_csv(value) + return splitstrip(value) except ValueError: raise OptionValueError( "option %s: invalid csv value: %r" % (opt, value)) diff --git a/test/unittest_textutils.py b/test/unittest_textutils.py index 708149b..7dcf4e5 100644 --- a/test/unittest_textutils.py +++ b/test/unittest_textutils.py @@ -101,7 +101,7 @@ the tests.""", indent=' ', line_len=70)), class GetCsvTC(TestCase): def test_known(self): - self.assertEquals(tu.get_csv('a, b,c '), ['a', 'b', 'c']) + self.assertEquals(tu.splitstrip('a, b,c '), ['a', 'b', 'c']) class UnitsTC(TestCase): diff --git a/textutils.py b/textutils.py index 8aabea2..c25d8c8 100644 --- a/textutils.py +++ b/textutils.py @@ -7,7 +7,7 @@ :group text formatting: normalize_text, normalize_paragraph, pretty_match,\ unquote, colorize_ansi -:group text manipulation: searchall, get_csv +:group text manipulation: searchall, splitstrip :sort: text formatting, text manipulation :type ANSI_STYLES: dict(str) @@ -37,6 +37,7 @@ try: except ImportError: linesep = '\n' # gae +from logilab.common.deprecation import deprecated MANUAL_UNICODE_MAP = { u'\xa1': u'!', # INVERTED EXCLAMATION MARK @@ -211,12 +212,13 @@ def splittext(text, line_len): return text[:pos], text[pos+1:].strip() -def get_csv(string, sep=','): - """return a list of string in from a csv formatted line +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. - >>> get_csv('a, b, c , 4') + >>> splitstrip('a, b, c , 4,,') ['a', 'b', 'c', '4'] - >>> get_csv('a') + >>> splitstrip('a') ['a'] >>> @@ -231,6 +233,8 @@ def get_csv(string, sep=','): """ return [word.strip() for word in string.split(sep) if word.strip()] +get_csv = deprecated()(splitstrip) + _BLANK_URE = r'(\s|,)+' _BLANK_RE = re.compile(_BLANK_URE) __VALUE_URE = r'-?(([0-9]+\.[0-9]*)|((0x?)?[0-9]+))' @@ -392,7 +396,7 @@ def _get_ansi_code(color=None, style=None): """ ansi_code = [] if style: - style_attrs = get_csv(style) + style_attrs = splitstrip(style) for effect in style_attrs: ansi_code.append(ANSI_STYLES[effect]) if color: |