Ticket #7676: threadsafe_serializers-same_public_api.diff
File threadsafe_serializers-same_public_api.diff, 3.0 KB (added by , 16 years ago) |
---|
-
django/core/serializers/__init__.py
35 35 _serializers = {} 36 36 37 37 def register_serializer(format, serializer_module): 38 """Register a new serializer by passing in a module name. """39 module = __import__(serializer_module, {}, {}, [''])40 _ serializers[format] = module38 """Register a new serializer by passing in a module name. 39 Not thread-safe.""" 40 _register_serializer(_serializers, format, serializer_module) 41 41 42 42 def unregister_serializer(format): 43 """Unregister a given serializer """43 """Unregister a given serializer. Not thread-safe.""" 44 44 del _serializers[format] 45 45 46 46 def get_serializer(format): 47 """Thread-safe.""" 47 48 if not _serializers: 48 49 _load_serializers() 49 50 return _serializers[format].Serializer 50 51 51 52 def get_serializer_formats(): 53 """Thread-safe.""" 52 54 if not _serializers: 53 55 _load_serializers() 54 56 return _serializers.keys() 55 57 56 58 def get_public_serializer_formats(): 59 """Thread-safe.""" 57 60 if not _serializers: 58 61 _load_serializers() 59 62 return [k for k, v in _serializers.iteritems() if not v.Serializer.internal_use_only] 60 63 61 64 def get_deserializer(format): 65 """Thread-safe.""" 62 66 if not _serializers: 63 67 _load_serializers() 64 68 return _serializers[format].Deserializer … … 67 71 """ 68 72 Serialize a queryset (or any iterator that returns database objects) using 69 73 a certain serializer. 74 Thread-safe. 70 75 """ 71 76 s = get_serializer(format)() 72 77 s.serialize(queryset, **options) … … 78 83 m2m_relation_dict)``, where ``obj`` is a instantiated -- but *unsaved* -- 79 84 object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name : 80 85 list_of_related_objects}``. 86 Thread-safe. 81 87 """ 82 88 d = get_deserializer(format) 83 89 return d(stream_or_string) … … 87 93 Register built-in and settings-defined serializers. This is done lazily so 88 94 that user code has a chance to (e.g.) set up custom settings without 89 95 needing to be careful of import order. 96 Thread-safe. 90 97 """ 98 global _serializers 99 serializers = {} 91 100 for format in BUILTIN_SERIALIZERS: 92 register_serializer(format, BUILTIN_SERIALIZERS[format])101 _register_serializer(serializers, format, BUILTIN_SERIALIZERS[format]) 93 102 if hasattr(settings, "SERIALIZATION_MODULES"): 94 103 for format in settings.SERIALIZATION_MODULES: 95 register_serializer(format, settings.SERIALIZATION_MODULES[format]) 104 _register_serializer(serializers, format, 105 settings.SERIALIZATION_MODULES[format]) 106 _serializers = serializers 107 108 def _register_serializer(serializers, format, serializer_module): 109 """Register a new serializer by passing in a module name.""" 110 module = __import__(serializer_module, {}, {}, ['']) 111 serializers[format] = module