Skip to content

Commit 4063dac

Browse files
committed
all: Use non-u versions of built-in modules.
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>
1 parent e1c9557 commit 4063dac

File tree

21 files changed

+69
-81
lines changed

21 files changed

+69
-81
lines changed

micropython/drivers/display/lcd160cr/lcd160cr.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import machine
66
from utime import sleep_ms
77
from ustruct import calcsize, pack_into
8-
import uerrno
8+
import errno
99

1010
# for set_orient
1111
PORTRAIT = const(0)
@@ -110,7 +110,7 @@ def _waitfor(self, n, buf):
110110
return
111111
t -= 1
112112
sleep_ms(1)
113-
raise OSError(uerrno.ETIMEDOUT)
113+
raise OSError(errno.ETIMEDOUT)
114114

115115
def oflush(self, n=255):
116116
t = 5000
@@ -121,7 +121,7 @@ def oflush(self, n=255):
121121
return
122122
t -= 1
123123
machine.idle()
124-
raise OSError(uerrno.ETIMEDOUT)
124+
raise OSError(errno.ETIMEDOUT)
125125

126126
def iflush(self):
127127
t = 5000
@@ -131,7 +131,7 @@ def iflush(self):
131131
return
132132
t -= 1
133133
sleep_ms(1)
134-
raise OSError(uerrno.ETIMEDOUT)
134+
raise OSError(errno.ETIMEDOUT)
135135

136136
#### MISC METHODS ####
137137

@@ -254,7 +254,7 @@ def get_pixel(self, x, y):
254254
return self.buf[3][1] | self.buf[3][2] << 8
255255
t -= 1
256256
sleep_ms(1)
257-
raise OSError(uerrno.ETIMEDOUT)
257+
raise OSError(errno.ETIMEDOUT)
258258

259259
def get_line(self, x, y, buf):
260260
l = len(buf) // 2
@@ -268,7 +268,7 @@ def get_line(self, x, y, buf):
268268
return
269269
t -= 1
270270
sleep_ms(1)
271-
raise OSError(uerrno.ETIMEDOUT)
271+
raise OSError(errno.ETIMEDOUT)
272272

273273
def screen_dump(self, buf, x=0, y=0, w=None, h=None):
274274
if w is None:

micropython/drivers/radio/nrf24l01/nrf24l01test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Test for nrf24l01 module. Portable between MicroPython targets."""
22

3-
import usys
4-
import ustruct as struct
3+
import sys
4+
import struct
55
import utime
66
from machine import Pin, SPI, SoftSPI
77
from nrf24l01 import NRF24L01
@@ -14,20 +14,20 @@
1414
# initiator may be a slow device. Value tested with Pyboard, ESP32 and ESP8266.
1515
_RESPONDER_SEND_DELAY = const(10)
1616

17-
if usys.platform == "pyboard":
17+
if sys.platform == "pyboard":
1818
spi = SPI(2) # miso : Y7, mosi : Y8, sck : Y6
1919
cfg = {"spi": spi, "csn": "Y5", "ce": "Y4"}
20-
elif usys.platform == "esp8266": # Hardware SPI
20+
elif sys.platform == "esp8266": # Hardware SPI
2121
spi = SPI(1) # miso : 12, mosi : 13, sck : 14
2222
cfg = {"spi": spi, "csn": 4, "ce": 5}
23-
elif usys.platform == "esp32": # Software SPI
23+
elif sys.platform == "esp32": # Software SPI
2424
spi = SoftSPI(sck=Pin(25), mosi=Pin(33), miso=Pin(32))
2525
cfg = {"spi": spi, "csn": 26, "ce": 27}
26-
elif usys.platform == "rp2": # Hardware SPI with explicit pin definitions
26+
elif sys.platform == "rp2": # Hardware SPI with explicit pin definitions
2727
spi = SPI(0, sck=Pin(2), mosi=Pin(3), miso=Pin(4))
2828
cfg = {"spi": spi, "csn": 5, "ce": 6}
2929
else:
30-
raise ValueError("Unsupported platform {}".format(usys.platform))
30+
raise ValueError("Unsupported platform {}".format(sys.platform))
3131

3232
# Addresses are in little-endian format. They correspond to big-endian
3333
# 0xf0f0f0f0e1, 0xf0f0f0f0d2

micropython/net/ntptime/ntptime.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import utime
2-
3-
try:
4-
import usocket as socket
5-
except:
6-
import socket
7-
try:
8-
import ustruct as struct
9-
except:
10-
import struct
1+
from time import gmtime
2+
import socket
3+
import struct
114

125
# The NTP host can be configured at runtime by doing: ntptime.host = 'myhost.org'
136
host = "pool.ntp.org"
@@ -53,7 +46,7 @@ def time():
5346

5447
# Convert timestamp from NTP format to our internal format
5548

56-
EPOCH_YEAR = utime.gmtime(0)[0]
49+
EPOCH_YEAR = gmtime(0)[0]
5750
if EPOCH_YEAR == 2000:
5851
# (date(2000, 1, 1) - date(1900, 1, 1)).days * 24*60*60
5952
NTP_DELTA = 3155673600
@@ -71,5 +64,5 @@ def settime():
7164
t = time()
7265
import machine
7366

74-
tm = utime.gmtime(t)
67+
tm = gmtime(t)
7568
machine.RTC().datetime((tm[0], tm[1], tm[2], tm[6] + 1, tm[3], tm[4], tm[5], 0))

micropython/udnspkt/example_resolve.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import uio
2-
import usocket
1+
import io
2+
import socket
33

44
import udnspkt
55

66

7-
s = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM)
8-
dns_addr = usocket.getaddrinfo("127.0.0.1", 53)[0][-1]
7+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
8+
dns_addr = socket.getaddrinfo("127.0.0.1", 53)[0][-1]
99

1010

1111
def resolve(domain, is_ipv6):
12-
buf = uio.BytesIO(48)
12+
buf = io.BytesIO(48)
1313
udnspkt.make_req(buf, "google.com", is_ipv6)
1414
v = buf.getvalue()
1515
print("query: ", v)
1616
s.sendto(v, dns_addr)
1717

1818
resp = s.recv(1024)
1919
print("resp:", resp)
20-
buf = uio.BytesIO(resp)
20+
buf = io.BytesIO(resp)
2121

2222
addr = udnspkt.parse_resp(buf, is_ipv6)
2323
print("bin addr:", addr)
24-
print("addr:", usocket.inet_ntop(usocket.AF_INET6 if is_ipv6 else usocket.AF_INET, addr))
24+
print("addr:", socket.inet_ntop(socket.AF_INET6 if is_ipv6 else socket.AF_INET, addr))
2525

2626

2727
resolve("google.com", False)

micropython/udnspkt/udnspkt.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import uio
2-
3-
41
def write_fqdn(buf, name):
52
parts = name.split(".")
63
for p in parts:

micropython/umqtt.robust/umqtt/robust.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import utime
1+
import time
22
from . import simple
33

44

@@ -7,7 +7,7 @@ class MQTTClient(simple.MQTTClient):
77
DEBUG = False
88

99
def delay(self, i):
10-
utime.sleep(self.DELAY)
10+
time.sleep(self.DELAY)
1111

1212
def log(self, in_reconnect, e):
1313
if self.DEBUG:

micropython/umqtt.simple/example_pub_button.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import time
2-
import ubinascii
2+
import binascii
33
import machine
44
from umqtt.simple import MQTTClient
55
from machine import Pin
@@ -10,7 +10,7 @@
1010

1111
# Default MQTT server to connect to
1212
SERVER = "192.168.1.35"
13-
CLIENT_ID = ubinascii.hexlify(machine.unique_id())
13+
CLIENT_ID = binascii.hexlify(machine.unique_id())
1414
TOPIC = b"led"
1515

1616

micropython/umqtt.simple/example_sub_led.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from umqtt.simple import MQTTClient
22
from machine import Pin
3-
import ubinascii
3+
import binascii
44
import machine
55
import micropython
66

@@ -11,7 +11,7 @@
1111

1212
# Default MQTT server to connect to
1313
SERVER = "192.168.1.35"
14-
CLIENT_ID = ubinascii.hexlify(machine.unique_id())
14+
CLIENT_ID = binascii.hexlify(machine.unique_id())
1515
TOPIC = b"led"
1616

1717

micropython/umqtt.simple/umqtt/simple.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import usocket as socket
2-
import ustruct as struct
3-
from ubinascii import hexlify
1+
import socket
2+
import struct
3+
from binascii import hexlify
44

55

66
class MQTTException(Exception):

micropython/urllib.urequest/urllib/urequest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import usocket
1+
import socket
22

33

44
def urlopen(url, data=None, method="GET"):
@@ -22,10 +22,10 @@ def urlopen(url, data=None, method="GET"):
2222
host, port = host.split(":", 1)
2323
port = int(port)
2424

25-
ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
25+
ai = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)
2626
ai = ai[0]
2727

28-
s = usocket.socket(ai[0], ai[1], ai[2])
28+
s = socket.socket(ai[0], ai[1], ai[2])
2929
try:
3030
s.connect(ai[-1])
3131
if proto == "https:":

python-ecosys/requests/requests/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import usocket
1+
import socket
22

33

44
class Response:
@@ -28,9 +28,9 @@ def text(self):
2828
return str(self.content, self.encoding)
2929

3030
def json(self):
31-
import ujson
31+
import json
3232

33-
return ujson.loads(self.content)
33+
return json.loads(self.content)
3434

3535

3636
def request(
@@ -48,11 +48,11 @@ def request(
4848
chunked_data = data and getattr(data, "__next__", None) and not getattr(data, "__len__", None)
4949

5050
if auth is not None:
51-
import ubinascii
51+
import binascii
5252

5353
username, password = auth
5454
formated = b"{}:{}".format(username, password)
55-
formated = str(ubinascii.b2a_base64(formated)[:-1], "ascii")
55+
formated = str(binascii.b2a_base64(formated)[:-1], "ascii")
5656
headers["Authorization"] = "Basic {}".format(formated)
5757

5858
try:
@@ -73,14 +73,14 @@ def request(
7373
host, port = host.split(":", 1)
7474
port = int(port)
7575

76-
ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
76+
ai = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)
7777
ai = ai[0]
7878

7979
resp_d = None
8080
if parse_headers is not False:
8181
resp_d = {}
8282

83-
s = usocket.socket(ai[0], usocket.SOCK_STREAM, ai[2])
83+
s = socket.socket(ai[0], socket.SOCK_STREAM, ai[2])
8484

8585
if timeout is not None:
8686
# Note: settimeout is not supported on all platforms, will raise
@@ -104,9 +104,9 @@ def request(
104104
s.write(b"\r\n")
105105
if json is not None:
106106
assert data is None
107-
import ujson
107+
import json
108108

109-
data = ujson.dumps(json)
109+
data = json.dumps(json)
110110
s.write(b"Content-Type: application/json\r\n")
111111
if data:
112112
if chunked_data:

python-stdlib/argparse/argparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
import sys
6-
from ucollections import namedtuple
6+
from collections import namedtuple
77

88

99
class _ArgError(BaseException):

python-stdlib/binascii/test_binascii.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from binascii import *
2-
import utime
2+
import time
33

44
data = b"zlutoucky kun upel dabelske ody"
55
h = hexlify(data)
@@ -14,10 +14,10 @@
1414

1515
a2b_base64(b"as==") == b"j"
1616

17-
start = utime.time()
17+
start = time.time()
1818
for x in range(100000):
1919
d = unhexlify(h)
2020

21-
print("100000 iterations in: " + str(utime.time() - start))
21+
print("100000 iterations in: " + str(time.time() - start))
2222

2323
print("OK")

python-stdlib/copy/copy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Error(Exception):
6262
error = Error # backward compatibility
6363

6464
try:
65-
from ucollections import OrderedDict
65+
from collections import OrderedDict
6666
except ImportError:
6767
OrderedDict = None
6868

python-stdlib/pkg_resources/pkg_resources.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import uio
1+
import io
22

33
c = {}
44

@@ -18,11 +18,11 @@ def resource_stream(package, resource):
1818
else:
1919
d = "."
2020
# if d[0] != "/":
21-
# import uos
22-
# d = uos.getcwd() + "/" + d
21+
# import os
22+
# d = os.getcwd() + "/" + d
2323
c[package] = d + "/"
2424

2525
p = c[package]
2626
if isinstance(p, dict):
27-
return uio.BytesIO(p[resource])
27+
return io.BytesIO(p[resource])
2828
return open(p + resource, "rb")

unix-ffi/machine/example_timer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import utime
1+
import time
22
from machine import Timer
33

44

@@ -7,5 +7,5 @@
77
t1.callback(lambda t: print(t, "tick1"))
88
t2.callback(lambda t: print(t, "tick2"))
99

10-
utime.sleep(3)
10+
time.sleep(3)
1111
print("done")

unix-ffi/machine/machine/timer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import ffilib
22
import uctypes
33
import array
4-
import uos
54
import os
6-
import utime
75
from signal import *
86

97
libc = ffilib.libc()

unix-ffi/os/os/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import array
2-
import ustruct as struct
2+
import struct
33
import errno as errno_
44
import stat as stat_
55
import ffilib

0 commit comments

Comments
 (0)