Skip to content

Commit 54e1359

Browse files
committed
Fix Message.from_str
1 parent db130c8 commit 54e1359

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pydifact/segmentcollection.py

+19
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,25 @@ def from_segments(
317317

318318
return cls(reference_number, identifier).add_segments(segments)
319319

320+
@classmethod
321+
def from_str(cls, string: str) -> "AbstractSegmentsContainer":
322+
segments = Parser().parse(string)
323+
324+
unh = None
325+
todo = []
326+
327+
for segment in segments:
328+
if segment.tag == "UNH":
329+
unh = segment
330+
continue
331+
if segment.tag == "UNT":
332+
continue
333+
todo.append(segment)
334+
335+
if not unh:
336+
raise EDISyntaxError("Missing header in message")
337+
return cls.from_segments(unh[0], unh[1], todo)
338+
320339

321340
class Interchange(FileSourcableMixin, UNAHandlingMixin, AbstractSegmentsContainer):
322341
"""

0 commit comments

Comments
 (0)