Skip to content

Commit

Permalink
Merge pull request #98 from EGA-archive/feature/yaml-tuple-parsing
Browse files Browse the repository at this point in the history
Fix tuple parsing in Yaml SafeLoader
  • Loading branch information
silverdaz committed Apr 12, 2020
2 parents f629935 + fd05ec7 commit 4c923ce
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lega/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
from logging.config import fileConfig, dictConfig
from pathlib import Path
import yaml
from yaml import SafeLoader as sf


LOG_FILE = os.getenv('LEGA_LOG', None)
CONF_FILE = os.getenv('LEGA_CONF', '/etc/ega/conf.ini')
LOG = logging.getLogger(__name__)

sf.add_constructor('tag:yaml.org,2002:python/tuple', lambda self, node: tuple(sf.construct_sequence(self, node)))


def get_from_file(filepath, mode='rb', remove_after=False):
"""Return file content.
Expand Down Expand Up @@ -163,7 +167,7 @@ def _load_log(self, filename):
_logger = _here / f'loggers/{filename}.yaml'
if _logger.exists():
with open(_logger, 'r') as stream:
dictConfig(yaml.safe_load(stream))
dictConfig(yaml.load(stream, Loader=sf))
return _logger

# Otherwise trying it as a path
Expand All @@ -174,7 +178,7 @@ def _load_log(self, filename):

if _filename.suffix in ('.yaml', '.yml'):
with open(_filename, 'r') as stream:
dictConfig(yaml.safe_load(stream))
dictConfig(yaml.load(stream, Loader=sf))
return filename

if _filename.suffix in ('.ini', '.INI'):
Expand Down

0 comments on commit 4c923ce

Please sign in to comment.