Improved bool parsing
This commit is contained in:
parent
cf1afee705
commit
5944ad64d9
1 changed files with 20 additions and 7 deletions
27
sgprops.py
27
sgprops.py
|
@ -106,11 +106,7 @@ class Node(object):
|
||||||
|
|
||||||
def write(self, path):
|
def write(self, path):
|
||||||
root = self._createXMLElement('PropertyList')
|
root = self._createXMLElement('PropertyList')
|
||||||
|
|
||||||
t = ET.ElementTree(root)
|
t = ET.ElementTree(root)
|
||||||
|
|
||||||
ET.dump(root)
|
|
||||||
|
|
||||||
t.write(path, 'utf-8', xml_declaration = True)
|
t.write(path, 'utf-8', xml_declaration = True)
|
||||||
|
|
||||||
def _createXMLElement(self, nm = None):
|
def _createXMLElement(self, nm = None):
|
||||||
|
@ -205,9 +201,9 @@ class PropsHandler(handler.ContentHandler):
|
||||||
self._current.value = self._content
|
self._current.value = self._content
|
||||||
if self._currentTy == "int":
|
if self._currentTy == "int":
|
||||||
self._current.value = int(self._content)
|
self._current.value = int(self._content)
|
||||||
if self._currentTy is "bool":
|
if self._currentTy == "bool":
|
||||||
self._current.value = bool(self._content)
|
self._current.value = self.parsePropsBool(self._content)
|
||||||
if self._currentTy is "double":
|
if self._currentTy == "double":
|
||||||
self._current.value = float(self._content)
|
self._current.value = float(self._content)
|
||||||
except:
|
except:
|
||||||
print "Parse error for value:", self._content, "at line:", self._locator.getLineNumber(), "of:", self._path
|
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._current = self._current.parent
|
||||||
self._content = None
|
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):
|
def characters(self, content):
|
||||||
if self._content is None:
|
if self._content is None:
|
||||||
self._content = ''
|
self._content = ''
|
||||||
|
|
Loading…
Reference in a new issue