The sqlite3_prepare and sqlite3_close have been changed to use the v2
version. For the prepare this was done as the v1 version is "legacy",
and for close the documentation describes the v2 version to be used for
"host languages that are garbage collected, and where the order in
which destructors are called is arbitrary", which fits here.
Some clean-up to comments has also be done, and the tests now also
close the Cursor and Connections.
Signed-off-by: Robert Klink <rhermanklink@ripe.net>
This commit adds the ability to enable URI on the connect, as can be done
in the cpython sqlite3 module. URI allows, among other things, to create
a shared named in-memory database, which non URI filenames cannot create.
Signed-off-by: Robert Klink <rhermanklink@ripe.net>
Currently, statements are only finalized upon a call to Cursor.close().
However, in Cursor.execute() new statements get created without the
previous statements being finalized, causing those to get leaked,
preventing the database from being closed. The fix addresses this by
finalizing the previous statement if it exists.
Signed-off-by: Robert Klink <rhermanklink@ripe.net>
Currently, the bytes object used to store the sqlite3 database pointer
is always 4 bytes, which causes segfaults on 64 bit platforms with 8
byte pointers. To address this, the size is now dynamically determined
using the uctypes modules pointer size.
Signed-off-by: Robert Klink <rhermanklink@ripe.net>
This points to the package's base directory of the within the
micropython-lib directory structure.
Signed-off-by: Damien George <damien@micropython.org>
Currently, the LoRa SX126x driver dynamically creates at least one,
sometimes two, memoryview objects with each call to `_cmd`. This commit
simply provides the class with a long-lived memoryview object for `_cmd` to
easily slice as necessary.
Unlike the SX127x chips, Semtech unfortunately designed the SX126x modems
to be more command-centric (as opposed to directly setting registers).
Given the amount `_cmd` is called during normal device operation, even a
minor improvement here should have a decent impact.
Basic TX and RX tests pass on hardware.
Signed-off-by: Max Holliday <maholli@stanford.edu>
If the CDC receive buffer was full and some code read less than 64 bytes
(wMaxTransferSize), the CDC code would submit an OUT transfer with N<64
bytes length to fill the buffer back up.
However if the host had more than N bytes to send then it would still send
the full 64 bytes (correctly) in the transfer. The remaining (64-N) bytes
would be lost.
Adds the restriction that CDCInterface rxbuf has to be at least 64 bytes.
Fixes issue #885.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
When running tests from subfolders, import by "full dotted path" rather
than just module name, removing the need to add the test parent folder to
`sys.path`.
This matches CPython more closely, which places `abspath(top)` at the start
of `sys.path` but doesn't include the test file parent dir at all.
It fixes issues where projects may include a `test_xxx.py` file in their
distribution which would (prior to this change) be unintentionally found by
unittest-discover.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
All of the runable package tests are run together in the new `tools/ci.sh`
function called `ci_package_tests_run`. This is added to a new GitHub
workflow to test the packages as part of CI.
Some packages use `unittest` while others use an ad-hoc test script.
Eventually it would be good to unify all the package tests to use
`unittest`.
Signed-off-by: Damien George <damien@micropython.org>
Since deque was removed from this repository the built-in one needs to be
used, and that doesn't have unbounded growth. So use a list instead, which
is adequate becasue contextlib only needs append and pop, not double ended
behaviour (the previous pure-Python implementation of deque that was used
here anyway used a list as its storage container).
Also tweak the excessive-nesting test so it uses less memory and can run on
the unix port.
Signed-off-by: Damien George <damien@micropython.org>
Storing references to tasks is required by CPython, and enforced by Ruff
RUF006. In this case it's also reasonable to cancel these tasks once the
test is finished.
Signed-off-by: Damien George <damien@micropython.org>
This changes almost all uses of "u-module" to just "module" for the
following built-in modules:
- binascii
- collections
- errno
- io
- json
- socket
- struct
- sys
- time
There are some remaining uses of "u-module" naming, for the cases where the
built-in module is extended in Python, eg `python-stdlib/os` uses `uos`.
Also, there are remaining uses of `utime` when non-standard (compared to
CPython) functions are used, like `utime.ticks_ms()`.
Signed-off-by: Damien George <damien@micropython.org>
This removes all the hard-coded request headers from the requests module so
they can be overridden by user provided headers dict. Furthermore allow
streaming request data without chunk encoding in those cases where content
length is known but it's not desirable to load the whole content into
memory. Also some servers (e.g. nginx) reject HTTP/1.0 requests with the
Transfer-Encoding header set.
The change should be backwards compatible as long as the user hasn't
provided any of the previously hard-coded headers.
Signed-off-by: Mirza Kapetanovic <mirza.kapetanovic@gmail.com>
Testing shows that the first two writes always go through and the rest are
dropped, so update the .exp file to match that.
Signed-off-by: Damien George <damien@micropython.org>
This tests both encoding and decoding multiple 16-bit and 32-bit services
within the one advertising field.
Signed-off-by: Damien George <damien@micropython.org>
Fixes are needed to support the cases of:
- There may be more than one UUID per advertising field.
- The UUID advertising field may be empty (no UUIDs).
- Constructing 32-bit `bluetooth.UUID()` entities, which must be done by
passing in a 4-byte bytes object, not an integer.
Signed-off-by: Damien George <damien@micropython.org>
When multiple UUIDs of the same size are advertised, they should all be
listed in a single LTV. Supplement to the Bluetooth Core Specification,
Part A, §1.1.1: "A packet or data block shall not contain more than one
instance for each Service UUID data size."
When aioble construct the advertisement data, it is creating a new data
block for each UUID that contains only that single UUID. Rather than,
e.g., a single 16-bit UUID block with a list of multiple UUIDs.
Not only is this against the specification, it wastes two bytes of limited
advertisement space per UUID beyond the first for the repeated data block
length and type fields.
Fix this by grouping each UUID size together.
Signed-off-by: Trent Piepho <tpiepho@gmail.com>
The value for the `timeout_ms` optional argument to
`DeviceConnection.disconnected()` async method is changed from 60000 to
None. This way users awaiting a device disconnection using `await
connection.disconnected()` won't be surprised by a 1 minute timeout.
Only read from the temp characteristic if the connection is still active.
Improves the example by avoiding a TypeError exception if/when the sensor
disconnects.
This sets the disconnected timeout to None, so that the peripheral waits
forever for the client to disconnect. Previously the peripheral would
abort the connection after 60 seconds (because that's the default timeout).
Signed-off-by: Stephen More <stephen.more@gmail.com>
This ensures that the peripheral notifies subscribed clients when the
characteristic is written to.
Signed-off-by: Stephen More <stephen.more@gmail.com>
The function `binascii.b2a_base64()` returns a `bytes`, but here needs a
string. Otherwise, the value of `Sec-WebSocket-Key` in the headers will be
`b'<BASE64-ENCODED_RANDOM_VALUE>'`.
Signed-off-by: AuroraTea <1352685369@qq.com>
Mostly small cleanups to put each top-level import on its own line. But
explicitly disable the lint for examples/tests which insert the current
directory into the path before importing.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Most of these look like they were used for print debugging and then kept in
when the print statements were removed or commented.
Some look like missing or incomplete functionality, these have been marked
with comments where possible.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
It's no longer necessary since the built-in C version of this type now
implements all the functionality here.
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
These packages build on top of machine.USBDevice() to provide high level
and flexible support for implementing USB devices in Python code.
Additional credits, as per included copyright notices:
- CDC support based on initial implementation by @hoihu with fixes by
@linted.
- MIDI support based on initial implementation by @paulhamsh.
- HID keypad example based on work by @turmoni.
- Everyone who tested and provided feedback on early versions of these
packages.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
axtls doesn't define all the CERT_xxx constants, nor the MBEDTLS_VERSION
constant.
This change means that `tls.SSLContext` is imported into the module, but
that's subsequently overridden by the class definition in this module.
Signed-off-by: Damien George <damien@micropython.org>
Changes are cosmetic - and maybe very minor code size - but not functional.
_reg_read() was calling struct.packinto() with an incorrect number of
arguments but it seems like MicroPython didn't mind, as result is correct
for both versions.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>