Univention Bugzilla – Attachment 10540 Details for
Bug 52270
Replace xml.etree.cElementTree with lxml.etree
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
patch from Arvid
lxml.patch (text/plain), 6.87 KB, created by
Florian Best
on 2020-10-28 23:52:22 CET
(
hide
)
Description:
patch from Arvid
Filename:
MIME Type:
Creator:
Florian Best
Created:
2020-10-28 23:52:22 CET
Size:
6.87 KB
patch
obsolete
>diff --git a/management/univention-management-console/src/univention/management/console/category.py b/management/univention-management-console/src/univention/management/console/category.py >index 32bcd10d2d..99ed5de2a4 100644 >--- a/management/univention-management-console/src/univention/management/console/category.py >+++ b/management/univention-management-console/src/univention/management/console/category.py >@@ -67,37 +67,37 @@ must be given in curly braces {VARIABLE}. > > import os > import sys >-import xml.parsers.expat >-import xml.etree.cElementTree as ET >+from lxml import etree > > from .log import RESOURCES > > >-class XML_Definition(ET.ElementTree): >+class XML_Definition(object): > > """Represents a category definition.""" > >- def __init__(self, root=None, filename=None, domain=None): >- ET.ElementTree.__init__(self, element=root, file=filename) >+ def __init__(self, root=None, domain=None): >+ self.tree = etree.ElementTree(root) >+ self.root = root > self.domain = domain > > @property > def name(self): > """Returns the descriptive name of the category""" >- return self.find('name').text >+ return self.tree.find('name').text > > @property > def id(self): > """Returns the unique identifier of the category""" >- return self._root.get('id') >+ return self.root.get('id') > > @property > def icon(self): >- return self._root.get('icon') >+ return self.root.get('icon') > > @property > def color(self): >- return self._root.get('color') >+ return self.root.get('color') > > @property > def priority(self): >@@ -108,9 +108,9 @@ class XML_Definition(ET.ElementTree): > :rtype: float or None > """ > try: >- return float(self._root.get('priority', -1)) >+ return float(self.root.get('priority', -1)) > except ValueError: >- RESOURCES.warn('No valid number type for property "priority": %s' % self._root.get('priority')) >+ RESOURCES.warn('No valid number type for property "priority": %s' % self.root.get('priority')) > return None > > def json(self): >@@ -148,7 +148,7 @@ class Manager(dict): > RESOURCES.info('Found file %s with wrong suffix' % filename) > continue > try: >- definitions = ET.ElementTree(file=os.path.join(Manager.DIRECTORY, filename)) >+ definitions = etree.parse(os.path.join(Manager.DIRECTORY, filename)) > categories = definitions.find('categories') > if categories is None: > continue >@@ -157,6 +157,6 @@ class Manager(dict): > category = XML_Definition(root=category_elem, domain=i18nDomain) > self[category.id] = category > RESOURCES.info('Loaded categories from %s' % filename) >- except (xml.parsers.expat.ExpatError, ET.ParseError) as exc: >+ except (etree.XMLSyntaxError,) as exc: > RESOURCES.warn('Failed to parse category file %s: %s' % (filename, exc)) > continue >diff --git a/management/univention-management-console/src/univention/management/console/module.py b/management/univention-management-console/src/univention/management/console/module.py >index 34439e778e..75ae9a7a2b 100644 >--- a/management/univention-management-console/src/univention/management/console/module.py >+++ b/management/univention-management-console/src/univention/management/console/module.py >@@ -121,8 +121,7 @@ import copy > import os > import sys > import re >-import xml.parsers.expat >-import xml.etree.cElementTree as ET >+from lxml import etree > > from .tools import JSON_Object, JSON_List > from .log import RESOURCES >@@ -272,17 +271,17 @@ class Link(Module): > pass > > >-class XML_Definition(ET.ElementTree): >+class XML_Definition(object): > > '''container for the interface description of a module''' > >- def __init__(self, root=None, filename=None): >- ET.ElementTree.__init__(self, element=root, file=filename) >- self.root = self.getroot() >+ def __init__(self, root=None): >+ self.tree = etree.ElementTree(root) >+ self.root = root > > @property > def name(self): >- return self.findtext('name') >+ return self.tree.findtext('name') > > @property > def version(self): >@@ -290,15 +289,15 @@ class XML_Definition(ET.ElementTree): > > @property > def url(self): >- return self.findtext('url') >+ return self.tree.findtext('url') > > @property > def description(self): >- return self.findtext('description') >+ return self.tree.findtext('description') > > @property > def keywords(self): >- return KEYWORD_PATTERN.split(self.findtext('keywords', '')) + [self.name] >+ return KEYWORD_PATTERN.split(self.tree.findtext('keywords', '')) + [self.name] > > @property > def id(self): >@@ -338,7 +337,7 @@ class XML_Definition(ET.ElementTree): > @property > def flavors(self): > '''Retrieve list of flavor objects''' >- for elem in self.findall('flavor'): >+ for elem in self.tree.findall('flavor'): > name = elem.findtext('name') > priority = None > try: >@@ -366,11 +365,11 @@ class XML_Definition(ET.ElementTree): > > @property > def categories(self): >- return [elem.get('name') for elem in self.findall('categories/category')] >+ return [elem.get('name') for elem in self.tree.findall('categories/category')] > > def commands(self): > '''Generator to iterate over the commands''' >- for command in self.findall('command'): >+ for command in self.tree.findall('command'): > yield command.get('name') > > def get_module(self): >@@ -383,7 +382,7 @@ class XML_Definition(ET.ElementTree): > priority=self.priority, > keywords=self.keywords, > translationId=self.translationId, >- required_commands=[cat.get('name') for cat in self.findall('requiredCommands/requiredCommand')], >+ required_commands=[cat.get('name') for cat in self.tree.findall('requiredCommands/requiredCommand')], > version=self.version, > ) > >@@ -395,12 +394,12 @@ class XML_Definition(ET.ElementTree): > > def get_command(self, name): > '''Retrieves details of a command''' >- for command in self.findall('command'): >+ for command in self.tree.findall('command'): > if command.get('name') == name: > return Command(name, command.get('function'), command.get('allow_anonymous', '0').lower() in ('yes', 'true', '1')) > > def __bool__(self): >- module = self.find('module') >+ module = self.tree.find('module') > return module is not None and len(module) != 0 > __nonzero__ = __bool__ > >@@ -433,16 +432,16 @@ class Manager(dict): > if not filename.endswith('.xml'): > continue > try: >- parsed_xml = ET.parse(os.path.join(Manager.DIRECTORY, filename)) >+ parsed_xml = etree.parse(os.path.join(Manager.DIRECTORY, filename)) > RESOURCES.info('Loaded module %s' % filename) >- for mod_tree in parsed_xml.getroot(): >- mod = XML_Definition(root=mod_tree) >+ for mod_element in parsed_xml.getroot().iterchildren(tag=etree.Element): >+ mod = XML_Definition(root=mod_element) > if mod.deactivated: > RESOURCES.info('Module is deactivated: %s' % filename) > continue > # save list of definitions in self > self.setdefault(mod.id, []).append(mod) >- except (xml.parsers.expat.ExpatError, ET.ParseError) as exc: >+ except (etree.XMLSyntaxError,) as exc: > RESOURCES.warn('Failed to load module %s: %s' % (filename, exc)) > continue >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 52270
: 10540