Does anyone know why this yaml is parsed and read correctly by my app
development:
autocreate_indexes: false
allow_dynamic_fields: true
include_root_in_json: false
parameterize_keys: true
persist_in_safe_mode: false
raise_not_found_error: true
reconnect_time: 3
uri: mongodb://app:app@flame.mongohq.com:27076/app1
But this yaml is not
defaults: &defaults
autocreate_indexes: false
allow_dynamic_fields: true
include_root_in_json: false
parameterize_keys: true
persist_in_safe_mode: false
raise_not_found_error: true
reconnect_time: 3
development:
<<: *defaults
uri: mongodb://app:app@flame.mongohq.com:27076/app1
I had this issue a number of times in the past and would remove the shortcut syntax as a work around, but this time I'm working with a large app and it uses this syntax all over the place so I can't easily convert it.
I never get a yaml parsing error, I just get various errors later in the call stack when values the app was depending on are not found.
My Environment:
ubuntu 11.04
python 2.7.1+
ruby 1.9.2-p180 under rvm
Let me know if there is anything else you would need to figure this out.
UPDATE
When I remove the shorthand syntax on this file, I get to the next error:
p开发者_C百科sych.rb:148:in `parse': couldn't parse YAML at line 7 column 19 (Psych::SyntaxError)
https://gist.github.com/958472
The solution was to add the following to my boot.rb
require 'yaml'
YAML::ENGINE.yamler= 'syck'
PyYAML seems to parse it fine:
>>> yaml.load(s)
<<<
{'defaults': {'allow_dynamic_fields': True,
'autocreate_indexes': False,
'include_root_in_json': False,
'parameterize_keys': True,
'persist_in_safe_mode': False,
'raise_not_found_error': True},
'development': {'allow_dynamic_fields': True,
'autocreate_indexes': False,
'include_root_in_json': False,
'parameterize_keys': True,
'persist_in_safe_mode': False,
'raise_not_found_error': True,
'uri': 'mongodb://app:app@flame.mongohq.com:27076/app1'},
'e': 3}
You didn't specify where/how you were loading the yaml, but if you are having trouble parsing it you could perhaps convert your config files using PyYAML:
with open('converted.yaml', 'w') as f:
f.write(yaml.dump(yaml.load(s)))
精彩评论