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:
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!
>> require 'yaml'
=> "--- !binary |\nw6U=\n\n"
>>> 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,
return load(stream, SafeLoader)
File "/usr/lib/python2.6/dist-packages/yaml/__init__.py", line 58,
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,
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: