Index: pyyaml/trunk/lib/yaml/representer.py
===================================================================
--- pyyaml/trunk/lib/yaml/representer.py	(revision 135)
+++ pyyaml/trunk/lib/yaml/representer.py	(revision 136)
@@ -21,67 +21,51 @@
     pass
 
-class BaseRepresenter(BaseDetector):
-
-    DEFAULT_SCALAR_TAG = u'tag:yaml.org,2002:str'
-    DEFAULT_SEQUENCE_TAG = u'tag:yaml.org,2002:seq'
-    DEFAULT_MAPPING_TAG = u'tag:yaml.org,2002:map'
-
-    def __init__(self, serializer):
-        self.serializer = serializer
+class BaseRepresenter:
+
+    yaml_representers = {}
+
+    def __init__(self):
         self.represented_objects = {}
 
-    def close(self):
-        self.serializer.close()
-
-    def represent(self, native):
-        node = self.represent_object(native)
-        self.serializer.serialize(node)
+    def represent(self, data):
+        node = self.represent_object(data)
+        self.serialize(node)
         self.represented_objects = {}
 
-    def represent_object(self, native):
-        if self.ignore_aliases(native):
+    def represent_object(self, data):
+        if self.ignore_aliases(data):
             alias_key = None
         else:
-            alias_key = id(native)
+            alias_key = id(data)
         if alias_key is not None:
             if alias_key in self.represented_objects:
                 node = self.represented_objects[alias_key]
                 if node is None:
-                    raise RepresenterError("recursive objects are not allowed: %r" % native)
+                    raise RepresenterError("recursive objects are not allowed: %r" % data)
                 return node
             self.represented_objects[alias_key] = None
-        for native_type in type(native).__mro__:
-            if native_type in self.yaml_representers:
-                node = self.yaml_representers[native_type](self, native)
+        for data_type in type(data).__mro__:
+            if data_type in self.yaml_representers:
+                node = self.yaml_representers[data_type](self, data)
                 break
         else:
             if None in self.yaml_representers:
-                node = self.yaml_representers[None](self, native)
+                node = self.yaml_representers[None](self, data)
             else:
-                node = ScalarNode(None, unicode(native))
+                node = ScalarNode(None, unicode(data))
         if alias_key is not None:
             self.represented_objects[alias_key] = node
         return node
 
-    def add_representer(cls, native_type, representer):
+    def add_representer(cls, data_type, representer):
         if not 'yaml_representers' in cls.__dict__:
             cls.yaml_representers = cls.yaml_representers.copy()
-        cls.yaml_representers[native_type] = representer
+        cls.yaml_representers[data_type] = representer
     add_representer = classmethod(add_representer)
 
-    yaml_representers = {}
-
     def represent_scalar(self, tag, value, style=None):
-        detected_tag = self.detect(value)
-        if detected_tag is None:
-            detected_tag = self.DEFAULT_SCALAR_TAG
-        implicit = (tag == detected_tag)
-        if tag == self.DEFAULT_SCALAR_TAG:
-            tag = None
-        return ScalarNode(tag, value, implicit=implicit, style=style)
+        return ScalarNode(tag, value, style=style)
 
     def represent_sequence(self, tag, sequence, flow_style=None):
-        if tag == self.DEFAULT_SEQUENCE_TAG:
-            tag = None
         value = []
         for item in sequence:
@@ -90,6 +74,4 @@
 
     def represent_mapping(self, tag, mapping, flow_style=None):
-        if tag == self.DEFAULT_MAPPING_TAG:
-            tag = None
         value = {}
         if hasattr(mapping, 'keys'):
@@ -104,27 +86,27 @@
         return MappingNode(tag, value, flow_style=flow_style)
 
-    def ignore_aliases(self, native):
+    def ignore_aliases(self, data):
         return False
 
-class SafeRepresenter(Detector, BaseRepresenter):
-
-    def ignore_aliases(self, native):
-        if native in [None, ()]:
+class SafeRepresenter(BaseRepresenter):
+
+    def ignore_aliases(self, data):
+        if data in [None, ()]:
             return True
-        if isinstance(native, (str, unicode, bool, int, float)):
+        if isinstance(data, (str, unicode, bool, int, float)):
             return True
 
-    def represent_none(self, native):
+    def represent_none(self, data):
         return self.represent_scalar(u'tag:yaml.org,2002:null',
                 u'null')
 
-    def represent_str(self, native):
+    def represent_str(self, data):
         encoding = None
         try:
-            unicode(native, 'ascii')
+            unicode(data, 'ascii')
             encoding = 'ascii'
         except UnicodeDecodeError:
             try:
-                unicode(native, 'utf-8')
+                unicode(data, 'utf-8')
                 encoding = 'utf-8'
             except UnicodeDecodeError:
@@ -132,14 +114,14 @@
         if encoding:
             return self.represent_scalar(u'tag:yaml.org,2002:str',
-                    unicode(native, encoding))
+                    unicode(data, encoding))
         else:
             return self.represent_scalar(u'tag:yaml.org,2002:binary',
-                    unicode(native.encode('base64')), style='|')
-
-    def represent_unicode(self, native):
-        return self.represent_scalar(u'tag:yaml.org,2002:str', native)
-
-    def represent_bool(self, native):
-        if native:
+                    unicode(data.encode('base64')), style='|')
+
+    def represent_unicode(self, data):
+        return self.represent_scalar(u'tag:yaml.org,2002:str', data)
+
+    def represent_bool(self, data):
+        if data:
             value = u'true'
         else:
@@ -147,63 +129,77 @@
         return self.represent_scalar(u'tag:yaml.org,2002:bool', value)
 
-    def represent_int(self, native):
-        return self.represent_scalar(u'tag:yaml.org,2002:int', unicode(native))
-
-    def represent_long(self, native):
-        return self.represent_scalar(u'tag:yaml.org,2002:int', unicode(native))
+    def represent_int(self, data):
+        return self.represent_scalar(u'tag:yaml.org,2002:int', unicode(data))
+
+    def represent_long(self, data):
+        return self.represent_scalar(u'tag:yaml.org,2002:int', unicode(data))
 
     inf_value = 1e300000
     nan_value = inf_value/inf_value
 
-    def represent_float(self, native):
-        if native == self.inf_value:
+    def represent_float(self, data):
+        if data == self.inf_value:
             value = u'.inf'
-        elif native == -self.inf_value:
+        elif data == -self.inf_value:
             value = u'-.inf'
-        elif native == self.nan_value or native != native:
+        elif data == self.nan_value or data != data:
             value = u'.nan'
         else:
-            value = unicode(native)
+            value = unicode(data)
         return self.represent_scalar(u'tag:yaml.org,2002:float', value)
 
-    def represent_list(self, native):
-        pairs = (len(native) > 0)
-        for item in native:
+    def represent_list(self, data):
+        pairs = (len(data) > 0)
+        for item in data:
             if not isinstance(item, tuple) or len(item) != 2:
                 pairs = False
                 break
         if not pairs:
-            return self.represent_sequence(u'tag:yaml.org,2002:seq', native)
+            return self.represent_sequence(u'tag:yaml.org,2002:seq', data)
         value = []
-        for item_key, item_value in native:
+        for item_key, item_value in data:
             value.append(self.represent_mapping(u'tag:yaml.org,2002:map',
                 [(item_key, item_value)]))
         return SequenceNode(u'tag:yaml.org,2002:pairs', value)
 
-    def represent_dict(self, native):
-        return self.represent_mapping(u'tag:yaml.org,2002:map', native)
-
-    def represent_set(self, native):
+    def represent_dict(self, data):
+        return self.represent_mapping(u'tag:yaml.org,2002:map', data)
+
+    def represent_set(self, data):
         value = {}
-        for key in native:
+        for key in data:
             value[key] = None
         return self.represent_mapping(u'tag:yaml.org,2002:set', value)
 
-    def represent_date(self, native):
-        value = u'%04d-%02d-%02d' % (native.year, native.month, native.day)
+    def represent_date(self, data):
+        value = u'%04d-%02d-%02d' % (data.year, data.month, data.day)
         return self.represent_scalar(u'tag:yaml.org,2002:timestamp', value)
 
-    def represent_datetime(self, native):
+    def represent_datetime(self, data):
         value = u'%04d-%02d-%02d %02d:%02d:%02d' \
-                % (native.year, native.month, native.day,
-                    native.hour, native.minute, native.second)
-        if native.microsecond:
-            value += u'.' + unicode(native.microsecond/1000000.0).split(u'.')[1]
-        if native.utcoffset():
-            value += unicode(native.utcoffset())
+                % (data.year, data.month, data.day,
+                    data.hour, data.minute, data.second)
+        if data.microsecond:
+            value += u'.' + unicode(data.microsecond/1000000.0).split(u'.')[1]
+        if data.utcoffset():
+            value += unicode(data.utcoffset())
         return self.represent_scalar(u'tag:yaml.org,2002:timestamp', value)
 
-    def represent_undefined(self, native):
-        raise RepresenterError("cannot represent an object: %s" % native)
+    def represent_yaml_object(self, tag, data, cls, flow_style=None):
+        if hasattr(data, '__getstate__'):
+            state = data.__getstate__()
+        else:
+            state = data.__dict__.copy()
+        mapping = state
+        if hasattr(state, 'keys'):
+            mapping = []
+            keys = state.keys()
+            keys.sort()
+            for key in keys:
+                mapping.append((key.replace('_', '-'), state[key]))
+        return self.represent_mapping(tag, mapping, flow_style=flow_style)
+
+    def represent_undefined(self, data):
+        raise RepresenterError("cannot represent an object: %s" % data)
 
 SafeRepresenter.add_representer(type(None),
