diff options
| author | Jannis Leidel <jannis@leidel.info> | 2012-02-09 18:56:58 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2012-02-09 18:56:58 +0000 |
| commit | 49288f838809d797fa7b8b2e6a2cb2f65d6cf8bd (patch) | |
| tree | 819f8adcbbd71685624d8fc769bbe8b3fe6eed5f /django/core | |
| parent | 75a9c8a5ef6408cd51fd75fc8aefb2e812e353a1 (diff) | |
Fixed #11970 -- Wrapped the exception happening during deserialization in DeserializationError exceptions. Thanks, Claude Paroz.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17469 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/serializers/json.py | 11 | ||||
| -rw-r--r-- | django/core/serializers/pyyaml.py | 10 |
2 files changed, 16 insertions, 5 deletions
diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py index 7b570f36d8..ce7cdb3179 100644 --- a/django/core/serializers/json.py +++ b/django/core/serializers/json.py @@ -6,6 +6,7 @@ import datetime import decimal from StringIO import StringIO +from django.core.serializers.base import DeserializationError from django.core.serializers.python import Serializer as PythonSerializer from django.core.serializers.python import Deserializer as PythonDeserializer from django.utils import simplejson @@ -27,6 +28,7 @@ class Serializer(PythonSerializer): if callable(getattr(self.stream, 'getvalue', None)): return self.stream.getvalue() + def Deserializer(stream_or_string, **options): """ Deserialize a stream or string of JSON data. @@ -35,8 +37,13 @@ def Deserializer(stream_or_string, **options): stream = StringIO(stream_or_string) else: stream = stream_or_string - for obj in PythonDeserializer(simplejson.load(stream), **options): - yield obj + try: + for obj in PythonDeserializer(simplejson.load(stream), **options): + yield obj + except Exception, e: + # Map to deserializer error + raise DeserializationError(e) + class DjangoJSONEncoder(simplejson.JSONEncoder): """ diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py index a9f4575823..1f4f967ebb 100644 --- a/django/core/serializers/pyyaml.py +++ b/django/core/serializers/pyyaml.py @@ -9,6 +9,7 @@ import decimal import yaml from django.db import models +from django.core.serializers.base import DeserializationError from django.core.serializers.python import Serializer as PythonSerializer from django.core.serializers.python import Deserializer as PythonDeserializer @@ -51,6 +52,9 @@ def Deserializer(stream_or_string, **options): stream = StringIO(stream_or_string) else: stream = stream_or_string - for obj in PythonDeserializer(yaml.safe_load(stream), **options): - yield obj - + try: + for obj in PythonDeserializer(yaml.safe_load(stream), **options): + yield obj + except Exception, e: + # Map to deserializer error + raise DeserializationError(e) |
