Skip to content

Commit

Permalink
Merge pull request #31 from Stranger6667/release-0.5.3
Browse files Browse the repository at this point in the history
Disable stripping in XMLObjectifyParser on PyPy. Closes #30
  • Loading branch information
Stranger6667 committed Oct 30, 2015
2 parents 3d43e51 + 0084a2a commit b1f0bc4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
5 changes: 5 additions & 0 deletions 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
----------------

Expand Down
22 changes: 11 additions & 11 deletions pyanyapi/interfaces.py
Expand Up @@ -4,6 +4,7 @@
"""
import csv
import re
import sys

import yaml

Expand Down Expand Up @@ -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)
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Expand Up @@ -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')
4 changes: 3 additions & 1 deletion 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": "<p> Pcontent </p>"}'
XML_CONTENT = '<p> Pcontent </p>'
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit b1f0bc4

Please sign in to comment.