requests: Rename urequests to requests.

This module implements a subset of the Python requests module, and so
it should have the same name.

Added a backwards-compatibility wrapper to allow people to continue to use
`import urequests`. This lives in micropython/urequests.

Changed requests to be a package, so that we can implement extension
packages in the future for optional functionality.

Added a basic README.md to both.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
pull/702/head
Jim Mussared 2023-07-21 16:39:28 +10:00 zatwierdzone przez Damien George
rodzic 5004436164
commit 8513bfbe9d
11 zmienionych plików z 49 dodań i 10 usunięć

Wyświetl plik

@ -5,5 +5,9 @@ metadata(
require("mip")
require("ntptime")
require("urequests")
require("requests")
require("webrepl")
# Provide urequests (which just forwards to requests) for backwards
# compatibility.
require("urequests")

Wyświetl plik

@ -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)

Wyświetl plik

@ -1,7 +1,7 @@
# MicroPython package installer
# MIT license; Copyright (c) 2022 Jim Mussared
import urequests as requests
import requests
import sys

Wyświetl plik

@ -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.

Wyświetl plik

@ -0,0 +1,5 @@
metadata(version="0.8.0", pypi="requests")
require("requests")
module("urequests.py")

Wyświetl plik

@ -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)

Wyświetl plik

@ -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.

Wyświetl plik

@ -1,7 +1,4 @@
try:
import urequests as requests
except ImportError:
import requests
import requests
r = requests.get("http://api.xively.com/")
print(r)

Wyświetl plik

@ -0,0 +1,3 @@
metadata(version="0.8.0", pypi="requests")
package("requests")

Wyświetl plik

@ -1,3 +0,0 @@
metadata(version="0.7.0", pypi="requests")
module("urequests.py")