Skip to content

Commit

Permalink
#4481 re-instate yaml packet encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jan 23, 2025
1 parent 5b82efb commit 2c6af8c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions xpra/net/packet_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
# all the encoders we know about:
ALL_ENCODERS: Sequence[str] = ("rencodeplus", "rencode", "bencode", "yaml", "none")

VALID_ENCODERS: Sequence[str] = ("rencodeplus", "none")
VALID_ENCODERS: Sequence[str] = ("rencodeplus", "yaml", "none")
# the encoders we may have, in the best compatibility order
TRY_ENCODERS: Sequence[str] = ("rencodeplus", "none")
TRY_ENCODERS: Sequence[str] = ("rencodeplus", "yaml", "none")
# order for performance:
PERFORMANCE_ORDER: Sequence[str] = ("rencodeplus",)
PERFORMANCE_ORDER: Sequence[str] = ("rencodeplus", "yaml", )


@dataclass
Expand All @@ -41,14 +41,26 @@ class PacketEncoder:

def init_rencodeplus() -> PacketEncoder:
from xpra.net.rencodeplus import rencodeplus # type: ignore[attr-defined]
rencodeplus_dumps = rencodeplus.dumps # @UndefinedVariable
rencodeplus_dumps = rencodeplus.dumps

def do_rencodeplus(value) -> tuple[SizedBuffer, int]:
return rencodeplus_dumps(value), FLAGS_RENCODEPLUS

return PacketEncoder("rencodeplus", FLAGS_RENCODEPLUS, rencodeplus.__version__, do_rencodeplus, rencodeplus.loads)


def init_yaml() -> PacketEncoder:
import yaml

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 PacketEncoder("yaml", FLAGS_YAML, yaml.__version__, yaml_encode, yaml_decode)


def b(value) -> bytes:
if isinstance(value, Iterable) and not isinstance(value, (str, bytes, memoryview, bytearray)):
return b" ".join(b(item) for item in value)
Expand Down

0 comments on commit 2c6af8c

Please sign in to comment.