This method can be called by methods that need a sequence. If `mutable` is true, it will also ensure that the response sequence is a standard Python list. .. versionadded:: 0.6
(self, mutable: bool = False)
| 314 | return sum(len(x) for x in self.iter_encoded()) |
| 315 | |
| 316 | def _ensure_sequence(self, mutable: bool = False) -> None: |
| 317 | """This method can be called by methods that need a sequence. If |
| 318 | `mutable` is true, it will also ensure that the response sequence |
| 319 | is a standard Python list. |
| 320 | |
| 321 | .. versionadded:: 0.6 |
| 322 | """ |
| 323 | if self.is_sequence: |
| 324 | # if we need a mutable object, we ensure it's a list. |
| 325 | if mutable and not isinstance(self.response, list): |
| 326 | self.response = list(self.response) # type: ignore |
| 327 | return |
| 328 | if self.direct_passthrough: |
| 329 | raise RuntimeError( |
| 330 | "Attempted implicit sequence conversion but the" |
| 331 | " response object is in direct passthrough mode." |
| 332 | ) |
| 333 | if not self.implicit_sequence_conversion: |
| 334 | raise RuntimeError( |
| 335 | "The response object required the iterable to be a" |
| 336 | " sequence, but the implicit conversion was disabled." |
| 337 | " Call make_sequence() yourself." |
| 338 | ) |
| 339 | self.make_sequence() |
| 340 | |
| 341 | def make_sequence(self) -> None: |
| 342 | """Converts the response iterator in a list. By default this happens |
no test coverage detected