Automated merge with ssh://hg.scrapy.org/scrapy

This commit is contained in:
Daniel Grana 2009-08-11 15:54:22 -03:00
commit 9b620652fc
2 changed files with 14 additions and 7 deletions

View File

@ -4,9 +4,12 @@ class SerializationTest(unittest.TestCase):
def setUp(self):
try:
import simplejson
except ImportError, e:
raise unittest.SkipTest(e)
import json
except ImportError:
try:
import simplejson
except ImportError, e:
raise unittest.SkipTest(e)
def test_string_serialization(self):
"""Test simple string serialization"""

View File

@ -11,9 +11,13 @@ import decimal
import cPickle as pickle
import pprint
import simplejson
try:
import json
except ImportError:
import simplejson as json
class ScrapyJSONEncoder(simplejson.JSONEncoder):
class ScrapyJSONEncoder(json.JSONEncoder):
"""
JSONEncoder subclass that knows how to encode date/time and decimal types.
"""
@ -34,13 +38,13 @@ class ScrapyJSONEncoder(simplejson.JSONEncoder):
return super(ScrapyJSONEncoder, self).default(o)
serialize_funcs = {
'json': lambda obj: simplejson.dumps(obj, cls=ScrapyJSONEncoder),
'json': lambda obj: json.dumps(obj, cls=ScrapyJSONEncoder),
'pprint': lambda obj: pprint.pformat(obj),
'pickle': lambda obj: pickle.dumps(obj),
}
unserialize_funcs = {
'json': lambda text: simplejson.loads(text),
'json': lambda text: json.loads(text),
'pprint': lambda text: eval(text),
'pickle': lambda text: pickle.loads(text),
}