Thanks to visit codestin.com
Credit goes to github.com

Skip to content

all: Rename utarfile->tarfile and urequests->requests. #702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion micropython/bundles/bundle-networking/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion micropython/mip/manifest.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion micropython/mip/mip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MicroPython package installer
# MIT license; Copyright (c) 2022 Jim Mussared

import urequests as requests
import requests
import sys


Expand Down
9 changes: 9 additions & 0 deletions micropython/urequests/README.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions micropython/urequests/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
metadata(version="0.8.0", pypi="requests")

require("requests")

module("urequests.py")
8 changes: 8 additions & 0 deletions micropython/urequests/urequests.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 0 additions & 4 deletions micropython/utarfile-write/manifest.py

This file was deleted.

16 changes: 16 additions & 0 deletions python-ecosys/requests/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
try:
import urequests as requests
except ImportError:
import requests
import requests

r = requests.get("http://api.xively.com/")
print(r)
Expand Down
3 changes: 3 additions & 0 deletions python-ecosys/requests/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
metadata(version="0.8.0", pypi="requests")

package("requests")
3 changes: 0 additions & 3 deletions python-ecosys/urequests/manifest.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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])
Expand All @@ -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)
Original file line number Diff line number Diff line change
@@ -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])
Expand All @@ -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)
4 changes: 4 additions & 0 deletions python-stdlib/tarfile-write/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
metadata(description="Adds write (create/append) support to tarfile.", version="0.1.1")

require("tarfile")
package("tarfile")
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# Originally written by Paul Sokolovsky.

package("utarfile")
package("tarfile")
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down