Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions pydecoder/xmldecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
from collections import Iterator

from six import wraps, u, string_types, text_type
from six.moves import map
from six.moves import map, reduce

from toolz import curry, first

from pyresult.result import ok, error, rmapn, rmap, and_then as andthen # pylint: disable=import-error
from pyresult import (
ok,
error,
rmap,
fold,
and_then as andthen # pylint: disable=import-error
)


def to_val(func):
Expand Down Expand Up @@ -39,7 +45,7 @@ def xml(creator, decoders, tree):
'''
values = [decoder(getter(tree)) for decoder in decoders] # pylint: disable=no-value-for-parameter

return rmapn(creator, values)
return rmap(creator, fold(values))


@curry
Expand Down Expand Up @@ -81,7 +87,7 @@ def to_int(val):
try:
return ok(int(val))
except (TypeError, ValueError) as err:
return error(unicode(err))
return error(text_type(err))


@to_val
Expand All @@ -90,7 +96,7 @@ def to_float(val):
try:
return ok(float(val))
except (TypeError, ValueError) as err:
return error(unicode(err))
return error(text_type(err))


@to_val
Expand All @@ -99,7 +105,7 @@ def to_string(val):
if val is None:
return error(u'Can\'t be null')

return ok(val) if isinstance(val, text_type) else ok(unicode(val, 'utf-8'))
return ok(val) if isinstance(val, text_type) else ok(text_type(val, 'utf-8'))


@to_val
Expand Down
2 changes: 1 addition & 1 deletion requirements/production.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
six>=1.7.3
toolz>=0.8.2
pyresult>=0.2.0
pyresult>=0.3.0
2 changes: 1 addition & 1 deletion tests/test_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def ftest(val):
rv = ftest(i)

assert is_error(rv)
assert rv.message == 'Value is empty.'
assert rv.value == 'Value is empty.'


def test_to_string_return_decoded_result():
Expand Down
9 changes: 4 additions & 5 deletions tests/test_xml_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from pyresult import is_ok, is_error, value


def creator(*args):
return args
def creator(values):
return values


@pytest.fixture
Expand Down Expand Up @@ -42,7 +42,7 @@ def test_xml_return_ok_result(tree):
)

assert is_ok(rv)
assert value(rv) == ('foo', )
assert value(rv) == ['foo', ]


def test_xml_return_error_result(tree):
Expand All @@ -68,6 +68,5 @@ def test_xml_return_error_result_with_aggregate_messages(tree):
)

assert is_error(rv)
messages = rv.message.split('\n')
for msg in messages:
for msg in rv.value:
assert msg.find(u'Value is empty.') > -1