-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,925 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2015 Spotify AB | ||
|
||
import os | ||
import sys | ||
|
||
import six | ||
|
||
from .errors import LoadRAMLError | ||
from .loader import RAMLLoader | ||
|
||
if sys.version_info[0] == 2: | ||
from io import open | ||
|
||
|
||
def load_file(raml_file): | ||
try: | ||
with _get_raml_object(raml_file) as raml: | ||
return RAMLLoader().load(raml) | ||
except IOError as e: | ||
raise LoadRAMLError(e) | ||
|
||
|
||
def load_string(raml_str): | ||
return RAMLLoader().load(raml_str) | ||
|
||
|
||
def _get_raml_object(raml_file): | ||
""" | ||
Returns a file object. | ||
""" | ||
if raml_file is None: | ||
msg = "RAML file can not be 'None'." | ||
raise LoadRAMLError(msg) | ||
|
||
if isinstance(raml_file, six.text_type) or isinstance( | ||
raml_file, bytes): | ||
return open(os.path.abspath(raml_file), 'r', encoding="UTF-8") | ||
elif hasattr(raml_file, 'read'): | ||
return raml_file | ||
else: | ||
msg = ("Can not load object '{0}': Not a basestring type or " | ||
"file object".format(raml_file)) | ||
raise LoadRAMLError(msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.