fixed issue 1318, as_yaml, thanks Alan
This commit is contained in:
@@ -19,6 +19,11 @@ except ImportError:
|
||||
except:
|
||||
import contrib.simplejson as json_parser # fallback to pure-Python module
|
||||
|
||||
have_yaml = True
|
||||
try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
have_yaml = False
|
||||
|
||||
def loads_json(o):
|
||||
# deserialize a json string
|
||||
@@ -119,3 +124,14 @@ def rss(feed):
|
||||
pubDate=entry.get('created_on', now)
|
||||
) for entry in feed.get('entries', [])])
|
||||
return rss.to_xml(encoding='utf-8')
|
||||
|
||||
def yaml(data):
|
||||
if have_yaml:
|
||||
return yaml.dump(data)
|
||||
else: raise ImportError("No YAML serializer available")
|
||||
|
||||
def loads_yaml(data):
|
||||
if have_yaml:
|
||||
return yaml.load(data)
|
||||
else: raise ImportError("No YAML serializer available")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user