(self, data)
| 343 | """ |
| 344 | |
| 345 | def _thread_safe_data_view(self, data): |
| 346 | # convenience string handler |
| 347 | if isinstance(data, str): |
| 348 | data = data.encode('ascii') |
| 349 | |
| 350 | if isinstance(data, (bytes, bytearray)): |
| 351 | # note: `BytesIO` (in py3.5+) will use buffer protocol (reuse data |
| 352 | # buffer) only for `bytes` objects, and make a copy otherwise! |
| 353 | |
| 354 | # use non-locking memory view over data buffer |
| 355 | return FileView(GettableMemory(data)) |
| 356 | |
| 357 | # use locking file view if possible |
| 358 | try: |
| 359 | return FileView(GettableFile(data, strict=True)) |
| 360 | except TypeError: |
| 361 | logger.debug("data does not conform to strict file-like requirements") |
| 362 | |
| 363 | # TODO: use stream view if possible |
| 364 | |
| 365 | # fallback to a less strict check of file-like's capabilities, |
| 366 | # accepting we might fail later |
| 367 | try: |
| 368 | return FileView(GettableFile(data, strict=False)) |
| 369 | except TypeError: |
| 370 | logger.debug("data does not conform to loose file-like requirements") |
| 371 | |
| 372 | raise TypeError("bytes/str/file-like data required") |
| 373 | |
| 374 | def __init__(self, data, chunk_size): |
| 375 | self.data = data |
no test coverage detected