.. autoclass:: fints.segments.FinTS3Segment
:members:
:inherited-members: print_nested
+ :member-order: bysource
.. attribute:: TYPE
.. autoclass:: fints.formals.SegmentHeader
:members:
+ :member-order: bysource
The :class:`~fints.segments.FinTS3Segment` class and its base classes employ a number of dynamic programming techniques so that derived classes need only specify the name, order and type of fields and all type conversion, construction etc. will take place automatically. All derived classes basically should behave "as expected", returning only native Python datatypes.
:members:
:inherited-members:
:exclude-members: print_nested
+ :member-order: bysource
+
+Field types
+___________
+
+.. automodule:: fints.formals
+ :members:
+ :undoc-members:
+ :exclude-members: print_nested
+ :member-order: bysource
segment.print_nested(stream=stream, level=level+1, indent=indent, prefix=prefix, first_level_indent=True, trailer=",")
stream.write( (prefix + level*indent) + "]){}\n".format(trailer) )
- def find_segments(self, type=None, version=None, callback=None, recurse=True):
+ def find_segments(self, query=None, version=None, callback=None, recurse=True):
"""Yields an iterable of all matching segments.
- :param type: Either a str specifying a segment type (such as 'HNHBK'), or a list or tuple of strings.
+ :param query: Either a str or class specifying a segment type (such as 'HNHBK', or :class:`~fints.segments.HNHBK3`), or a list or tuple of strings or classes.
If a list/tuple is specified, segments returning any matching type will be returned.
:param version: Either an int specifying a segment version, or a list or tuple of ints.
If a list/tuple is specified, segments returning any matching version will be returned.
The match results of all given parameters will be AND-combined.
"""
- if type is None:
- type = []
- elif isinstance(type, str) or not isinstance(type, (list, tuple, Iterable)):
- type = [type]
+ if query is None:
+ query = []
+ elif isinstance(query, str) or not isinstance(query, (list, tuple, Iterable)):
+ query = [query]
if version is None:
version = []
callback = lambda s: True
for s in self.segments:
- if ((not type) or any(s.header.type == t for t in type)) and \
+ if ((not query) or any( (isinstance(s, t) if isinstance(t, type) else s.header.type == t) for t in query)) and \
((not version) or any(s.header.version == v for v in version)) and \
callback(s):
yield s
if isinstance(field, SegmentSequenceField):
val = getattr(s, name)
if val:
- yield from val.find_segments(type=type, version=version, callback=callback, recurse=recurse)
+ yield from val.find_segments(query=query, version=version, callback=callback, recurse=recurse)
def find_segment_first(self, *args, **kwargs):
"""Finds the first matching segment.
assert len( m.find_segment_first('HITANS', 3).parameter.twostep_parameters ) == 6
assert m.find_segment_first('HITANS', recurse=False) is None
+
+def test_find_by_class():
+ from conftest import TEST_MESSAGES
+ from fints.parser import FinTS3Parser
+ from fints.segments import HNHBS1
+
+ m = FinTS3Parser().parse_message(TEST_MESSAGES['basic_complicated'])
+
+ assert list(m.find_segments(HNHBS1))[0].__class__ == HNHBS1
+
+ assert m.find_segment_first(HNHBS1).header.type == 'HNHBS'