# HG changeset patch # User RhodeCode Admin # Date 2023-05-16 09:23:48 # Node ID 0553d498602a42f2477c2a17b1373d193323333d # Parent 6e658db3f76ac467a10e3ca930def66d5d62daa0 core: make binary envelope behave like bytes type object for serialization and internal API usage. We would need to unpack it otherwise manually diff --git a/vcsserver/base.py b/vcsserver/base.py --- a/vcsserver/base.py +++ b/vcsserver/base.py @@ -140,3 +140,39 @@ class BinaryEnvelope(object): def __init__(self, value, bin_type=True): self.value = value self.bin_type = bin_type + + def __len__(self): + return len(self.value) + + def __getitem__(self, index): + return self.value[index] + + def __iter__(self): + return iter(self.value) + + def __str__(self): + return str(self.value) + + def __repr__(self): + return repr(self.value) + + def __eq__(self, other): + if isinstance(other, BinaryEnvelope): + return self.value == other.value + return False + + def __ne__(self, other): + return not self.__eq__(other) + + def __add__(self, other): + if isinstance(other, BinaryEnvelope): + return BinaryEnvelope(self.value + other.value) + raise TypeError(f"unsupported operand type(s) for +: 'BinaryEnvelope' and '{type(other)}'") + + def __radd__(self, other): + if isinstance(other, BinaryEnvelope): + return BinaryEnvelope(other.value + self.value) + raise TypeError(f"unsupported operand type(s) for +: '{type(other)}' and 'BinaryEnvelope'") + + +