|
1 | 1 | import re
|
2 | 2 |
|
3 |
| -from fints.formals import Container, SegmentHeader, DataElementGroupField, DataElementField, ReferenceMessage, SegmentSequenceField, SecurityProfile, SecurityIdentificationDetails, SecurityDateTime, EncryptionAlgorithm, KeyName, Certificate, HashAlgorithm, SignatureAlgorithm, UserDefinedSignature, Response |
| 3 | +from fints.formals import Container, ContainerMeta, SegmentHeader, DataElementGroupField, DataElementField, ReferenceMessage, SegmentSequenceField, SecurityProfile, SecurityIdentificationDetails, SecurityDateTime, EncryptionAlgorithm, KeyName, Certificate, HashAlgorithm, SignatureAlgorithm, UserDefinedSignature, Response |
4 | 4 |
|
5 | 5 | from fints.utils import classproperty, SubclassesMixin
|
6 | 6 |
|
7 | 7 | TYPE_VERSION_RE = re.compile(r'^([A-Z]+)(\d+)$')
|
8 | 8 |
|
9 |
| -class FinTS3Segment(Container, SubclassesMixin): |
| 9 | +class FinTS3SegmentMeta(ContainerMeta): |
| 10 | + @staticmethod |
| 11 | + def _check_fields_recursive(instance): |
| 12 | + for name, field in instance._fields.items(): |
| 13 | + if not isinstance(field, (DataElementField, DataElementGroupField)): |
| 14 | + raise TypeError("{}={!r} is not DataElementField or DataElementGroupField".format(name, field)) |
| 15 | + if isinstance(field, DataElementGroupField): |
| 16 | + FinTS3SegmentMeta._check_fields_recursive(field.type) |
| 17 | + |
| 18 | + def __new__(cls, name, bases, classdict): |
| 19 | + retval = super().__new__(cls, name, bases, classdict) |
| 20 | + FinTS3SegmentMeta._check_fields_recursive(retval) |
| 21 | + return retval |
| 22 | + |
| 23 | +class FinTS3Segment(Container, SubclassesMixin, metaclass=FinTS3SegmentMeta): |
10 | 24 | header = DataElementGroupField(type=SegmentHeader)
|
11 | 25 |
|
12 | 26 | @classproperty
|
|
0 commit comments