diff options
author | Andrej Shadura <andrewsh@debian.org> | 2018-11-05 14:44:38 +0100 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2018-11-05 14:44:38 +0100 |
commit | 4d73449bab819dddc8e7f52ddf01b6bacd2a7e40 (patch) | |
tree | 992d9135cdaf62c13cf05fb6bc73628b1d5c7577 /ofxparse/ofxutil.py | |
parent | 8f6a863fcd6a0518ea8e3e1e863346553d0250ba (diff) | |
parent | 59c3ccc50d3504bfeb1a3f7e31ba806e2b5c3a07 (diff) |
Update upstream source from tag 'upstream/0.19'
Update to upstream version '0.19'
with Debian dir 0cc2866dc4222e919db114429121a55eadb99c77
Diffstat (limited to 'ofxparse/ofxutil.py')
-rw-r--r-- | ofxparse/ofxutil.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/ofxparse/ofxutil.py b/ofxparse/ofxutil.py index 0002ee1..391c221 100644 --- a/ofxparse/ofxutil.py +++ b/ofxparse/ofxutil.py @@ -1,17 +1,15 @@ from __future__ import absolute_import, with_statement import os -import copy import collections import xml.etree.ElementTree as ET +import six if 'OrderedDict' in dir(collections): odict = collections else: import ordereddict as odict -import six - class InvalidOFXStructureException(Exception): pass @@ -103,18 +101,18 @@ class OfxData(object): return len(self.nodes) def __str__(self): - return os.linesep.join("\t" * line[1] + line[0] for line \ - in self.format()) + return os.linesep.join("\t" * line[1] + line[0] for line in + self.format()) def format(self): if self.data or not self.nodes: if self.tag.upper() == "OFX": - return [["<%s>%s</%s>" % (self.tag, self.data \ + return [["<%s>%s</%s>" % (self.tag, self.data if self.data else "", self.tag), 0]] return [["<%s>%s" % (self.tag, self.data), 0]] else: ret = [["<%s>" % self.tag, -1]] - for name, child in six.iteritems(self.nodes): + for _, child in six.iteritems(self.nodes): if isinstance(child, OfxData): ret.extend(child.format()) else: @@ -138,7 +136,7 @@ class OfxUtil(OfxData): ofx_data.lower().endswith('.ofx'): self.parse(ofx_data) else: - self.parse(open(ofx_data).read() if isinstance(\ + self.parse(open(ofx_data).read() if isinstance( ofx_data, six.string_types) else ofx_data.read()) def parse(self, ofx): @@ -150,8 +148,6 @@ class OfxUtil(OfxData): self.headers[header] = value except ValueError: pass - except: - raise finally: if "OFXHEADER" not in self.headers: self.headers["OFXHEADER"] = "100" @@ -201,7 +197,7 @@ class OfxUtil(OfxData): self.xml = ET.fromstringlist(tags) self.load_from_xml(self, self.xml) - except: + except Exception: raise InvalidOFXStructureException def load_from_xml(self, ofx, xml): @@ -219,11 +215,12 @@ class OfxUtil(OfxData): f.write(str(self)) def __str__(self): - ret = os.linesep.join(":".join(line) for line in \ + ret = os.linesep.join(":".join(line) for line in six.iteritems(self.headers)) + os.linesep * 2 ret += super(OfxUtil, self).__str__() return ret + if __name__ == "__main__": here = os.path.dirname(__file__) fixtures = os.path.join(here, '../tests/fixtures/') |