fixed issue 1318, as_yaml, thanks Alan
This commit is contained in:
@@ -1 +1 @@
|
||||
Version 2.4.1-alpha.2+timestamp.2013.02.03.09.10.34
|
||||
Version 2.4.1-alpha.2+timestamp.2013.02.04.09.27.30
|
||||
|
||||
@@ -7610,6 +7610,12 @@ def index():
|
||||
d = self.as_dict(flat=True, sanitize=sanitize)
|
||||
return serializers.json(d)
|
||||
|
||||
def as_yaml(self, sanitize=True):
|
||||
if not have_serializers:
|
||||
raise ImportError("No YAML serializers available")
|
||||
d = self.as_dict(flat=True, sanitize=sanitize)
|
||||
return serializers.yaml(d)
|
||||
|
||||
def __contains__(self, tablename):
|
||||
try:
|
||||
return tablename in self.tables
|
||||
@@ -8521,6 +8527,12 @@ class Table(object):
|
||||
d = self.as_dict(flat=True, sanitize=sanitize)
|
||||
return serializers.json(d)
|
||||
|
||||
def as_yaml(self, sanitize=True):
|
||||
if not have_serializers:
|
||||
raise ImportError("No YAML serializers available")
|
||||
d = self.as_dict(flat=True, sanitize=sanitize)
|
||||
return serializers.yaml(d)
|
||||
|
||||
def with_alias(self, alias):
|
||||
return self._db._adapter.alias(self,alias)
|
||||
|
||||
@@ -9229,6 +9241,13 @@ class Field(Expression):
|
||||
d = self.as_dict(flat=True, sanitize=sanitize)
|
||||
return json(d)
|
||||
|
||||
def as_yaml(self, sanitize=True):
|
||||
if have_serializers:
|
||||
d = self.as_dict(flat=True, sanitize=sanitize)
|
||||
return serializers.yaml(d)
|
||||
else:
|
||||
raise ImportError("No YAML serializers available")
|
||||
|
||||
def __nonzero__(self):
|
||||
return True
|
||||
|
||||
|
||||
@@ -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