From 5944ad64d939af372ae7a4733aa03a2082585ade Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 11 Jul 2015 22:23:14 +0100 Subject: [PATCH] Improved bool parsing --- sgprops.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/sgprops.py b/sgprops.py index bcab4e9..43c24aa 100644 --- a/sgprops.py +++ b/sgprops.py @@ -106,11 +106,7 @@ class Node(object): def write(self, path): root = self._createXMLElement('PropertyList') - t = ET.ElementTree(root) - - ET.dump(root) - t.write(path, 'utf-8', xml_declaration = True) def _createXMLElement(self, nm = None): @@ -205,9 +201,9 @@ class PropsHandler(handler.ContentHandler): self._current.value = self._content if self._currentTy == "int": self._current.value = int(self._content) - if self._currentTy is "bool": - self._current.value = bool(self._content) - if self._currentTy is "double": + if self._currentTy == "bool": + self._current.value = self.parsePropsBool(self._content) + if self._currentTy == "double": self._current.value = float(self._content) except: print "Parse error for value:", self._content, "at line:", self._locator.getLineNumber(), "of:", self._path @@ -215,6 +211,23 @@ class PropsHandler(handler.ContentHandler): self._current = self._current.parent self._content = None + def parsePropsBool(self, content): + if content == "True" or content == "true": + return True + + if content == "False" or content == "false": + return False + + try: + icontent = int(content) + if icontent is not None: + if icontent == 0: + return False + else: + return True; + except: + return False + def characters(self, content): if self._content is None: self._content = ''