Skip to content

Commit

Permalink
util: Use libyaml if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
avdgrinten committed Nov 4, 2024
1 parent a181735 commit 2a5905c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion y4/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ def main():
ctx.bind(tag, binding)
else:
out = ctx.evaluate(root)
sys.stdout.write(yaml.dump(out, sort_keys=False, explicit_start=True))
sys.stdout.write(
yaml.dump(
out,
sort_keys=False,
explicit_start=True,
Dumper=util.YamlDumper,
)
)


if __name__ == "__main__":
Expand Down
10 changes: 9 additions & 1 deletion y4/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
YAML_MAP_TAG = "tag:yaml.org,2002:map"
YAML_STR_TAG = "tag:yaml.org,2002:str"

YamlLoader = yaml.SafeLoader
try:
YamlLoader = yaml.CSafeLoader
except AttributeError:
YamlLoader = yaml.SafeLoader

try:
YamlDumper = yaml.CSafeDumper
except AttributeError:
YamlDumper = yaml.SafeDumper


class InternalNode(yaml.Node):
Expand Down

0 comments on commit 2a5905c

Please sign in to comment.