summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-01-05 18:01:16 +0100
committerClaude Paroz <claude@2xlibre.net>2013-01-05 18:04:00 +0100
commita843539af2f557e9bdc71b9b5ef66eabe0e39e3c (patch)
tree61f966687243ac1610023310c974f766a7b23e48
parentc8eff0dbcb0936aac2748a7a896d08f34b54c50f (diff)
Fixed #12914 -- Use yaml faster C implementation when available
Thanks Beuc for the report and the initial patch.
-rw-r--r--django/core/serializers/pyyaml.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py
index 4c11626bad..27239e0445 100644
--- a/django/core/serializers/pyyaml.py
+++ b/django/core/serializers/pyyaml.py
@@ -14,8 +14,15 @@ from django.core.serializers.python import Serializer as PythonSerializer
from django.core.serializers.python import Deserializer as PythonDeserializer
from django.utils import six
+# Use the C (faster) implementation if possible
+try:
+ 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('tag:yaml.org,2002:str', str(data))
@@ -58,7 +65,7 @@ def Deserializer(stream_or_string, **options):
else:
stream = stream_or_string
try:
- for obj in PythonDeserializer(yaml.safe_load(stream), **options):
+ for obj in PythonDeserializer(yaml.load(stream, Loader=SafeLoader), **options):
yield obj
except GeneratorExit:
raise