Skip to content

Commit 10bf74e

Browse files
committed
[FIX] fix for ever the problem of unknow now key, add a generic parser and update the version of the lib
1 parent ca00991 commit 10bf74e

File tree

2 files changed

+13
-44
lines changed

2 files changed

+13
-44
lines changed

cfonb/parser/common.py

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, line):
5050
"""
5151
# do re match
5252
parser = Parser.get_parser(line[0:2])
53-
self.update(parser().parse(line))
53+
self.update(parser.parse(line))
5454

5555
def __getattr__(self, attr):
5656
return self[attr]
@@ -65,8 +65,8 @@ class Parser(object):
6565
def get_parser(cls, key):
6666
for sub_cls in cls.__subclasses__():
6767
if sub_cls._code == key:
68-
return sub_cls
69-
raise Exception('No class found for key %s'%key)
68+
return sub_cls()
69+
return ParserGeneric(key)
7070

7171
def __init__(self):
7272
self._regex
@@ -203,7 +203,7 @@ class ParserContent05(Parser):
203203
def parse(self, line):
204204
result = super(ParserContent05, self).parse(line)
205205
parser = Parser.get_parser(result['qualifier'])
206-
new_result = parser().parse(result['additional_info'])
206+
new_result = parser.parse(result['additional_info'])
207207
return new_result
208208

209209

@@ -368,47 +368,16 @@ class ParserCBE(Parser):
368368
]
369369

370370

371-
##### TODO FIXME this 3 new parser are introduced by the new sepa norme but
372-
# you know administration is an administration and so the spec for the norme
373-
# are somewhere but I still not suceed to get it, I send an email to the CFONB
374-
# and I wait for the norme. For now I just process the line like that.
371+
#Use a generic parser for all case that are not in the norme...
372+
class ParserGeneric(Parser):
373+
_code = None
374+
_regex = []
375375

376-
#Still no news of the administration
377-
#It seem that the norm allow bank to add what they want very usefull norm ;)
378-
#By chance the next norme will may be fix the format.
379-
#Indeed next norme is "format camt.05". I ask the Cfonb organisation to know when the bank will start to use
380-
#this new format but ... they don't know ;)
376+
def __init__(self, code):
377+
self._code = code
381378

382-
class ParserREF(Parser):
383-
_code = 'REF'
384-
_regex = [
385-
('ref', G_ALL, 70),
386-
]
387-
388-
class ParserBDB(Parser):
389-
_code = 'BDB'
390-
_regex = [
391-
('bdb', G_ALL, 70),
392-
]
393-
394-
class ParserLEM(Parser):
395-
_code = 'LEM'
396-
_regex = [
397-
('lem', G_ALL, 70),
398-
]
399-
400-
class ParserPDO(Parser):
401-
_code = 'PDO'
402-
_regex = [
403-
('pdo', G_ALL, 70),
404-
]
405-
406-
407-
class ParserRET(Parser):
408-
_code = 'RET'
409-
_regex = [
410-
('ret', G_ALL, 70),
411-
]
379+
def parse(self, line):
380+
return {self._code: line}
412381

413382

414383
#specific to withdrawal

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22
import sys, os
33

4-
version = '0.1'
4+
version = '0.2.0'
55

66
long_description = open('README.rst').read()
77

0 commit comments

Comments
 (0)