How to use the azure-storage-common.azure.storage.common._error._ERROR_VALUE_SHOULD_BE_BYTES_OR_STREAM.format function in azure-storage-common

To help you get started, we’ve selected a few azure-storage-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-storage-python / azure-storage-common / azure / storage / common / _serialization.py View on Github external
def _get_data_bytes_or_stream_only(param_name, param_value):
    '''Validates the request body passed in is a stream/file-like or bytes
    object.'''
    if param_value is None:
        return b''

    if isinstance(param_value, bytes) or hasattr(param_value, 'read'):
        return param_value

    raise TypeError(_ERROR_VALUE_SHOULD_BE_BYTES_OR_STREAM.format(param_name))
github Azure / azure-storage-python / azure-storage-common / azure / storage / common / _common_conversion.py View on Github external
if isinstance(data, bytes):
        md5.update(data)
    elif hasattr(data, 'read'):
        pos = 0
        try:
            pos = data.tell()
        except:
            pass
        for chunk in iter(lambda: data.read(4096), b""):
            md5.update(chunk)
        try:
            data.seek(pos, SEEK_SET)
        except (AttributeError, IOError):
            raise ValueError(_ERROR_VALUE_SHOULD_BE_SEEKABLE_STREAM.format('data'))
    else:
        raise ValueError(_ERROR_VALUE_SHOULD_BE_BYTES_OR_STREAM.format('data'))

    return base64.b64encode(md5.digest()).decode('utf-8')

azure-storage-common

Microsoft Azure Storage Common Client Library for Python

MIT
Latest version published 5 years ago

Package Health Score

85 / 100
Full package analysis

Similar packages