summaryrefslogtreecommitdiff
path: root/ofxparse/ofxutil.py
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2018-11-05 14:44:38 +0100
committerAndrej Shadura <andrewsh@debian.org>2018-11-05 14:44:38 +0100
commit59c3ccc50d3504bfeb1a3f7e31ba806e2b5c3a07 (patch)
tree8021d433dbbd4dc2cff52ea33de8d61625d444cd /ofxparse/ofxutil.py
parentd8736ad37771257f5e8090072fccfbac90098633 (diff)
New upstream version 0.19
Diffstat (limited to 'ofxparse/ofxutil.py')
-rw-r--r--ofxparse/ofxutil.py21
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/')