summaryrefslogtreecommitdiffstats
path: root/contrib/python
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2024-10-30 14:43:19 +0300
committerrobot-piglet <[email protected]>2024-10-30 15:24:20 +0300
commite589edb669af5acb0efabcfa77cebb60a9b97407 (patch)
tree7d829c61c48fdf7e3a50cc469c60eea589a03816 /contrib/python
parent978be2360a794c68ff6177e6c7fd7649b4e8354f (diff)
Intermediate changes
commit_hash:8728d5088f12247cf38892337baf887b6df09d87
Diffstat (limited to 'contrib/python')
-rw-r--r--contrib/python/xmltodict/py3/.dist-info/METADATA20
-rw-r--r--contrib/python/xmltodict/py3/README.md13
-rw-r--r--contrib/python/xmltodict/py3/tests/__init__.py0
-rw-r--r--contrib/python/xmltodict/py3/tests/test_dicttoxml.py22
-rw-r--r--contrib/python/xmltodict/py3/tests/test_xmltodict.py26
-rw-r--r--contrib/python/xmltodict/py3/xmltodict.py68
-rw-r--r--contrib/python/xmltodict/py3/ya.make2
7 files changed, 94 insertions, 57 deletions
diff --git a/contrib/python/xmltodict/py3/.dist-info/METADATA b/contrib/python/xmltodict/py3/.dist-info/METADATA
index e2aaa3e797d..da6664f77f8 100644
--- a/contrib/python/xmltodict/py3/.dist-info/METADATA
+++ b/contrib/python/xmltodict/py3/.dist-info/METADATA
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: xmltodict
-Version: 0.13.0
+Version: 0.14.0
Summary: Makes working with XML feel like you are working with JSON
Home-page: https://github.com/martinblech/xmltodict
Author: Martin Blech
@@ -19,6 +19,9 @@ Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
+Classifier: Programming Language :: Python :: 3.11
+Classifier: Programming Language :: Python :: 3.12
+Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Text Processing :: Markup :: XML
Requires-Python: >=3.4
@@ -29,7 +32,7 @@ License-File: LICENSE
`xmltodict` is a Python module that makes working with XML feel like you are working with [JSON](http://docs.python.org/library/json.html), as in this ["spec"](http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html):
-[![Build Status](https://travis-ci.com/martinblech/xmltodict.svg?branch=master)](https://travis-ci.com/martinblech/xmltodict)
+[![Build Status](https://app.travis-ci.com/martinblech/xmltodict.svg?branch=master)](https://app.travis-ci.com/martinblech/xmltodict)
```python
>>> print(json.dumps(xmltodict.parse("""
@@ -231,6 +234,17 @@ You just need to
$ pip install xmltodict
```
+### Using conda
+
+For installing `xmltodict` using Anaconda/Miniconda (*conda*) from the
+[conda-forge channel][#xmltodict-conda] all you need to do is:
+
+[#xmltodict-conda]: https://anaconda.org/conda-forge/xmltodict
+
+```sh
+$ conda install -c conda-forge xmltodict
+```
+
### RPM-based distro (Fedora, RHEL, …)
There is an [official Fedora package for xmltodict](https://apps.fedoraproject.org/packages/python-xmltodict).
@@ -274,5 +288,3 @@ $ zypper in python2-xmltodict
# Python3
$ zypper in python3-xmltodict
```
-
-
diff --git a/contrib/python/xmltodict/py3/README.md b/contrib/python/xmltodict/py3/README.md
index ab63401a80a..6f776a8b4d8 100644
--- a/contrib/python/xmltodict/py3/README.md
+++ b/contrib/python/xmltodict/py3/README.md
@@ -2,7 +2,7 @@
`xmltodict` is a Python module that makes working with XML feel like you are working with [JSON](http://docs.python.org/library/json.html), as in this ["spec"](http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html):
-[![Build Status](https://travis-ci.com/martinblech/xmltodict.svg?branch=master)](https://travis-ci.com/martinblech/xmltodict)
+[![Build Status](https://app.travis-ci.com/martinblech/xmltodict.svg?branch=master)](https://app.travis-ci.com/martinblech/xmltodict)
```python
>>> print(json.dumps(xmltodict.parse("""
@@ -204,6 +204,17 @@ You just need to
$ pip install xmltodict
```
+### Using conda
+
+For installing `xmltodict` using Anaconda/Miniconda (*conda*) from the
+[conda-forge channel][#xmltodict-conda] all you need to do is:
+
+[#xmltodict-conda]: https://anaconda.org/conda-forge/xmltodict
+
+```sh
+$ conda install -c conda-forge xmltodict
+```
+
### RPM-based distro (Fedora, RHEL, …)
There is an [official Fedora package for xmltodict](https://apps.fedoraproject.org/packages/python-xmltodict).
diff --git a/contrib/python/xmltodict/py3/tests/__init__.py b/contrib/python/xmltodict/py3/tests/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/contrib/python/xmltodict/py3/tests/__init__.py
diff --git a/contrib/python/xmltodict/py3/tests/test_dicttoxml.py b/contrib/python/xmltodict/py3/tests/test_dicttoxml.py
index 7fc21718aee..470aca98a18 100644
--- a/contrib/python/xmltodict/py3/tests/test_dicttoxml.py
+++ b/contrib/python/xmltodict/py3/tests/test_dicttoxml.py
@@ -144,6 +144,26 @@ class DictToXMLTestCase(unittest.TestCase):
self.assertEqual(xml, unparse(obj, pretty=True,
newl=newl, indent=indent))
+ def test_pretty_print_with_int_indent(self):
+ obj = {'a': OrderedDict((
+ ('b', [{'c': [1, 2]}, 3]),
+ ('x', 'y'),
+ ))}
+ newl = '\n'
+ indent = 2
+ xml = dedent('''\
+ <?xml version="1.0" encoding="utf-8"?>
+ <a>
+ <b>
+ <c>1</c>
+ <c>2</c>
+ </b>
+ <b>3</b>
+ <x>y</x>
+ </a>''')
+ self.assertEqual(xml, unparse(obj, pretty=True,
+ newl=newl, indent=indent))
+
def test_encoding(self):
try:
value = unichr(39321)
@@ -171,8 +191,6 @@ class DictToXMLTestCase(unittest.TestCase):
self.assertEqual('<a attr="1"></a>', _strip(unparse(obj)))
def test_short_empty_elements(self):
- if sys.version_info[0] < 3:
- return
obj = {'a': None}
self.assertEqual('<a/>', _strip(unparse(obj, short_empty_elements=True)))
diff --git a/contrib/python/xmltodict/py3/tests/test_xmltodict.py b/contrib/python/xmltodict/py3/tests/test_xmltodict.py
index 04137f9e039..037771eea39 100644
--- a/contrib/python/xmltodict/py3/tests/test_xmltodict.py
+++ b/contrib/python/xmltodict/py3/tests/test_xmltodict.py
@@ -93,13 +93,13 @@ class XMLToDictTestCase(unittest.TestCase):
"""
self.assertEqual(
parse(xml),
- {'root': {'emptya': None,
+ {'root': {'emptya': " ",
'emptyb': {'@attr': 'attrvalue'},
'value': 'hello'}})
def test_keep_whitespace(self):
xml = "<root> </root>"
- self.assertEqual(parse(xml), dict(root=None))
+ self.assertEqual(parse(xml), dict(root=' '))
self.assertEqual(parse(xml, strip_whitespace=False),
dict(root=' '))
@@ -168,14 +168,14 @@ class XMLToDictTestCase(unittest.TestCase):
except NameError:
value = chr(39321)
self.assertEqual({'a': value},
- parse('<a>%s</a>' % value))
+ parse(f'<a>{value}</a>'))
def test_encoded_string(self):
try:
value = unichr(39321)
except NameError:
value = chr(39321)
- xml = '<a>%s</a>' % value
+ xml = f'<a>{value}</a>'
self.assertEqual(parse(xml),
parse(xml.encode('utf-8')))
@@ -457,3 +457,21 @@ class XMLToDictTestCase(unittest.TestCase):
}
}
self.assertEqual(parse(xml, process_comments=True), expectedResult)
+
+ def test_streaming_attrs(self):
+ xml = """
+ <a>
+ <b attr1="value">
+ <c>cdata</c>
+ </b>
+ </a>
+ """
+ def handler(path, item):
+ expected = {
+ '@attr1': 'value',
+ 'c': 'cdata'
+ }
+ self.assertEqual(expected, item)
+ return True
+
+ parse(xml, item_depth=2, item_callback=handler)
diff --git a/contrib/python/xmltodict/py3/xmltodict.py b/contrib/python/xmltodict/py3/xmltodict.py
index ca760aa6379..21242cfc107 100644
--- a/contrib/python/xmltodict/py3/xmltodict.py
+++ b/contrib/python/xmltodict/py3/xmltodict.py
@@ -1,19 +1,10 @@
#!/usr/bin/env python
"Makes working with XML feel like you are working with JSON"
-try:
- from defusedexpat import pyexpat as expat
-except ImportError:
- from xml.parsers import expat
+from xml.parsers import expat
from xml.sax.saxutils import XMLGenerator
from xml.sax.xmlreader import AttributesImpl
-try: # pragma no cover
- from cStringIO import StringIO
-except ImportError: # pragma no cover
- try:
- from StringIO import StringIO
- except ImportError:
- from io import StringIO
+from io import StringIO
_dict = dict
import platform
@@ -22,17 +13,8 @@ if tuple(map(int, platform.python_version_tuple()[:2])) < (3, 7):
from inspect import isgenerator
-try: # pragma no cover
- _basestring = basestring
-except NameError: # pragma no cover
- _basestring = str
-try: # pragma no cover
- _unicode = unicode
-except NameError: # pragma no cover
- _unicode = str
-
__author__ = 'Martin Blech'
-__version__ = '0.13.0'
+__version__ = '0.14.0'
__license__ = 'MIT'
@@ -40,7 +22,7 @@ class ParsingInterrupted(Exception):
pass
-class _DictSAXHandler(object):
+class _DictSAXHandler:
def __init__(self,
item_depth=0,
item_callback=lambda *args: True,
@@ -107,7 +89,7 @@ class _DictSAXHandler(object):
attrs['xmlns'] = self.namespace_declarations
self.namespace_declarations = self.dict_constructor()
self.path.append((name, attrs or None))
- if len(self.path) > self.item_depth:
+ if len(self.path) >= self.item_depth:
self.stack.append((self.item, self.data))
if self.xml_attribs:
attr_entries = []
@@ -135,13 +117,13 @@ class _DictSAXHandler(object):
should_continue = self.item_callback(self.path, item)
if not should_continue:
- raise ParsingInterrupted()
+ raise ParsingInterrupted
if self.stack:
data = (None if not self.data
else self.cdata_separator.join(self.data))
item = self.item
self.item, self.data = self.stack.pop()
- if self.strip_whitespace and data:
+ if self.strip_whitespace and data and item:
data = data.strip() or None
if data and self.force_cdata and item is None:
item = self.dict_constructor()
@@ -335,9 +317,8 @@ def parse(xml_input, encoding=None, expat=expat, process_namespaces=False,
"""
handler = _DictSAXHandler(namespace_separator=namespace_separator,
**kwargs)
- if isinstance(xml_input, _unicode):
- if not encoding:
- encoding = 'utf-8'
+ if isinstance(xml_input, str):
+ encoding = encoding or 'utf-8'
xml_input = xml_input.encode(encoding)
if not process_namespaces:
namespace_separator = None
@@ -372,8 +353,8 @@ def parse(xml_input, encoding=None, expat=expat, process_namespaces=False,
parser.ParseFile(xml_input)
elif isgenerator(xml_input):
for chunk in xml_input:
- parser.Parse(chunk,False)
- parser.Parse(b'',True)
+ parser.Parse(chunk, False)
+ parser.Parse(b'', True)
else:
parser.Parse(xml_input, True)
return handler.item
@@ -412,9 +393,7 @@ def _emit(key, value, content_handler,
if result is None:
return
key, value = result
- if (not hasattr(value, '__iter__')
- or isinstance(value, _basestring)
- or isinstance(value, dict)):
+ if not hasattr(value, '__iter__') or isinstance(value, (str, dict)):
value = [value]
for index, v in enumerate(value):
if full_document and depth == 0 and index > 0:
@@ -422,16 +401,13 @@ def _emit(key, value, content_handler,
if v is None:
v = _dict()
elif isinstance(v, bool):
- if v:
- v = _unicode('true')
- else:
- v = _unicode('false')
- elif not isinstance(v, dict):
- if expand_iter and hasattr(v, '__iter__') and not isinstance(v, _basestring):
+ v = 'true' if v else 'false'
+ elif not isinstance(v, (dict, str)):
+ if expand_iter and hasattr(v, '__iter__'):
v = _dict(((expand_iter, v),))
else:
- v = _unicode(v)
- if isinstance(v, _basestring):
+ v = str(v)
+ if isinstance(v, str):
v = _dict(((cdata_key, v),))
cdata = None
attrs = _dict()
@@ -445,14 +421,16 @@ def _emit(key, value, content_handler,
attr_prefix)
if ik == '@xmlns' and isinstance(iv, dict):
for k, v in iv.items():
- attr = 'xmlns{}'.format(':{}'.format(k) if k else '')
- attrs[attr] = _unicode(v)
+ attr = 'xmlns{}'.format(f':{k}' if k else '')
+ attrs[attr] = str(v)
continue
- if not isinstance(iv, _unicode):
- iv = _unicode(iv)
+ if not isinstance(iv, str):
+ iv = str(iv)
attrs[ik[len(attr_prefix):]] = iv
continue
children.append((ik, iv))
+ if isinstance(indent, int):
+ indent = ' ' * indent
if pretty:
content_handler.ignorableWhitespace(depth * indent)
content_handler.startElement(key, AttributesImpl(attrs))
diff --git a/contrib/python/xmltodict/py3/ya.make b/contrib/python/xmltodict/py3/ya.make
index 6872d9affa2..462ce1b4ebd 100644
--- a/contrib/python/xmltodict/py3/ya.make
+++ b/contrib/python/xmltodict/py3/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(0.13.0)
+VERSION(0.14.0)
LICENSE(MIT)