Cleanup save handling of xml.etree.ElementTree
This commit is contained in:
parent
0dda58ebd3
commit
1f2b19ce42
5 changed files with 10 additions and 9 deletions
|
@ -12,6 +12,9 @@ from xml.etree.ElementTree import parse as _parse
|
|||
from xml.etree.ElementTree import iterparse as _iterparse
|
||||
from xml.etree.ElementTree import tostring
|
||||
|
||||
# Enable creation of new xmls and xml elements
|
||||
from xml.etree.ElementTree import ElementTree, Element, SubElement, ParseError
|
||||
|
||||
|
||||
class UnicodeXMLParser(DefusedXMLParser):
|
||||
"""
|
||||
|
|
|
@ -262,7 +262,7 @@ class DownloadUtils(object):
|
|||
return r
|
||||
try:
|
||||
# xml response
|
||||
r = utils.defused_etree.fromstring(r.content)
|
||||
r = utils.etree.fromstring(r.content)
|
||||
return r
|
||||
except Exception:
|
||||
r.encoding = 'utf-8'
|
||||
|
|
|
@ -10,10 +10,8 @@ from unicodedata import normalize
|
|||
from threading import Lock
|
||||
import urllib
|
||||
# Originally tried faster cElementTree, but does NOT work reliably with Kodi
|
||||
import xml.etree.ElementTree as etree
|
||||
# etree parse unsafe; make sure we're always receiving unicode
|
||||
from . import defused_etree
|
||||
from xml.etree.ElementTree import ParseError
|
||||
from . import defused_etree as etree
|
||||
from functools import wraps
|
||||
import re
|
||||
import gc
|
||||
|
@ -697,7 +695,7 @@ class XmlKodiSetting(object):
|
|||
|
||||
def __enter__(self):
|
||||
try:
|
||||
self.tree = defused_etree.parse(self.path)
|
||||
self.tree = etree.parse(self.path)
|
||||
except IOError:
|
||||
# Document is blank or missing
|
||||
if self.force_create is False:
|
||||
|
@ -707,14 +705,14 @@ class XmlKodiSetting(object):
|
|||
# Create topmost xml entry
|
||||
self.tree = etree.ElementTree(etree.Element(self.top_element))
|
||||
self.write_xml = True
|
||||
except ParseError:
|
||||
except etree.ParseError:
|
||||
LOG.error('Error parsing %s', self.path)
|
||||
# "Kodi cannot parse {0}. PKC will not function correctly. Please
|
||||
# visit {1} and correct your file!"
|
||||
messageDialog(lang(29999), lang(39716).format(
|
||||
self.filename,
|
||||
'http://kodi.wiki'))
|
||||
self.__exit__(ParseError('Error parsing XML'), None, None)
|
||||
self.__exit__(etree.ParseError('Error parsing XML'), None, None)
|
||||
self.root = self.tree.getroot()
|
||||
return self
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ class Alexa_Websocket(WebSocket):
|
|||
self.__class__.__name__)
|
||||
LOG.debug('%s: %s', self.__class__.__name__, message)
|
||||
try:
|
||||
message = utils.defused_etree.fromstring(message)
|
||||
message = utils.etree.fromstring(message)
|
||||
except Exception as ex:
|
||||
LOG.error('%s: Error decoding message from Alexa: %s',
|
||||
self.__class__.__name__, ex)
|
||||
|
|
|
@ -22,7 +22,7 @@ PATH = path_ops.translate_path('special://userdata/')
|
|||
|
||||
def get_etree(topelement):
|
||||
try:
|
||||
xml = utils.defused_etree.parse(
|
||||
xml = utils.etree.parse(
|
||||
path_ops.path.join(PATH, '%s.xml' % topelement))
|
||||
except IOError:
|
||||
# Document is blank or missing
|
||||
|
|
Loading…
Reference in a new issue