diff --git a/CHANGELOG.md b/CHANGELOG.md index 9019a2c..b113dd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ History ------- +0.5.3 - 30.10.2015 +---------------- + +* Disable stripping in XMLObjectifyParser on PyPy (#30). + 0.5.2 - 20.10.2015 ---------------- diff --git a/pyanyapi/interfaces.py b/pyanyapi/interfaces.py index 67b12e7..121f684 100644 --- a/pyanyapi/interfaces.py +++ b/pyanyapi/interfaces.py @@ -4,6 +4,7 @@ """ import csv import re +import sys import yaml @@ -169,6 +170,11 @@ class XMLObjectifyInterface(BaseInterface): """ _error_message = 'XML data can not be parsed.' + def __init__(self, content, strip=False): + assert not (strip and hasattr(sys, 'pypy_translation_info') and sys.version_info[0] == 2), \ + 'Stripping is not supported on PyPy' + super(XMLObjectifyInterface, self).__init__(content, strip) + def perform_parsing(self): try: return objectify.fromstring(self.content) @@ -186,19 +192,13 @@ def __getattribute__(self, item): except AttributeError: return None - def _strip_object(self, obj): - for key, value in obj.__dict__.items(): - if isinstance(value, objectify.StringElement): - if value.text is not None: - setattr(obj, key, value.text.strip()) - elif isinstance(value, objectify.ObjectifiedElement): - self._strip_object(value) - def maybe_strip(self, value): if self.strip and isinstance(value, objectify.ObjectifiedElement): - self._strip_object(value) - if self.strip and isinstance(value, objectify.StringElement) and value.text is not None: - return value.text.strip() + if isinstance(value, objectify.StringElement) and value.text is not None: + value = value.text.strip() + else: + for key, inner_value in value.__dict__.items(): + value[key] = self.maybe_strip(inner_value) return value diff --git a/setup.py b/setup.py index 7f4d773..e0724e4 100644 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ def run_tests(self): setup( name='pyanyapi', url='https://github.com/Stranger6667/pyanyapi', - version='0.5.2', + version='0.5.3', packages=['pyanyapi'], license='MIT', author='Dmitry Dygalo', diff --git a/tests/conftest.py b/tests/conftest.py index 2d16d0d..06f9542 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -90,8 +90,10 @@ def test_5(self, value): return 'Will not be included' +PYPY = hasattr(sys, 'pypy_translation_info') and sys.version_info[0] == 2 PYPY3 = hasattr(sys, 'pypy_translation_info') and sys.version_info[0] == 3 JYTHON = platform.system() == 'Java' lxml_is_supported = pytest.mark.skipif(PYPY3 or JYTHON, reason='lxml is not supported') lxml_is_not_supported = pytest.mark.skipif(not (PYPY3 or JYTHON), reason='Only on if lxml is supported') +not_pypy = pytest.mark.skipif(PYPY, reason='PyPy is not supported') diff --git a/tests/test_strip.py b/tests/test_strip.py index 6344131..9778a57 100644 --- a/tests/test_strip.py +++ b/tests/test_strip.py @@ -1,7 +1,8 @@ # coding: utf-8 -from .conftest import lxml_is_supported +from .conftest import lxml_is_supported, not_pypy from pyanyapi import RegExpParser, JSONParser, AJAXParser, XMLParser, XMLObjectifyParser + JSON_CONTENT = '{"container":" 1 "}' AJAX_CONTENT = '{"content": "

Pcontent

"}' XML_CONTENT = '

Pcontent

' @@ -57,6 +58,7 @@ def test_objectify_strip_default(): @lxml_is_supported +@not_pypy def test_objectify_strip(): with_strip = XMLObjectifyParser(strip=True).parse(OBJECTIFY_CONTENT) assert with_strip.Messages.Message == 'abc'