Handle the case where multiple encodings have been applied.
| 201 | |
| 202 | |
| 203 | class MultiDecoder(ContentDecoder): |
| 204 | """ |
| 205 | Handle the case where multiple encodings have been applied. |
| 206 | """ |
| 207 | |
| 208 | def __init__(self, children: typing.Sequence[ContentDecoder]) -> None: |
| 209 | """ |
| 210 | 'children' should be a sequence of decoders in the order in which |
| 211 | each was applied. |
| 212 | """ |
| 213 | # Note that we reverse the order for decoding. |
| 214 | self.children = list(reversed(children)) |
| 215 | |
| 216 | def decode(self, data: bytes) -> bytes: |
| 217 | for child in self.children: |
| 218 | data = child.decode(data) |
| 219 | return data |
| 220 | |
| 221 | def flush(self) -> bytes: |
| 222 | data = b"" |
| 223 | for child in self.children: |
| 224 | data = child.decode(data) + child.flush() |
| 225 | return data |
| 226 | |
| 227 | |
| 228 | class ByteChunker: |
no outgoing calls
no test coverage detected