Changed bytearray to a union

This commit is contained in:
dherrada 2020-07-02 12:39:17 -04:00
parent ffc5f0c338
commit ac113fdc81
7 changed files with 16 additions and 16 deletions

View File

@ -12,7 +12,7 @@
//| class AES:
//| """Encrypt and decrypt AES streams"""
//|
//| def __init__(self, key: bytearray, mode: int=0, iv: bytearray=None, segment_size: int=8) -> AES:
//| def __init__(self, key: Union[bytes, bytearray, memoryview], mode: int=0, iv: Union[bytes, bytearray, memoryview]=None, segment_size: int=8) -> AES:
//| """Create a new AES state with the given key.
//|
//| :param bytearray key: A 16-, 24-, or 32-byte key
@ -152,7 +152,7 @@ STATIC void validate_length(aesio_aes_obj_t *self, size_t src_length,
}
}
//| def encrypt_into(src: bytes, dest: bytearray) -> None:
//| def encrypt_into(src: Union[bytes, bytearray, memoryview], dest: Union[bytes, bytearray, memoryview]) -> None:
//| """Encrypt the buffer from ``src`` into ``dest``.
//|
//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the
@ -183,7 +183,7 @@ STATIC mp_obj_t aesio_aes_encrypt_into(mp_obj_t aesio_obj, mp_obj_t src,
STATIC MP_DEFINE_CONST_FUN_OBJ_3(aesio_aes_encrypt_into_obj,
aesio_aes_encrypt_into);
//| def decrypt_into(src: bytes, dest: bytearray) -> None:
//| def decrypt_into(src: Union[bytes, bytearray, memoryview], dest: Union[bytes, bytearray, memoryview]) -> None:
//|
//| """Decrypt the buffer from ``src`` into ``dest``.
//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the

View File

@ -168,7 +168,7 @@ STATIC mp_obj_t audiobusio_pdmin_obj___exit__(size_t n_args, const mp_obj_t *arg
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_pdmin___exit___obj, 4, 4, audiobusio_pdmin_obj___exit__);
//| def record(self, destination: bytearray, destination_length: int) -> None:
//| def record(self, destination: Union[bytes, bytearray, memoryview], destination_length: int) -> None:
//| """Records destination_length bytes of samples to destination. This is
//| blocking.
//|

View File

@ -40,7 +40,7 @@
//| be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating
//| an internal buffer."""
//|
//| def __init__(self, file: typing.BinaryIO, buffer: bytearray):
//| def __init__(self, file: typing.BinaryIO, buffer: Union[bytes, bytearray, memoryview]):
//| """Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
//|
//| :param typing.BinaryIO file: Already opened wave file

View File

@ -37,7 +37,7 @@
//| class MP3:
//| """Load a mp3 file for audio playback"""
//|
//| def __init__(self, file: typing.BinaryIO, buffer: bytearray):
//| def __init__(self, file: typing.BinaryIO, buffer: Union[bytes, bytearray, memoryview]):
//|
//| """Load a .mp3 file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
//|

View File

@ -165,7 +165,7 @@ STATIC mp_obj_t bitbangio_i2c_obj_unlock(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_unlock_obj, bitbangio_i2c_obj_unlock);
//| def readfrom_into(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None) -> None:
//| def readfrom_into(self, address: int, buffer: Union[bytes, bytearray, memoryview], *, start: int = 0, end: int = None) -> None:
//| """Read into ``buffer`` from the device selected by ``address``.
//| The number of bytes read will be the length of ``buffer``.
//| At least one byte must be read.
@ -217,7 +217,7 @@ STATIC mp_obj_t bitbangio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_a
}
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 3, bitbangio_i2c_readfrom_into);
//| def writeto(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None, stop: bool = True) -> None:
//| def writeto(self, address: int, buffer: Union[bytes, bytearray, memoryview], *, start: int = 0, end: int = None, stop: bool = True) -> None:
//| """Write the bytes from ``buffer`` to the device selected by ``address`` and then transmits a
//| stop bit. Use `writeto_then_readfrom` when needing a write, no stop and repeated start
//| before a read.
@ -277,7 +277,7 @@ STATIC mp_obj_t bitbangio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, m
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_writeto);
//| def writeto_then_readfrom(self, address: int, out_buffer: bytearray, in_buffer: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None:
//| def writeto_then_readfrom(self, address: int, out_buffer: Union[bytes, bytearray, memoryview], in_buffer: Union[bytes, bytearray, memoryview], *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None:
//| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
//| ``in_buffer`` can be the same buffer because they are used sequentially.

View File

@ -200,7 +200,7 @@ STATIC mp_obj_t bitbangio_spi_obj_unlock(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_unlock_obj, bitbangio_spi_obj_unlock);
//| def write(self, buf: bytes) -> None:
//| def write(self, buf: Union[bytes, bytearray, memoryview]) -> None:
//| """Write the data contained in ``buf``. Requires the SPI being locked.
//| If the buffer is empty, nothing happens."""
//| ...
@ -224,7 +224,7 @@ STATIC mp_obj_t bitbangio_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) {
MP_DEFINE_CONST_FUN_OBJ_2(bitbangio_spi_write_obj, bitbangio_spi_write);
//| def readinto(self, buf: bytearray) -> None:
//| def readinto(self, buf: Union[bytes, bytearray, memoryview]) -> None:
//| """Read into the buffer specified by ``buf`` while writing zeroes.
//| Requires the SPI being locked.
//| If the number of bytes to read is 0, nothing happens."""
@ -248,7 +248,7 @@ STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_spi_readinto_obj, 2, 2, bitbangio_spi_readinto);
//| def write_readinto(self, buffer_out: bytearray, buffer_in: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None:
//| def write_readinto(self, buffer_out: Union[bytes, bytearray, memoryview], buffer_in: Union[bytes, bytearray, memoryview], *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None:
//| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
//| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
//| must be equal.

View File

@ -164,7 +164,7 @@ STATIC mp_obj_t busio_i2c_obj_try_lock(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_try_lock_obj, busio_i2c_obj_try_lock);
//| def unlock(self, ) -> none:
//| def unlock(self, ) -> None:
//| """Releases the I2C lock."""
//| ...
//|
@ -176,7 +176,7 @@ STATIC mp_obj_t busio_i2c_obj_unlock(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock);
//| def readfrom_into(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None) -> None:
//| def readfrom_into(self, address: int, buffer: Union[bytes, bytearray, memoryview], *, start: int = 0, end: int = None) -> None:
//| """Read into ``buffer`` from the device selected by ``address``.
//| The number of bytes read will be the length of ``buffer``.
//| At least one byte must be read.
@ -228,7 +228,7 @@ STATIC mp_obj_t busio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args,
}
MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 3, busio_i2c_readfrom_into);
//| def writeto(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None, stop: bool = True) -> None:
//| def writeto(self, address: int, buffer: Union[bytes, bytearray, memoryview], *, start: int = 0, end: int = None, stop: bool = True) -> None:
//| """Write the bytes from ``buffer`` to the device selected by ``address``.
//| Transmits a stop bit when stop is True. Setting stop=False is deprecated and stop will be
//| removed in CircuitPython 6.x. Use `writeto_then_readfrom` when needing a write, no stop and
@ -287,7 +287,7 @@ STATIC mp_obj_t busio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_ma
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto);
//| def writeto_then_readfrom(self, address: int, out_buffer: bytearray, in_buffer: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None:
//| def writeto_then_readfrom(self, address: int, out_buffer: Union[bytes, bytearray, memoryview], in_buffer: Union[bytes, bytearray, memoryview], *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None:
//| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
//| ``in_buffer`` can be the same buffer because they are used sequentially.