Ignore:
Timestamp:
08/21/07 16:25:34 (7 years ago)
Author:
xi
Message:

Make compose() and load() ensure that the input stream contains a single document. Fixes #54.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyyaml/trunk/lib/yaml/composer.py

    r233 r258  
    2626        if not self.check_event(StreamEndEvent): 
    2727            return self.compose_document() 
     28 
     29    def get_single_node(self): 
     30        # Drop the STREAM-START event. 
     31        self.get_event() 
     32 
     33        # Compose a document if the stream is not empty. 
     34        document = None 
     35        if not self.check_event(StreamEndEvent): 
     36            document = self.compose_document() 
     37 
     38        # Ensure that the stream contains no more documents. 
     39        if not self.check_event(StreamEndEvent): 
     40            event = self.get_event() 
     41            raise ComposerError("expected a single document in the stream", 
     42                    document.start_mark, "but found another document", 
     43                    event.start_mark) 
     44 
     45        # Drop the STREAM-END event. 
     46        self.get_event() 
     47 
     48        return document 
    2849 
    2950    def compose_document(self): 
Note: See TracChangeset for help on using the changeset viewer.