From adfeccd2095cb0cba8c6f5c81bf23610f6290916 Mon Sep 17 00:00:00 2001 From: Pat Ekman Date: Sat, 6 Feb 2021 17:29:47 -0800 Subject: [PATCH] Fixing parse error "unknown encoding: cpNONE" This handles the case where the encoding is "USASCII" and the charset is the string "NONE" instead of a valid charset. I've seen this in files from two different institutions. --- ofxparse/ofxparse.py | 2 ++ tests/test_parse.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ofxparse/ofxparse.py b/ofxparse/ofxparse.py index 8af6c60..6b853c4 100644 --- a/ofxparse/ofxparse.py +++ b/ofxparse/ofxparse.py @@ -124,6 +124,8 @@ def handle_encoding(self): cp = ascii_headers.get("CHARSET", "1252") if cp == "8859-1": encoding = "iso-8859-1" + elif cp == "NONE": + encoding = "1252" else: encoding = "cp%s" % (cp, ) diff --git a/tests/test_parse.py b/tests/test_parse.py index 78bd779..7208b2b 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -123,6 +123,24 @@ def testBrokenLineEndings(self): ofx_file = self.OfxFileCls(fh) self.assertEqual(len(ofx_file.headers.keys()), 2) + def testUSASCIICharsetNone(self): + fh = six.BytesIO(six.b("""OFXHEADER:100 +DATA:OFXSGML +VERSION:102 +SECURITY:NONE +ENCODING:USASCII +CHARSET:NONE +COMPRESSION:NONE +OLDFILEUID:NONE +NEWFILEUID:NONE +""")) + ofx_file = self.OfxFileCls(fh) + headers = ofx_file.headers + result = ofx_file.fh.read() + + self.assertTrue(type(result) is six.text_type) + self.assertHeadersTypes(headers) + class TestOfxPreprocessedFile(TestOfxFile): OfxFileCls = OfxPreprocessedFile