From 911f3e33652b9b202bd1a43d10763edf9f346f7e Mon Sep 17 00:00:00 2001 From: Ondrej Tucek Date: Sun, 21 May 2017 17:32:41 +0200 Subject: [PATCH 1/5] Added new version of pyresult --- pydecoder/xmldecode.py | 10 ++++++++-- requirements/production.txt | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pydecoder/xmldecode.py b/pydecoder/xmldecode.py index d71e65eb..a6a0e14d 100644 --- a/pydecoder/xmldecode.py +++ b/pydecoder/xmldecode.py @@ -8,7 +8,13 @@ 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): @@ -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 diff --git a/requirements/production.txt b/requirements/production.txt index 1bd6d89d..3bc43a6b 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -1,3 +1,3 @@ six>=1.7.3 toolz>=0.8.2 -pyresult>=0.2.0 +pyresult>=0.3.0 From f6af8ec585c4eac491e29580cf870a9fcf9ebd8b Mon Sep 17 00:00:00 2001 From: "Jindrich K. Smitka" Date: Mon, 22 May 2017 10:28:30 +0200 Subject: [PATCH 2/5] Fixed errors isn't concatend by default --- tests/test_xml_decoder.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_xml_decoder.py b/tests/test_xml_decoder.py index 7c9db015..1eaec79d 100644 --- a/tests/test_xml_decoder.py +++ b/tests/test_xml_decoder.py @@ -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 From b475043adcb9e8ebccc3a853e65afc59216aeaa2 Mon Sep 17 00:00:00 2001 From: "Jindrich K. Smitka" Date: Mon, 22 May 2017 10:49:52 +0200 Subject: [PATCH 3/5] Fixed error message param --- tests/test_decoders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_decoders.py b/tests/test_decoders.py index ed48cdf4..aba57d79 100644 --- a/tests/test_decoders.py +++ b/tests/test_decoders.py @@ -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(): From 746d3c94e9bcbe34dd005e7c956779271647caf6 Mon Sep 17 00:00:00 2001 From: "Jindrich K. Smitka" Date: Mon, 22 May 2017 11:56:46 +0200 Subject: [PATCH 4/5] Fixed creator test --- tests/test_xml_decoder.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_xml_decoder.py b/tests/test_xml_decoder.py index 1eaec79d..ecc565d4 100644 --- a/tests/test_xml_decoder.py +++ b/tests/test_xml_decoder.py @@ -10,8 +10,8 @@ from pyresult import is_ok, is_error, value -def creator(*args): - return args +def creator(values): + return values @pytest.fixture @@ -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): From 612af93762d96052fba2f5b25238eccbc6ed209a Mon Sep 17 00:00:00 2001 From: "Jindrich K. Smitka" Date: Mon, 22 May 2017 11:58:00 +0200 Subject: [PATCH 5/5] Fixed unicode handling and reduce import --- pydecoder/xmldecode.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pydecoder/xmldecode.py b/pydecoder/xmldecode.py index a6a0e14d..667156d0 100644 --- a/pydecoder/xmldecode.py +++ b/pydecoder/xmldecode.py @@ -4,7 +4,7 @@ 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 @@ -87,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 @@ -96,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 @@ -105,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