From 2c2ba478796d2edea46357c508aafebf9b4c0173 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Sep 2016 11:23:22 -0400 Subject: [PATCH] Add test for xml_bool and correct implementation, simplify by using json. --- wolframalpha/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/wolframalpha/__init__.py b/wolframalpha/__init__.py index 61fa166..62906ea 100644 --- a/wolframalpha/__init__.py +++ b/wolframalpha/__init__.py @@ -1,4 +1,5 @@ import itertools +import json from six.moves import urllib, map @@ -125,11 +126,13 @@ class Subpod(Document): def xml_bool(str_val): - return ( - bool(int(str_val)) - if str_val.isdigit() else - str_val.lower() != 'true' - ) + """ + >>> xml_bool('true') + True + >>> xml_bool('false') + False + """ + return bool(json.loads(str_val)) class Pod(ErrorHandler, Document):