Skip to content

Commit

Permalink
adding yaml loader to accommodate yaml 5.1 spec
Browse files Browse the repository at this point in the history
  • Loading branch information
havok2063 committed May 2, 2019
1 parent 5c32fa8 commit 253cb79
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Changed
^^^^^^^
- Setting ``verify`` default back to True
- Changed JHU db check to look for SCISERVER environment variable

- Added new get_yaml_loader function to get proper yaml Loader for 3.1/5.1 spec
- Used new yaml Loader to accommodate 5.1 spec

[0.1.1] - 2018/12/10
--------------------
Expand Down
6 changes: 3 additions & 3 deletions python/brain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import warnings
import yaml
from brain.core.exceptions import BrainError, BrainUserWarning
from brain.utils.general.general import merge
from brain.utils.general.general import merge, get_yaml_loader

# Set the Brain version
__version__ = '0.1.2dev'
Expand Down Expand Up @@ -94,10 +94,10 @@ def has_netrc(self):
def _load_defaults(self):
''' Load the Brain config yaml file '''

config = yaml.load(open(os.path.join(os.path.dirname(__file__), 'data/brain.yml')))
config = yaml.load(open(os.path.join(os.path.dirname(__file__), 'data/brain.yml')), Loader=get_yaml_loader())
user_config_path = os.path.expanduser('~/.brain/brain.yml')
if os.path.exists(user_config_path):
config = merge(yaml.load(open(user_config_path)), config)
config = merge(yaml.load(open(user_config_path), Loader=get_yaml_loader()), config)

# update any matching Config values
for key, value in config.items():
Expand Down
14 changes: 13 additions & 1 deletion python/brain/utils/general/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import datetime
import numpy as np
import json
import yaml
from pkg_resources import parse_version
from brain.core.exceptions import BrainError, BrainWarning
from hashlib import md5
from passlib.apache import HtpasswdFile
Expand All @@ -17,7 +19,8 @@

__all__ = ['getDbMachine', 'merge', 'convertIvarToErr', 'compress_data',
'uncompress_data', 'inspection_authenticate', 'validate_user',
'get_db_user', 'build_routemap', 'collaboration_authenticate']
'get_db_user', 'build_routemap', 'collaboration_authenticate',
'get_yaml_loader']


def getDbMachine():
Expand Down Expand Up @@ -429,3 +432,12 @@ def build_routemap(app):

return output


def get_yaml_loader():
''' Get a yaml loader based on the yaml package version '''

if parse_version(yaml.__version__) >= parse_version('5.1'):
loader = yaml.FullLoader
else:
loader = yaml.SafeLoader
return loader

0 comments on commit 253cb79

Please sign in to comment.