source: dynamicfieldsplugin/trunk/dynfields/compat.py

Last change on this file was 16952, checked in by Ryan J Ollos, 6 years ago

TracDynamicFields 2.3.0dev: Add compat.py, missing in r16949

Refs #13323.

File size: 675 bytes
Line 
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2010-2014 Rob Guttman <guttman@alum.mit.edu>
4#
5# This software is licensed as described in the file COPYING, which
6# you should have received as part of this distribution.
7#
8
9
10def to_list(splittable, sep=','):
11    """Split a string at `sep` and return a list without any empty items.
12
13    >>> to_list('1,2, 3,4 ')
14    ['1', '2', '3', '4']
15    >>> to_list('1;2; 3;4 ', sep=';')
16    ['1', '2', '3', '4']
17    >>> to_list('')
18    []
19    >>> to_list(None)
20    []
21    >>> to_list([])
22    []
23    """
24    if not splittable:
25        return []
26    split = [x.strip() for x in splittable.split(sep)]
27    return [item for item in split if item]
Note: See TracBrowser for help on using the repository browser.