Just a small update. I found a really small and nice solution to the problem. The following module will make python able to parse ruby yaml objects better, and solves all my problems. Hope that someone else also finds use for it. Just use ruby_yaml.safe_load(xxx) instead of yaml and it will work much better. Here is ruby_yaml.py:

from yaml import *

# Add constructors for special ruby yaml objects
for loader in (Loader, SafeLoader):
    add_constructor(u'!binary', constructor.SafeConstructor.construct_yaml_binary, loader)
    add_constructor(u'!map:HashWithIndifferentAccess', constructor.SafeConstructor.construct_mapping, loader)


On Tue, Jul 27, 2010 at 11:26, Dr AA <anders.arpteg@gmail.com> wrote:

We are having problem with the Ruby and the Python implementation of
YAML. Ruby seems to be YAML 1.0 and Python shall be YAML 1.1
compatible. Hopefully, one would wish that the Python implementation
was backward compatible and able to parse Ruby encoded data. However,
that seems not to be the case. See example below.

I have tried with the PySyck module that is YAML 1.0 compatible, and
it can then parse the Ruby YAML. However, that project seems abandoned
and seems to have problems with certain python versions. Anyone with
similar problems, and possible solutions?

This cause serious problems for us and it seems very strange that YAML
is not even backwards compatible. Perhaps we have to switch to JSON or
some other format to overcome this problem, but hopefully have I
overlooked some issue/solution that someone in this mailing list can
help me with.

Thanks in advance!

Ruby 1.9.0:

>> require 'yaml'
=> []
>> YAML.dump('ċ')
=> "--- !binary |\nw6U=\n\n"

Python 2.6.5:

>>> import yaml
>>> yaml.safe_load("--- !binary |\nw6U=\n\n")
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/lib/python2.6/dist-packages/yaml/__init__.py", line 75,
in safe_load
   return load(stream, SafeLoader)
 File "/usr/lib/python2.6/dist-packages/yaml/__init__.py", line 58,
in load
   return loader.get_single_data()
 File "/usr/lib/python2.6/dist-packages/yaml/constructor.py", line
42, in get_single_data
   node = self.get_single_node()
 File "/usr/lib/python2.6/dist-packages/yaml/composer.py", line 39,
in get_single_node
   if not self.check_event(StreamEndEvent):
 File "/usr/lib/python2.6/dist-packages/yaml/parser.py", line 93, in
   self.current_event = self.state()
 File "/usr/lib/python2.6/dist-packages/yaml/parser.py", line 169, in
yaml.parser.ParserError: expected '<document start>', but found
 in "<string>", line 2, column 1: