xmlparser: don't manage errors at this level
This commit is contained in:
parent
0b06261d18
commit
a7b166498c
@ -191,8 +191,12 @@ class ModuleLoader(SourceLoader):
|
||||
module.del_event = del_event
|
||||
|
||||
if not hasattr(module, "NODATA"):
|
||||
module.DATAS = parse_file(os.path.join(self.context.data_path,
|
||||
module.__name__ + ".xml"))
|
||||
data_file = os.path.join(self.context.data_path,
|
||||
module.__name__ + ".xml")
|
||||
if os.path.isfile(data_file):
|
||||
module.DATAS = parse_file(data_file)
|
||||
else:
|
||||
module.DATAS = module_state.ModuleState("nemubotstate")
|
||||
module.save = mod_save
|
||||
else:
|
||||
module.DATAS = None
|
||||
|
@ -54,28 +54,11 @@ def parse_file(filename):
|
||||
parser = xml.sax.make_parser()
|
||||
mod = ModuleStatesFile()
|
||||
parser.setContentHandler(mod)
|
||||
try:
|
||||
parser.parse(open(filename, "r"))
|
||||
return mod.root
|
||||
except IOError:
|
||||
logger.exception("error occurs during XML parsing of %s", filename)
|
||||
return module_state.ModuleState("nemubotstate")
|
||||
except:
|
||||
logger.exception("error occurs during XML parsing of %s", filename)
|
||||
if mod.root is None:
|
||||
return module_state.ModuleState("nemubotstate")
|
||||
else:
|
||||
return mod.root
|
||||
parser.parse(open(filename, "r"))
|
||||
return mod.root
|
||||
|
||||
|
||||
def parse_string(string):
|
||||
mod = ModuleStatesFile()
|
||||
try:
|
||||
xml.sax.parseString(string, mod)
|
||||
return mod.root
|
||||
except:
|
||||
logger.exception("error occurs during XML parsing")
|
||||
if mod.root is None:
|
||||
return module_state.ModuleState("nemubotstate")
|
||||
else:
|
||||
return mod.root
|
||||
xml.sax.parseString(string, mod)
|
||||
return mod.root
|
||||
|
Loading…
Reference in New Issue
Block a user