MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / _thread_safe_data_view

Method _thread_safe_data_view

dwave/cloud/upload.py:345–372  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

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

Callers 1

__init__Method · 0.95

Calls 3

FileViewClass · 0.85
GettableMemoryClass · 0.85
GettableFileClass · 0.85

Tested by

no test coverage detected