Use xml.etree.cElementTree whenever possible to avoid memory leaks

This commit is contained in:
croneter 2018-10-13 20:17:16 +02:00
parent b7a9a1eca9
commit c5741c7225
7 changed files with 14 additions and 11 deletions

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, unicode_literals
from logging import getLogger
import defusedxml.ElementTree as etree # etree parse unsafe
import requests
from . import utils
@ -276,7 +275,7 @@ class DownloadUtils():
return r
try:
# xml response
r = etree.fromstring(r.content)
r = utils.defused_etree.fromstring(r.content)
return r
except:
r.encoding = 'utf-8'

View file

@ -3,7 +3,6 @@
from __future__ import absolute_import, division, unicode_literals
from logging import getLogger
from Queue import Queue
import xml.etree.ElementTree as etree
from xbmc import executebuiltin, translatePath
@ -494,7 +493,7 @@ class InitialSetup(object):
xml.set_setting(['video', 'ignoresecondsatstart'],
value='60')
reboot = xml.write_xml
except etree.ParseError:
except utils.etree.ParseError:
cache = None
reboot = False
# Kodi default cache if no setting is set

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, unicode_literals
from logging import getLogger
from xml.etree.ElementTree import ParseError
from . import utils
from .plex_api import API
@ -66,7 +65,7 @@ def excludefromscan_music_folders(xml):
element.text)
parent.remove(element)
xml_file.write_xml = True
except (ParseError, IOError):
except (utils.etree.ParseError, IOError):
LOG.error('Could not adjust advancedsettings.xml')
if reboot is True:
# 'New Plex music library detected. Sorry, but we need to

View file

@ -67,6 +67,7 @@ class Service():
utils.settings('syncSpecificPlexPlaylistsPrefix') == 'true')
LOG.info('Play playlist prefix: %s',
utils.settings('syncSpecificPlexPlaylistsPrefix'))
LOG.info('XML decoding being used: %s', utils.ETREE)
self.monitor = xbmc.Monitor()
# Load/Reset PKC entirely - important for user/Kodi profile switch
initialsetup.reload_pkc()

View file

@ -9,8 +9,14 @@ from sqlite3 import connect, OperationalError
from datetime import datetime, timedelta
from time import localtime, strftime
from unicodedata import normalize
try:
import xml.etree.cElementTree as etree
import defusedxml.cElementTree as defused_etree # etree parse unsafe
ETREE = 'cElementTree'
except ImportError:
import xml.etree.ElementTree as etree
import defusedxml.ElementTree as defused_etree # etree parse unsafe
ETREE = 'ElementTree'
from functools import wraps, partial
from urllib import quote_plus
import hashlib

View file

@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, unicode_literals
from logging import getLogger
import xml.etree.ElementTree as etree
from . import utils
from .utils import etree
from . import path_ops
from . import variables as v
from . import state

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
from logging import getLogger
from json import loads
import defusedxml.ElementTree as etree # etree parse unsafe
from threading import Thread
from ssl import CERT_NONE
from xbmc import sleep
@ -222,7 +221,7 @@ class Alexa_Websocket(WebSocket):
self.__class__.__name__)
LOG.debug('%s: %s', self.__class__.__name__, message)
try:
message = etree.fromstring(message)
message = utils.defused_etree.fromstring(message)
except Exception as ex:
LOG.error('%s: Error decoding message from Alexa: %s',
self.__class__.__name__, ex)