From 4c8307317667d67975c967f07e2fd85ba1b0db1b Mon Sep 17 00:00:00 2001 From: ntoofu Date: Sat, 7 Oct 2017 17:54:09 +0900 Subject: [PATCH] [fix] Use yaml module with another name to avoid to change internal state of original yaml module. --- pyraml/__init__.py | 6 +++++- pyraml/parser.py | 3 ++- pyraml/raml_elements.py | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pyraml/__init__.py b/pyraml/__init__.py index 99682f0..9c8e6db 100644 --- a/pyraml/__init__.py +++ b/pyraml/__init__.py @@ -1,7 +1,7 @@ __author__ = 'ad' import mimetypes -import yaml +import imp try: from collections import OrderedDict except ImportError: @@ -11,6 +11,10 @@ from .raml_elements import ParserRamlInclude from .constants import RAML_CONTENT_MIME_TYPES + +yaml = imp.load_module('pyraml_yaml', *imp.find_module('yaml')) + + class ValidationError(Exception): def __init__(self, validation_errors): self.errors = validation_errors diff --git a/pyraml/parser.py b/pyraml/parser.py index 7889f9d..0a2588d 100644 --- a/pyraml/parser.py +++ b/pyraml/parser.py @@ -5,7 +5,7 @@ import mimetypes import os.path import codecs -import yaml +import imp import json try: from collections import OrderedDict @@ -28,6 +28,7 @@ __all__ = ["RamlException", "RamlNotFoundException", "RamlParseException", "ParseContext", "load", "parse"] +yaml = imp.load_module('pyraml_yaml', *imp.find_module('yaml')) class RamlException(Exception): diff --git a/pyraml/raml_elements.py b/pyraml/raml_elements.py index e710c53..af1cb42 100644 --- a/pyraml/raml_elements.py +++ b/pyraml/raml_elements.py @@ -1,6 +1,9 @@ __author__ = 'ad' -import yaml +import imp + + +yaml = imp.load_module('pyraml_yaml', *imp.find_module('yaml')) class ParserRamlInclude(yaml.YAMLObject):