changeset 24:111f8d6c1d79

Parse only supported tags in _find_swit_tags
author Nicolas Évrard <nicoe@b2ck.com>
date Tue, 21 Feb 2017 18:23:29 +0100
parents ceff7fe13a4b
children 4fce8272c8d9
files mt940/__init__.py mt940/test.py
diffstat 2 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mt940/__init__.py	Wed Jan 27 10:34:21 2016 +0100
+++ b/mt940/__init__.py	Tue Feb 21 18:23:29 2017 +0100
@@ -173,12 +173,17 @@
     for tag, name in tags:
         if description.startswith(tag):
             description = description[len(tag):]
-            try:
-                i = description.index('/')
-            except ValueError:
-                i = len(description)
-            values[name] = description[:i]
-            description = description[i:]
+            cursor = len(description)
+            for next_tag, _ in tags:
+                if next_tag in values or next_tag == tag:
+                    continue
+                index = description.find(next_tag)
+                if index == -1:
+                    continue
+                cursor = min(cursor, index)
+            next_tag_index = cursor
+            values[name] = description[:next_tag_index]
+            description = description[next_tag_index:]
         if not description:
             break
     return values
--- a/mt940/test.py	Wed Jan 27 10:34:21 2016 +0100
+++ b/mt940/test.py	Tue Feb 21 18:23:29 2017 +0100
@@ -127,6 +127,16 @@
         self.assertEqual(rabo_description('foo'), {})
         self.assertEqual(rabo_description('/FOO/BAR/NAME/'), {})
 
+    def test_mixed_tags(self):
+        self.assertEqual(
+            rabo_description(
+                '/EREF/0007301960/ORDP//NAME/Acist Europe B.V./ADDR/'
+                'Heerlen 6422 PH Heerlen NL/REMI//INV/16000291 29.7.2016'),
+            {'eref': '0007301960', 'ordp': '',
+                'name': 'Acist Europe B.V.',
+                'addr': 'Heerlen 6422 PH Heerlen NL',
+                'remi': '/INV/16000291 29.7.2016'})
+
 
 class TestABNAMRODescription(unittest.TestCase):