Use xml.etree.cElementTree whenever possible to avoid memory leaks
This commit is contained in:
parent
b7a9a1eca9
commit
c5741c7225
7 changed files with 14 additions and 11 deletions
|
@ -2,7 +2,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
import defusedxml.ElementTree as etree # etree parse unsafe
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
@ -276,7 +275,7 @@ class DownloadUtils():
|
||||||
return r
|
return r
|
||||||
try:
|
try:
|
||||||
# xml response
|
# xml response
|
||||||
r = etree.fromstring(r.content)
|
r = utils.defused_etree.fromstring(r.content)
|
||||||
return r
|
return r
|
||||||
except:
|
except:
|
||||||
r.encoding = 'utf-8'
|
r.encoding = 'utf-8'
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
import xml.etree.ElementTree as etree
|
|
||||||
|
|
||||||
from xbmc import executebuiltin, translatePath
|
from xbmc import executebuiltin, translatePath
|
||||||
|
|
||||||
|
@ -494,7 +493,7 @@ class InitialSetup(object):
|
||||||
xml.set_setting(['video', 'ignoresecondsatstart'],
|
xml.set_setting(['video', 'ignoresecondsatstart'],
|
||||||
value='60')
|
value='60')
|
||||||
reboot = xml.write_xml
|
reboot = xml.write_xml
|
||||||
except etree.ParseError:
|
except utils.etree.ParseError:
|
||||||
cache = None
|
cache = None
|
||||||
reboot = False
|
reboot = False
|
||||||
# Kodi default cache if no setting is set
|
# Kodi default cache if no setting is set
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from xml.etree.ElementTree import ParseError
|
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
from .plex_api import API
|
from .plex_api import API
|
||||||
|
@ -66,7 +65,7 @@ def excludefromscan_music_folders(xml):
|
||||||
element.text)
|
element.text)
|
||||||
parent.remove(element)
|
parent.remove(element)
|
||||||
xml_file.write_xml = True
|
xml_file.write_xml = True
|
||||||
except (ParseError, IOError):
|
except (utils.etree.ParseError, IOError):
|
||||||
LOG.error('Could not adjust advancedsettings.xml')
|
LOG.error('Could not adjust advancedsettings.xml')
|
||||||
if reboot is True:
|
if reboot is True:
|
||||||
# 'New Plex music library detected. Sorry, but we need to
|
# 'New Plex music library detected. Sorry, but we need to
|
||||||
|
|
|
@ -67,6 +67,7 @@ class Service():
|
||||||
utils.settings('syncSpecificPlexPlaylistsPrefix') == 'true')
|
utils.settings('syncSpecificPlexPlaylistsPrefix') == 'true')
|
||||||
LOG.info('Play playlist prefix: %s',
|
LOG.info('Play playlist prefix: %s',
|
||||||
utils.settings('syncSpecificPlexPlaylistsPrefix'))
|
utils.settings('syncSpecificPlexPlaylistsPrefix'))
|
||||||
|
LOG.info('XML decoding being used: %s', utils.ETREE)
|
||||||
self.monitor = xbmc.Monitor()
|
self.monitor = xbmc.Monitor()
|
||||||
# Load/Reset PKC entirely - important for user/Kodi profile switch
|
# Load/Reset PKC entirely - important for user/Kodi profile switch
|
||||||
initialsetup.reload_pkc()
|
initialsetup.reload_pkc()
|
||||||
|
|
|
@ -9,8 +9,14 @@ from sqlite3 import connect, OperationalError
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from time import localtime, strftime
|
from time import localtime, strftime
|
||||||
from unicodedata import normalize
|
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 xml.etree.ElementTree as etree
|
||||||
import defusedxml.ElementTree as defused_etree # etree parse unsafe
|
import defusedxml.ElementTree as defused_etree # etree parse unsafe
|
||||||
|
ETREE = 'ElementTree'
|
||||||
from functools import wraps, partial
|
from functools import wraps, partial
|
||||||
from urllib import quote_plus
|
from urllib import quote_plus
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
import xml.etree.ElementTree as etree
|
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
from .utils import etree
|
||||||
from . import path_ops
|
from . import path_ops
|
||||||
from . import variables as v
|
from . import variables as v
|
||||||
from . import state
|
from . import state
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from json import loads
|
from json import loads
|
||||||
import defusedxml.ElementTree as etree # etree parse unsafe
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from ssl import CERT_NONE
|
from ssl import CERT_NONE
|
||||||
from xbmc import sleep
|
from xbmc import sleep
|
||||||
|
@ -222,7 +221,7 @@ class Alexa_Websocket(WebSocket):
|
||||||
self.__class__.__name__)
|
self.__class__.__name__)
|
||||||
LOG.debug('%s: %s', self.__class__.__name__, message)
|
LOG.debug('%s: %s', self.__class__.__name__, message)
|
||||||
try:
|
try:
|
||||||
message = etree.fromstring(message)
|
message = utils.defused_etree.fromstring(message)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error('%s: Error decoding message from Alexa: %s',
|
LOG.error('%s: Error decoding message from Alexa: %s',
|
||||||
self.__class__.__name__, ex)
|
self.__class__.__name__, ex)
|
||||||
|
|
Loading…
Reference in a new issue