Ignore:
Timestamp:
08/03/06 12:07:29 (8 years ago)
Author:
xi
Message:

Subclass all base classes from object.

Hold references to the objects being represented (should fix #22).

The value of a mapping node is represented as a list of pairs (key, value)
now.

Sort dictionary items (fix #23).

Recursive structures are now loaded and dumped correctly, including complex
structures like recursive tuples (fix #5). Thanks Peter Murphy for the patches.
To make it possible, representer functions are allowed to be generators.
In this case, the first generated value is an object. Other values produced
by the representer are ignored.

Make Representer not try to guess !!pairs when a list is represented.
You need to construct a !!pairs node explicitly now.

Do not check for duplicate mapping keys as it didn't work correctly anyway.

File:
1 edited

Legend:

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

    r139 r222  
    99    pass 
    1010 
    11 class Serializer: 
     11class Serializer(object): 
    1212 
    1313    ANCHOR_TEMPLATE = u'id%03d' 
     
    6868                    self.anchor_node(item) 
    6969            elif isinstance(node, MappingNode): 
    70                 if hasattr(node.value, 'keys'): 
    71                     for key in node.value.keys(): 
    72                         self.anchor_node(key) 
    73                         self.anchor_node(node.value[key]) 
    74                 else: 
    75                     for key, value in node.value: 
    76                         self.anchor_node(key) 
    77                         self.anchor_node(value) 
     70                for key, value in node.value: 
     71                    self.anchor_node(key) 
     72                    self.anchor_node(value) 
    7873 
    7974    def generate_anchor(self, node): 
     
    109104                self.emit(MappingStartEvent(alias, node.tag, implicit, 
    110105                    flow_style=node.flow_style)) 
    111                 if hasattr(node.value, 'keys'): 
    112                     for key in node.value.keys(): 
    113                         self.serialize_node(key, node, None) 
    114                         self.serialize_node(node.value[key], node, key) 
    115                 else: 
    116                     for key, value in node.value: 
    117                         self.serialize_node(key, node, None) 
    118                         self.serialize_node(value, node, key) 
     106                for key, value in node.value: 
     107                    self.serialize_node(key, node, None) 
     108                    self.serialize_node(value, node, key) 
    119109                self.emit(MappingEndEvent()) 
    120110            self.ascend_resolver() 
Note: See TracChangeset for help on using the changeset viewer.