-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
11 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,4 @@ | ||
from collections import defaultdict | ||
from xml.etree import cElementTree as ET | ||
import xmltodict | ||
|
||
# XML to Dict parser, from: | ||
# https://stackoverflow.com/questions/2148119/how-to-convert-an-xml-string-to-a-dictionary-in-python/10077069 | ||
# Used in SiEPIC-Tools (https://github.com/lukasc-ubc/SiEPIC-Tools) | ||
def etree_to_dict(t): | ||
d = {t.tag: {} if t.attrib else None} | ||
children = list(t) | ||
if children: | ||
dd = defaultdict(list) | ||
for dc in map(etree_to_dict, children): | ||
for k, v in dc.items(): | ||
dd[k].append(v) | ||
d = {t.tag: {k: v[0] if len(v) == 1 else v for k, v in dd.items()}} | ||
if t.attrib: | ||
d[t.tag].update(('@' + k, v) for k, v in t.attrib.items()) | ||
if t.text: | ||
text = t.text.strip() | ||
if children or t.attrib: | ||
if text: | ||
d[t.tag]['#text'] = text | ||
else: | ||
d[t.tag] = text | ||
return d | ||
|
||
|
||
def xml_to_dict(t): | ||
try: | ||
e = ET.XML(t) | ||
except: | ||
raise UserWarning("Error in the XML file.") | ||
return etree_to_dict(e) | ||
def xml_to_dict(xml_content): | ||
return xmltodict.parse(xml_content, process_namespaces=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ def readme(): | |
author_email='[email protected]', | ||
license='MIT', | ||
packages=['lygadgets'], | ||
install_requires=[], | ||
install_requires=['xmltodict'], | ||
package_data={'': ['*.lym']}, | ||
include_package_data=True, | ||
entry_points={'console_scripts': ['lygadgets_link=lygadgets.command_line:cm_link_any']}, | ||
|