Skip to content

Commit ab9c9e4

Browse files
committed
Avoid deprecated yaml.load() w/ PyYAML > 3.
Use yaml.full_load() instead. Fixes robotframework#3122.
1 parent 2d92ab0 commit ab9c9e4

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/robot/variables/filesetter.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ def _set(self, variables, overwrite=False):
5959

6060
class YamlImporter(object):
6161

62-
def __init__(self):
63-
if not yaml:
64-
raise DataError('Using YAML variable files requires PyYAML module '
65-
'to be installed. Typically you can install it '
66-
'by running `pip install pyyaml`.')
67-
6862
def import_variables(self, path, args=None):
6963
if args:
7064
raise DataError('YAML variable files do not accept arguments.')
@@ -74,12 +68,22 @@ def import_variables(self, path, args=None):
7468

7569
def _import(self, path):
7670
with io.open(path, encoding='UTF-8') as stream:
77-
variables = yaml.load(stream)
71+
variables = self._load_yaml(stream)
7872
if not is_dict_like(variables):
7973
raise DataError('YAML variable file must be a mapping, got %s.'
8074
% type_name(variables))
8175
return variables.items()
8276

77+
def _load_yaml(self, stream):
78+
if not yaml:
79+
raise DataError('Using YAML variable files requires PyYAML module '
80+
'to be installed. Typically you can install it '
81+
'by running `pip install pyyaml`.')
82+
if yaml.__version__.split('.')[0] == '3':
83+
return yaml.load(stream)
84+
return yaml.full_load(stream)
85+
86+
8387
def _dot_dict(self, value):
8488
if is_dict_like(value):
8589
value = DotDict((n, self._dot_dict(v)) for n, v in value.items())

0 commit comments

Comments
 (0)