diff --git a/rest_framework_swagger/introspectors.py b/rest_framework_swagger/introspectors.py index fb84598a..9529362c 100644 --- a/rest_framework_swagger/introspectors.py +++ b/rest_framework_swagger/introspectors.py @@ -29,7 +29,11 @@ import django_filters except ImportError: django_filters = None - +try: + # try and use C if available, since it's faster + from yaml import CSafeLoader as SafeLoader +except ImportError: + from yaml import SafeLoader def get_view_description(view_cls, html=False, docstring=None): if docstring is not None: @@ -944,7 +948,7 @@ def load_obj_from_docstring(self, docstring): yaml_string = "\n".join(split_lines[cut_from:]) yaml_string = formatting.dedent(yaml_string) try: - return yaml.load(yaml_string) + return yaml.load(yaml_string, Loader=SafeLoader) except yaml.YAMLError as e: self.yaml_error = e return None