Browse files

Fixed #12914 -- Use yaml faster C implementation when available

Thanks Beuc for the report and the initial patch.
  • Loading branch information...
claudep committed Jan 5, 2013
1 parent c8eff0d commit a843539af2f557e9bdc71b9b5ef66eabe0e39e3c
Showing with 9 additions and 2 deletions.
  1. +9 −2 django/core/serializers/
@@ -14,8 +14,15 @@
from django.core.serializers.python import Deserializer as PythonDeserializer
from django.utils import six
+# Use the C (faster) implementation if possible
+ from yaml import CSafeLoader as SafeLoader
+ from yaml import CSafeDumper as SafeDumper
+except ImportError:
+ from yaml import SafeLoader, SafeDumper
-class DjangoSafeDumper(yaml.SafeDumper):
+class DjangoSafeDumper(SafeDumper):
def represent_decimal(self, data):
return self.represent_scalar(',2002:str', str(data))
@@ -58,7 +65,7 @@ def Deserializer(stream_or_string, **options):
stream = stream_or_string
- for obj in PythonDeserializer(yaml.safe_load(stream), **options):
+ for obj in PythonDeserializer(yaml.load(stream, Loader=SafeLoader), **options):
yield obj
except GeneratorExit:

0 comments on commit a843539

Please sign in to comment.