~corey.bryant/charms/trusty/neutron-openvswitch/git

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/core/strutils.py

  • Committer: Liam Young
  • Date: 2015-02-16 12:04:50 UTC
  • Revision ID: liam.young@canonical.com-20150216120450-xl1csh09unb5ta0t
[gnuoy,trivial] charmhelpers sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# You should have received a copy of the GNU Lesser General Public License
18
18
# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
19
19
 
 
20
import six
 
21
 
20
22
 
21
23
def bool_from_string(value):
22
24
    """Interpret string value as boolean.
23
25
 
24
26
    Returns True if value translates to True otherwise False.
25
27
    """
26
 
    if isinstance(value, str):
27
 
        value = value.lower()
 
28
    if isinstance(value, six.string_types):
 
29
        value = six.text_type(value)
28
30
    else:
29
31
        msg = "Unable to interpret non-string value '%s' as boolean" % (value)
30
32
        raise ValueError(msg)
31
33
 
 
34
    value = value.strip().lower()
 
35
 
32
36
    if value in ['y', 'yes', 'true', 't']:
33
37
        return True
34
38
    elif value in ['n', 'no', 'false', 'f']: