In XMLparser, getBool, getInt and getDate use the content if no name is given
This commit is contained in:
parent
a7fd178a41
commit
d4def8c026
@ -49,37 +49,50 @@ class ModuleState:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def getDate(self, name):
|
def getDate(self, name=None):
|
||||||
"""Get the asked argument and return it as a date"""
|
"""Get the asked argument and return it as a date"""
|
||||||
if name in self.attributes.keys():
|
if name is None:
|
||||||
if isinstance(self.attributes[name], datetime):
|
source = self.content
|
||||||
return self.attributes[name]
|
elif name in self.attributes.keys():
|
||||||
else:
|
source = self.attributes[name]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if isinstance(source, datetime):
|
||||||
|
return source
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
return datetime.fromtimestamp(float(self.attributes[name]))
|
return datetime.fromtimestamp(float(source))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return datetime.fromtimestamp(time.mktime(time.strptime(self.attributes[name][:19], "%Y-%m-%d %H:%M:%S")))
|
return datetime.fromtimestamp(time.mktime(
|
||||||
except ImportError:
|
time.strptime(source[:19], "%Y-%m-%d %H:%M:%S")))
|
||||||
pass
|
except ImportError:
|
||||||
else:
|
pass
|
||||||
return None
|
|
||||||
|
|
||||||
def getInt(self, name):
|
def getInt(self, name=None):
|
||||||
"""Get the asked argument and return it as an integer"""
|
"""Get the asked argument and return it as an integer"""
|
||||||
if name in self.attributes.keys():
|
if name is None:
|
||||||
return int(float(self.attributes[name]))
|
source = self.content
|
||||||
|
elif name in self.attributes.keys():
|
||||||
|
source = self.attributes[name]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def getBool(self, name):
|
return int(float(source))
|
||||||
|
|
||||||
|
def getBool(self, name=None):
|
||||||
"""Get the asked argument and return it as an integer"""
|
"""Get the asked argument and return it as an integer"""
|
||||||
if name in self.attributes.keys():
|
if name is None:
|
||||||
return (isinstance(self.attributes[name], bool) and self.attributes[name]) or self.attributes[name] == "True"
|
source = self.content
|
||||||
|
elif name in self.attributes.keys():
|
||||||
|
source = self.attributes[name]
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
return (isinstance(source, bool) and source) or source == "True"
|
||||||
|
|
||||||
def setIndex(self, fieldname = "name", tagname = None):
|
def setIndex(self, fieldname = "name", tagname = None):
|
||||||
"""Defines an hash table to accelerate childs search. You have just to define a common attribute"""
|
"""Defines an hash table to accelerate childs search. You have just to define a common attribute"""
|
||||||
self.index = dict()
|
self.index = dict()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user