Commit e15bb26d authored by Pavel Vainerman's avatar Pavel Vainerman

(python): подправил коментарии к некоторым функциям и изменил название на более…

(python): подправил коментарии к некоторым функциям и изменил название на более "удачное". Добавил в UniXML параметр позволяющий загружать xml не только из файла, но и из "памяти"(строки).
parent 446ee2f2
...@@ -94,7 +94,7 @@ def to_sid(str_id, ui): ...@@ -94,7 +94,7 @@ def to_sid(str_id, ui):
# Получение списка пар [id@node,int(val)] из строки "id1@node1=val1,id2=val2,.." # Получение списка пар [id@node,int(val)] из строки "id1@node1=val1,id2=val2,.."
def get_int_list(raw_str,sep='='): def get_int_list(raw_str,sep='='):
if raw_str == None or raw_str == "": if raw_str == None or raw_str == "":
return [] return []
......
...@@ -33,12 +33,16 @@ class UniXMLException(Exception): ...@@ -33,12 +33,16 @@ class UniXMLException(Exception):
return self.err return self.err
# ----------------------------- # -----------------------------
class UniXML(): class UniXML():
def __init__(self, xfile): def __init__(self, xfile, isDoc=False):
try: try:
self.doc = None self.doc = None
self.fname = xfile if isDoc:
self.doc = libxml2.parseFile(xfile) self.fname = ''
self.doc = libxml2.parseDoc(xfile)
else:
self.fname = xfile
self.doc = libxml2.parseFile(xfile)
except libxml2.parserError: except libxml2.parserError:
raise UniXMLException("(UniXML): Can`t open file " + xfile) raise UniXMLException("(UniXML): Can`t open file " + xfile)
...@@ -147,11 +151,15 @@ class UniXML(): ...@@ -147,11 +151,15 @@ class UniXML():
return self.doc.saveFile(filename) return self.doc.saveFile(filename)
def reopen(self, filename): def reopen(self, filename, isDoc=False):
try: try:
self.doc.freeDoc() self.doc.freeDoc()
self.fname = filename if isDoc:
self.doc = libxml2.parseFile(filename) self.fname = ''
self.doc = libxml2.parseDoc(filename)
else:
self.fname = filename
self.doc = libxml2.parseFile(filename)
except libxml2.parserError: except libxml2.parserError:
sys.exit(-1) sys.exit(-1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment