def test_strip_empty_tags(self): with open(join(realpath(dirname(__file__)), 'fixtures', 'empty_tags.ofx'), 'r') as f: empty_tags_file = f.read() empty_tag_pattern = '<(?P<tag>[^>]+)>\s*</(?P=tag)>' result = strip_empty_tags(empty_tags_file) self.assertFalse(re.match(empty_tag_pattern, result))
def parse(self, ofx): """Parse a string argument and return a tree structure representing the parsed document.""" if(isinstance(ofx, bytes)): ofx = ofx.decode('utf-8') ofx = strip_empty_tags(ofx) ofx = self.strip_close_tags(ofx) ofx = self.strip_blank_dtasof(ofx) ofx = self.strip_junk_ascii(ofx) ofx = self.fix_unknown_account_type(ofx) parsed = self.parser.parseString(ofx).asDict() def add_on_presence(k): if k in parsed["body"]["OFX"][0]: parsed["body"]["OFX"][k] = parsed["body"]["OFX"][0][k] add_on_presence("SIGNONMSGSRSV1") add_on_presence("SIGNONMSGSRQV1") add_on_presence("CREDITCARDMSGSRSV1") add_on_presence("BANKMSGSRSV1") add_on_presence("CREDITCARDMSGSRQV1") add_on_presence("BANKMSGSRQV1") add_on_presence("SIGNUPMSGSRQV1") return parsed
def parse(self, ofx): """Parse a string argument and return a tree structure representing the parsed document.""" if (isinstance(ofx, bytes)): ofx = ofx.decode('utf-8') ofx = strip_empty_tags(ofx) ofx = self.strip_close_tags(ofx) ofx = self.strip_blank_dtasof(ofx) ofx = self.strip_junk_ascii(ofx) ofx = self.fix_unknown_account_type(ofx) parsed = self.parser.parseString(ofx).asDict() def add_on_presence(k): if k in parsed["body"]["OFX"][0]: parsed["body"]["OFX"][k] = parsed["body"]["OFX"][0][k] add_on_presence("SIGNONMSGSRSV1") add_on_presence("SIGNONMSGSRQV1") add_on_presence("CREDITCARDMSGSRSV1") add_on_presence("BANKMSGSRSV1") add_on_presence("CREDITCARDMSGSRQV1") add_on_presence("BANKMSGSRQV1") add_on_presence("SIGNUPMSGSRQV1") return parsed
def test_strip_empty_tags(self): with open( join(realpath(dirname(__file__)), 'fixtures', 'empty_tags.ofx'), 'r') as f: empty_tags_file = f.read() empty_tag_pattern = '<(?P<tag>[^>]+)>\s*</(?P=tag)>' result = strip_empty_tags(empty_tags_file) self.assertFalse(re.match(empty_tag_pattern, result))
def parse(self, ofc): """Parse a string argument and return a tree structure representing the parsed document.""" ofc = self.add_zero_to_empty_ledger_tag(ofc) ofc = self.remove_inline_closing_tags(ofc) ofc = strip_empty_tags(ofc) ofc = self._translate_chknum_to_checknum(ofc) # if you don't have a good stomach, skip this part # XXX:needs better solution import sys sys.setrecursionlimit(5000) try: return self.parser.parseString(ofc).asDict() except ParseException: fixed_ofc = self.fix_ofc(ofc) return self.parser.parseString(fixed_ofc).asDict()