Skip to content

Commit f012931

Browse files
authored
Fix yaml loader (#963)
1 parent 1105f25 commit f012931

7 files changed

Lines changed: 15 additions & 15 deletions

File tree

montreal_forced_aligner/abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ def __init__(
10771077

10781078
def load_mapping(self) -> None:
10791079
with mfa_open(self.phone_mapping_path, "r") as f:
1080-
self.phone_remapping = yaml.load(f, Loader=yaml.Loader)
1080+
self.phone_remapping = yaml.load(f, Loader=yaml.SafeLoader)
10811081
for key, values in self.phone_remapping.items():
10821082
if not isinstance(values, list):
10831083
self.phone_remapping[key] = [values]

montreal_forced_aligner/command_line/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def validate_model_arg(name: str, model_type: str) -> MfaModel:
266266
raise click.BadParameter(str(FileArgumentNotFoundError(name)))
267267
if model_type == "dictionary" and name.suffix.lower() == ".yaml":
268268
with mfa_open(name, "r") as f:
269-
data = yaml.load(f, Loader=yaml.Loader)
269+
data = yaml.load(f, Loader=yaml.SafeLoader)
270270
paths = sorted(set(data.values()))
271271
for path in paths:
272272
validate_model_arg(path, "dictionary")

montreal_forced_aligner/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def load_command_history() -> List[Dict[str, Any]]:
105105
history = []
106106
if path.exists():
107107
with mfa_open(path, "r") as f:
108-
history = yaml.load(f, Loader=yaml.Loader)
108+
history = yaml.load(f, Loader=yaml.SafeLoader)
109109
if not history:
110110
history = []
111111
history = [h for h in history if h["command"]]
@@ -267,7 +267,7 @@ def save(self) -> None:
267267
def load(self) -> None:
268268
"""Load MFA configuration"""
269269
with mfa_open(self.config_path, "r") as f:
270-
data = yaml.load(f, Loader=yaml.Loader)
270+
data = yaml.load(f, Loader=yaml.SafeLoader)
271271
for k, v in data.items():
272272
if any(k.endswith(x) for x in ["_path", "_directory", "_dir"]):
273273
data[k] = pathlib.Path(v)
@@ -288,7 +288,7 @@ def load_configuration():
288288
if not config_path.exists():
289289
return
290290
with mfa_open(config_path, "r") as f:
291-
data = yaml.load(f, Loader=yaml.Loader)
291+
data = yaml.load(f, Loader=yaml.SafeLoader)
292292
profiles = data.pop("profiles", {})
293293
if CURRENT_PROFILE_NAME == "global":
294294
update_configuration(data)

montreal_forced_aligner/corpus/remapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def setup(self) -> None:
5858

5959
def load_mapping(self) -> None:
6060
with mfa_open(self.phone_mapping_path, "r") as f:
61-
data = yaml.load(f, Loader=yaml.Loader)
61+
data = yaml.load(f, Loader=yaml.SafeLoader)
6262
for key, value in data.items():
6363
if isinstance(value, list):
6464
value = value[0]

montreal_forced_aligner/dictionary/multispeaker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def load_phone_groups(self) -> None:
166166
"""
167167
if self.phone_groups_path is not None and self.phone_groups_path.exists():
168168
with mfa_open(self.phone_groups_path) as f:
169-
self._phone_groups = yaml.load(f, Loader=yaml.Loader)
169+
self._phone_groups = yaml.load(f, Loader=yaml.SafeLoader)
170170
if isinstance(self._phone_groups, list):
171171
self._phone_groups = {k: v for k, v in enumerate(self._phone_groups)}
172172
for k, v in self._phone_groups.items():
@@ -214,7 +214,7 @@ def load_phone_topologies(self) -> None:
214214
with mfa_open(self.topology_path) as f:
215215
self._topologies = {
216216
k: v
217-
for k, v in yaml.load(f, Loader=yaml.Loader).items()
217+
for k, v in yaml.load(f, Loader=yaml.SafeLoader).items()
218218
if k in self.non_silence_phones
219219
}
220220
found_phones = set(self._topologies.keys())
@@ -932,7 +932,7 @@ def load_phonological_rules(self) -> None:
932932
if not self.rules_path or not self.rules_path.exists():
933933
return
934934
with mfa_open(self.rules_path) as f:
935-
rule_data = yaml.load(f, Loader=yaml.Loader)
935+
rule_data = yaml.load(f, Loader=yaml.SafeLoader)
936936
with self.session() as session:
937937
if session.query(PhonologicalRule).first() is not None:
938938
return

montreal_forced_aligner/helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def load_configuration(config_path: typing.Union[str, Path]) -> typing.Dict[str,
126126
config_path = Path(config_path)
127127
with mfa_open(config_path, "r") as f:
128128
if config_path.suffix == ".yaml":
129-
data = yaml.load(f, Loader=yaml.Loader)
129+
data = yaml.load(f, Loader=yaml.SafeLoader)
130130
elif config_path.suffix == ".json":
131131
data = json.load(f)
132132
if not data:
@@ -544,7 +544,7 @@ def default(self, o: typing.Any) -> typing.Any:
544544

545545
def load_evaluation_mapping(custom_mapping_path):
546546
with mfa_open(custom_mapping_path, "r") as f:
547-
mapping = yaml.load(f, Loader=yaml.Loader)
547+
mapping = yaml.load(f, Loader=yaml.SafeLoader)
548548
for k, v in mapping.items():
549549
if isinstance(v, str):
550550
mapping[k] = {v}

montreal_forced_aligner/models/classes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ def meta(self) -> dict:
666666
file_format = "yaml"
667667
with mfa_open(meta_path, "r") as f:
668668
if file_format == "yaml":
669-
self._meta = yaml.load(f, Loader=yaml.Loader)
669+
self._meta = yaml.load(f, Loader=yaml.SafeLoader)
670670
else:
671671
self._meta = json.load(f)
672672
return self._meta
@@ -1159,7 +1159,7 @@ def meta(self) -> dict:
11591159
if format == "json":
11601160
self._meta = json.load(f)
11611161
else:
1162-
self._meta = yaml.load(f, Loader=yaml.Loader)
1162+
self._meta = yaml.load(f, Loader=yaml.SafeLoader)
11631163
self._meta["phones"] = set(self._meta.get("phones", []))
11641164
self._meta["graphemes"] = set(self._meta.get("graphemes", []))
11651165
self._meta["evaluation"] = self._meta.get("evaluation", [])
@@ -1329,7 +1329,7 @@ def meta(self) -> dict:
13291329
if format == "json":
13301330
self._meta = json.load(f)
13311331
else:
1332-
self._meta = yaml.load(f, Loader=yaml.Loader)
1332+
self._meta = yaml.load(f, Loader=yaml.SafeLoader)
13331333
self._meta["evaluation"] = self._meta.get("evaluation", [])
13341334
self._meta["training"] = self._meta.get("training", [])
13351335
return self._meta
@@ -1751,7 +1751,7 @@ def load_dictionary_paths(
17511751
mapping = {}
17521752
if self.is_multiple:
17531753
with mfa_open(self.path, "r") as f:
1754-
data = yaml.load(f, Loader=yaml.Loader)
1754+
data = yaml.load(f, Loader=yaml.SafeLoader)
17551755
for speaker, path in data.items():
17561756
if path not in mapping:
17571757
if path != "nonnative":

0 commit comments

Comments
 (0)