##// END OF EJS Templates
core: make binary envelope behave like bytes type object for serialization and internal API usage....
super-admin -
r1094:0553d498 python3
parent child Browse files
Show More
@@ -140,3 +140,39 b' class BinaryEnvelope(object):'
140 140 def __init__(self, value, bin_type=True):
141 141 self.value = value
142 142 self.bin_type = bin_type
143
144 def __len__(self):
145 return len(self.value)
146
147 def __getitem__(self, index):
148 return self.value[index]
149
150 def __iter__(self):
151 return iter(self.value)
152
153 def __str__(self):
154 return str(self.value)
155
156 def __repr__(self):
157 return repr(self.value)
158
159 def __eq__(self, other):
160 if isinstance(other, BinaryEnvelope):
161 return self.value == other.value
162 return False
163
164 def __ne__(self, other):
165 return not self.__eq__(other)
166
167 def __add__(self, other):
168 if isinstance(other, BinaryEnvelope):
169 return BinaryEnvelope(self.value + other.value)
170 raise TypeError(f"unsupported operand type(s) for +: 'BinaryEnvelope' and '{type(other)}'")
171
172 def __radd__(self, other):
173 if isinstance(other, BinaryEnvelope):
174 return BinaryEnvelope(other.value + self.value)
175 raise TypeError(f"unsupported operand type(s) for +: '{type(other)}' and 'BinaryEnvelope'")
176
177
178
General Comments 0
You need to be logged in to leave comments. Login now