diff --git a/micropython/bundles/bundle-networking/manifest.py b/micropython/bundles/bundle-networking/manifest.py index 1db1b08cd..79d5e9d9d 100644 --- a/micropython/bundles/bundle-networking/manifest.py +++ b/micropython/bundles/bundle-networking/manifest.py @@ -5,5 +5,9 @@ require("mip") require("ntptime") -require("urequests") +require("requests") require("webrepl") + +# Provide urequests (which just forwards to requests) for backwards +# compatibility. +require("urequests") diff --git a/micropython/mip/manifest.py b/micropython/mip/manifest.py index f6d47e228..00efa5454 100644 --- a/micropython/mip/manifest.py +++ b/micropython/mip/manifest.py @@ -1,5 +1,5 @@ metadata(version="0.2.0", description="On-device package installer for network-capable boards") -require("urequests") +require("requests") package("mip", opt=3) diff --git a/micropython/mip/mip/__init__.py b/micropython/mip/mip/__init__.py index 0593e2e0f..5f6f4fcd6 100644 --- a/micropython/mip/mip/__init__.py +++ b/micropython/mip/mip/__init__.py @@ -1,7 +1,7 @@ # MicroPython package installer # MIT license; Copyright (c) 2022 Jim Mussared -import urequests as requests +import requests import sys diff --git a/micropython/urequests/README.md b/micropython/urequests/README.md new file mode 100644 index 000000000..f6612b356 --- /dev/null +++ b/micropython/urequests/README.md @@ -0,0 +1,9 @@ +## urequests compatibility + +The MicroPython version of +[requests](https://requests.readthedocs.io/en/latest/) was previously called +`urequests` and a lot of existing code depends on being able to still +import the module by that name. + +This package provides a wrapper to allow this. Prefer to install and use the +`requests` package instead. diff --git a/micropython/urequests/manifest.py b/micropython/urequests/manifest.py new file mode 100644 index 000000000..3fbe61c25 --- /dev/null +++ b/micropython/urequests/manifest.py @@ -0,0 +1,5 @@ +metadata(version="0.8.0", pypi="requests") + +require("requests") + +module("urequests.py") diff --git a/micropython/urequests/urequests.py b/micropython/urequests/urequests.py new file mode 100644 index 000000000..227a1ae5c --- /dev/null +++ b/micropython/urequests/urequests.py @@ -0,0 +1,8 @@ +# This module provides a backwards-compatble import for `urequests`. +# It lazy-loads from `requests` without duplicating its globals dict. + + +def __getattr__(attr): + import requests + + return getattr(requests, attr) diff --git a/micropython/utarfile-write/manifest.py b/micropython/utarfile-write/manifest.py deleted file mode 100644 index bd120ef51..000000000 --- a/micropython/utarfile-write/manifest.py +++ /dev/null @@ -1,4 +0,0 @@ -metadata(description="Adds write (create/append) support to utarfile.", version="0.1.1") - -require("utarfile") -package("utarfile") diff --git a/python-ecosys/requests/README.md b/python-ecosys/requests/README.md new file mode 100644 index 000000000..d6ceaadc5 --- /dev/null +++ b/python-ecosys/requests/README.md @@ -0,0 +1,16 @@ +## requests + +This module provides a lightweight version of the Python +[requests](https://requests.readthedocs.io/en/latest/) library. + +It includes support for all HTTP verbs, https, json decoding of responses, +redirects, basic authentication. + +### Limitations + +* Certificate validation is not currently supported. +* A dictionary passed as post data will not do automatic JSON or + multipart-form encoding of post data (this can be done manually). +* Compressed requests/responses are not currently supported. +* File upload is not supported. +* Chunked encoding in responses is not supported. diff --git a/python-ecosys/urequests/example_xively.py b/python-ecosys/requests/example_xively.py similarity index 80% rename from python-ecosys/urequests/example_xively.py rename to python-ecosys/requests/example_xively.py index 88b890cbc..60e139b98 100644 --- a/python-ecosys/urequests/example_xively.py +++ b/python-ecosys/requests/example_xively.py @@ -1,7 +1,4 @@ -try: - import urequests as requests -except ImportError: - import requests +import requests r = requests.get("http://api.xively.com/") print(r) diff --git a/python-ecosys/requests/manifest.py b/python-ecosys/requests/manifest.py new file mode 100644 index 000000000..7fc2d63bd --- /dev/null +++ b/python-ecosys/requests/manifest.py @@ -0,0 +1,3 @@ +metadata(version="0.8.0", pypi="requests") + +package("requests") diff --git a/python-ecosys/urequests/urequests.py b/python-ecosys/requests/requests/__init__.py similarity index 100% rename from python-ecosys/urequests/urequests.py rename to python-ecosys/requests/requests/__init__.py diff --git a/python-ecosys/urequests/manifest.py b/python-ecosys/urequests/manifest.py deleted file mode 100644 index 4c134081c..000000000 --- a/python-ecosys/urequests/manifest.py +++ /dev/null @@ -1,3 +0,0 @@ -metadata(version="0.7.0", pypi="requests") - -module("urequests.py") diff --git a/micropython/utarfile-write/example-append.py b/python-stdlib/tarfile-write/example-append.py similarity index 86% rename from micropython/utarfile-write/example-append.py rename to python-stdlib/tarfile-write/example-append.py index 9adf34d13..f496eb3aa 100644 --- a/micropython/utarfile-write/example-append.py +++ b/python-stdlib/tarfile-write/example-append.py @@ -1,7 +1,7 @@ """ tar append writes additional files to the end of an existing tar file.""" import os import sys -import utarfile +import tarfile if len(sys.argv) < 2: raise ValueError("Usage: %s appendfile.tar newinputfile1 ..." % sys.argv[0]) @@ -10,6 +10,6 @@ if not tarfile.endswith(".tar"): raise ValueError("Filename %s does not end with .tar" % tarfile) -with utarfile.TarFile(sys.argv[1], "a") as t: +with tarfile.TarFile(sys.argv[1], "a") as t: for filename in sys.argv[2:]: t.add(filename) diff --git a/micropython/utarfile-write/example-create.py b/python-stdlib/tarfile-write/example-create.py similarity index 85% rename from micropython/utarfile-write/example-create.py rename to python-stdlib/tarfile-write/example-create.py index f0c9b206a..ee6ec6255 100644 --- a/micropython/utarfile-write/example-create.py +++ b/python-stdlib/tarfile-write/example-create.py @@ -1,6 +1,6 @@ """ tar create writes a new tar file containing the specified files.""" import sys -import utarfile +import tarfile if len(sys.argv) < 2: raise ValueError("Usage: %s outputfile.tar inputfile1 ..." % sys.argv[0]) @@ -9,6 +9,6 @@ if not tarfile.endswith(".tar"): raise ValueError("Filename %s does not end with .tar" % tarfile) -with utarfile.TarFile(sys.argv[1], "w") as t: +with tarfile.TarFile(sys.argv[1], "w") as t: for filename in sys.argv[2:]: t.add(filename) diff --git a/python-stdlib/tarfile-write/manifest.py b/python-stdlib/tarfile-write/manifest.py new file mode 100644 index 000000000..248f7da60 --- /dev/null +++ b/python-stdlib/tarfile-write/manifest.py @@ -0,0 +1,4 @@ +metadata(description="Adds write (create/append) support to tarfile.", version="0.1.1") + +require("tarfile") +package("tarfile") diff --git a/micropython/utarfile-write/utarfile/write.py b/python-stdlib/tarfile-write/tarfile/write.py similarity index 99% rename from micropython/utarfile-write/utarfile/write.py rename to python-stdlib/tarfile-write/tarfile/write.py index 2bae38a54..062b8ae6b 100644 --- a/micropython/utarfile-write/utarfile/write.py +++ b/python-stdlib/tarfile-write/tarfile/write.py @@ -1,7 +1,7 @@ """Additions to the TarFile class to support creating and appending tar files. The methods defined below in are injected into the TarFile class in the -utarfile package. +tarfile package. """ import uctypes diff --git a/micropython/utarfile/example-extract.py b/python-stdlib/tarfile/example-extract.py similarity index 76% rename from micropython/utarfile/example-extract.py rename to python-stdlib/tarfile/example-extract.py index a8a05d5bc..94ce829ce 100644 --- a/micropython/utarfile/example-extract.py +++ b/python-stdlib/tarfile/example-extract.py @@ -1,14 +1,14 @@ import sys import os -import utarfile +import tarfile if len(sys.argv) < 2: raise ValueError("Usage: %s inputfile.tar" % sys.argv[0]) -t = utarfile.TarFile(sys.argv[1]) +t = tarfile.TarFile(sys.argv[1]) for i in t: print(i.name) - if i.type == utarfile.DIRTYPE: + if i.type == tarfile.DIRTYPE: os.mkdir(i.name) else: f = t.extractfile(i) diff --git a/micropython/utarfile/manifest.py b/python-stdlib/tarfile/manifest.py similarity index 86% rename from micropython/utarfile/manifest.py rename to python-stdlib/tarfile/manifest.py index 68f88e330..9940bb051 100644 --- a/micropython/utarfile/manifest.py +++ b/python-stdlib/tarfile/manifest.py @@ -2,4 +2,4 @@ # Originally written by Paul Sokolovsky. -package("utarfile") +package("tarfile") diff --git a/micropython/utarfile/utarfile/__init__.py b/python-stdlib/tarfile/tarfile/__init__.py similarity index 96% rename from micropython/utarfile/utarfile/__init__.py rename to python-stdlib/tarfile/tarfile/__init__.py index c367b2b36..4bb95af30 100644 --- a/micropython/utarfile/utarfile/__init__.py +++ b/python-stdlib/tarfile/tarfile/__init__.py @@ -93,7 +93,7 @@ def __init__(self, name=None, mode="r", fileobj=None): try: self._open_write(name=name, mode=mode, fileobj=fileobj) except AttributeError: - raise NotImplementedError("Install utarfile-write") + raise NotImplementedError("Install tarfile-write") def __enter__(self): return self @@ -141,7 +141,7 @@ def close(self): pass self.f.close() - # Add additional methods to support write/append from the utarfile-write package. + # Add additional methods to support write/append from the tarfile-write package. try: from .write import _open_write, _close_write, addfile, add except ImportError: