Skip to content

Commit ba426ed

Browse files
theangryangelBlommaertsEdwin
authored andcommitted
Fix Message.from_str
1 parent 061ec2d commit ba426ed

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pydifact/segmentcollection.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,25 @@ def from_segments(
395395

396396
return cls(reference_number, identifier).add_segments(segments)
397397

398+
@classmethod
399+
def from_str(cls, string: str) -> "AbstractSegmentsContainer":
400+
segments = Parser().parse(string)
401+
402+
unh = None
403+
todo = []
404+
405+
for segment in segments:
406+
if segment.tag == "UNH":
407+
unh = segment
408+
continue
409+
if segment.tag == "UNT":
410+
continue
411+
todo.append(segment)
412+
413+
if not unh:
414+
raise EDISyntaxError("Missing header in message")
415+
return cls.from_segments(unh[0], unh[1], todo)
416+
398417

399418
class Interchange(FileSourcableMixin, UNAHandlingMixin, AbstractSegmentsContainer):
400419
"""

0 commit comments

Comments
 (0)