Skip to content

Commit

Permalink
#4481 enhance the SafeLoader with support for tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jan 23, 2025
1 parent 0dad8e4 commit 0410879
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion xpra/net/packet_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ def do_rencodeplus(value) -> tuple[SizedBuffer, int]:
def init_yaml() -> PacketEncoder:
import yaml

class TupleLoader(yaml.SafeLoader):
def construct_tuple(self, node):
# print(f"construct_tuple({loader}, {node!r})")
return tuple(yaml.Loader.construct_sequence(self, node))

TupleLoader.add_constructor("tag:yaml.org,2002:python/tuple", TupleLoader.construct_tuple)

def yaml_encode(value) -> tuple[SizedBuffer, int]:
return yaml.dump(value).encode("utf-8"), FLAGS_YAML

def yaml_decode(value) -> Any:
return yaml.full_load(value.decode("utf-8"))
return yaml.load(value.decode("utf-8"), Loader=TupleLoader)

return PacketEncoder("yaml", FLAGS_YAML, yaml.__version__, yaml_encode, yaml_decode)

Expand Down

0 comments on commit 0410879

Please sign in to comment.