Commits

Jesper Nøhr committed 79f7f6d

yaml emitter is now optional (pyYAML is not in stdlib), so only registering emitter if yaml import was ok, fixes #24, thanks mmarshall

  • Participants
  • Parent commits 7657cd6

Comments (0)

Files changed (1)

File piston/emitters.py

-import types, decimal, yaml, types, re, inspect
+import types, decimal, types, re, inspect
+
+try:
+    # yaml isn't standard with python.  It shouldn't be required if it
+    # isn't used.
+    import yaml
+except ImportError:
+    yaml = None
 
 from django.db.models.query import QuerySet
 from django.db.models import Model, permalink
     def render(self, request):
         return yaml.safe_dump(self.construct())
 
-Emitter.register('yaml', YAMLEmitter, 'application/x-yaml; charset=utf-8')
+if yaml:  # Only register yaml if it was import successfully.
+    Emitter.register('yaml', YAMLEmitter, 'application/x-yaml; charset=utf-8')
 
 class PickleEmitter(Emitter):
     """