def parse(self, source): if not hasattr(source, 'read'): source = open(source) with source as s: source = s.read() if hasattr(source, 'decode'): source = source.decode() # Validate and strip the OFX header source = OFXHeader.strip(source) # Then parse tag soup into tree of Elements parser = TreeBuilder(element_factory=self.element_factory) parser.feed(source) self._root = parser.close()
def _testFeedSonrs(self, body): """ str -> Element tests reused to test responses with identical content but different formatting. """ builder = TreeBuilder() builder.feed(body) root = builder.close() self._testElement(root, tag="OFX", text=None, length=1) msgsrs = root[0] self._testElement(msgsrs, tag="SIGNONMSGSRSV1", text=None, length=1) sonrs = msgsrs[0] self._testElement(sonrs, tag="SONRS", text=None, length=6) status, dtserver, language, dtprofup, dtacctup, fi = sonrs self._testElement(status, tag="STATUS", text=None, length=2) code, severity = status self._testElement(code, tag="CODE", text="0", length=0) self._testElement(severity, tag="SEVERITY", text="INFO", length=0) self._testElement(dtserver, tag="DTSERVER", text="20051029101003", length=0) self._testElement(language, tag="LANGUAGE", text="ENG", length=0) self._testElement(dtprofup, tag="DTPROFUP", text="19991029101003", length=0) self._testElement(dtacctup, tag="DTACCTUP", text="20031029101003", length=0) self._testElement(fi, tag="FI", text=None, length=2) org, fid = fi self._testElement(org, tag="ORG", text="NCH", length=0) self._testElement(fid, tag="FID", text="1001", length=0)
def setUpClass(cls): cls.tree = OFXTree() parser = TreeBuilder() parser.feed(cls.ofx) cls.tree._root = parser.close()