Skip to content

Commit 84ba452

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 7271f1d commit 84ba452

File tree

22 files changed

+72
-84
lines changed

22 files changed

+72
-84
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:":

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy