Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #6110 -- Mark the python format serializer as for internal use …

…only. Thanks, empty.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6922 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fc413b8f611677e51ea8c24e3b56a3716652a619 1 parent 6754be4
Malcolm Tredinnick authored December 17, 2007
8  django/core/management/commands/dumpdata.py
... ...
@@ -1,11 +1,13 @@
1 1
 from django.core.management.base import BaseCommand, CommandError
  2
+from django.core import serializers
2 3
 
3 4
 from optparse import make_option
4 5
 
5 6
 class Command(BaseCommand):
  7
+    serializer_formats = serializers.get_public_serializer_formats()
6 8
     option_list = BaseCommand.option_list + (
7 9
         make_option('--format', default='json', dest='format',
8  
-            help='Specifies the output serialization format for fixtures'),
  10
+            help='Specifies the output serialization format for fixtures.  Formats available: %s' % serializer_formats),
9 11
         make_option('--indent', default=None, dest='indent', type='int',
10 12
             help='Specifies the indent level to use when pretty-printing output'),
11 13
     )
@@ -14,7 +16,6 @@ class Command(BaseCommand):
14 16
 
15 17
     def handle(self, *app_labels, **options):
16 18
         from django.db.models import get_app, get_apps, get_models
17  
-        from django.core import serializers
18 19
 
19 20
         format = options.get('format', 'json')
20 21
         indent = options.get('indent', None)
@@ -26,6 +27,9 @@ def handle(self, *app_labels, **options):
26 27
 
27 28
         # Check that the serialization format exists; this is a shortcut to
28 29
         # avoid collating all the objects and _then_ failing.
  30
+        if format not in self.serializer_formats:
  31
+            raise CommandError("Unknown serialization format: %s" % format)
  32
+
29 33
         try:
30 34
             serializers.get_serializer(format)
31 35
         except KeyError:
4  django/core/management/commands/loaddata.py
@@ -50,10 +50,10 @@ def handle(self, *fixture_labels, **options):
50 50
             parts = fixture_label.split('.')
51 51
             if len(parts) == 1:
52 52
                 fixture_name = fixture_label
53  
-                formats = serializers.get_serializer_formats()
  53
+                formats = serializers.get_public_serializer_formats()
54 54
             else:
55 55
                 fixture_name, format = '.'.join(parts[:-1]), parts[-1]
56  
-                if format in serializers.get_serializer_formats():
  56
+                if format in serializers.get_public_serializer_formats():
57 57
                     formats = [format]
58 58
                 else:
59 59
                     formats = []
5  django/core/serializers/__init__.py
@@ -53,6 +53,11 @@ def get_serializer_formats():
53 53
         _load_serializers()
54 54
     return _serializers.keys()
55 55
 
  56
+def get_public_serializer_formats():
  57
+    if not _serializers:
  58
+        _load_serializers()
  59
+    return [k for k, v in _serializers.iteritems() if not v.Serializer.internal_use_only]
  60
+
56 61
 def get_deserializer(format):
57 62
     if not _serializers:
58 63
         _load_serializers()
4  django/core/serializers/base.py
@@ -22,6 +22,10 @@ class Serializer(object):
22 22
     Abstract serializer base class.
23 23
     """
24 24
 
  25
+    # Indicates if the implemented serializer is only available for 
  26
+    # internal Django use.
  27
+    internal_use_only = False
  28
+    
25 29
     def serialize(self, queryset, **options):
26 30
         """
27 31
         Serialize a queryset.
2  django/core/serializers/json.py
@@ -20,6 +20,8 @@ class Serializer(PythonSerializer):
20 20
     """
21 21
     Convert a queryset to JSON.
22 22
     """
  23
+    internal_use_only = False
  24
+    
23 25
     def end_serialization(self):
24 26
         self.options.pop('stream', None)
25 27
         self.options.pop('fields', None)
4  django/core/serializers/python.py
@@ -13,7 +13,9 @@ class Serializer(base.Serializer):
13 13
     """
14 14
     Serializes a QuerySet to basic Python objects.
15 15
     """
16  
-
  16
+    
  17
+    internal_use_only = True
  18
+    
17 19
     def start_serialization(self):
18 20
         self._current = None
19 21
         self.objects = []
2  django/core/serializers/pyyaml.py
@@ -19,6 +19,8 @@ class Serializer(PythonSerializer):
19 19
     Convert a queryset to YAML.
20 20
     """
21 21
     
  22
+    internal_use_only = False
  23
+    
22 24
     def handle_field(self, obj, field):
23 25
         # A nasty special case: base YAML doesn't support serialization of time
24 26
         # types (as opposed to dates or datetimes, which it does support). Since

0 notes on commit fc413b8

Please sign in to comment.
Something went wrong with that request. Please try again.