Skip to content

Commit 05efdd0

Browse files
bulletmarkdpgeorge
authored andcommitted
uaiohttpclient: Update "yield from" to "await".
Signed-off-by: Mark Blakeney <mark.blakeney@bullet-systems.net>
1 parent 9d09cdd commit 05efdd0

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

micropython/uaiohttpclient/uaiohttpclient.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ class ClientResponse:
55
def __init__(self, reader):
66
self.content = reader
77

8-
def read(self, sz=-1):
9-
return (yield from self.content.read(sz))
8+
async def read(self, sz=-1):
9+
return await self.content.read(sz)
1010

1111
def __repr__(self):
1212
return "<ClientResponse %d %s>" % (self.status, self.headers)
@@ -17,30 +17,30 @@ def __init__(self, reader):
1717
self.content = reader
1818
self.chunk_size = 0
1919

20-
def read(self, sz=4 * 1024 * 1024):
20+
async def read(self, sz=4 * 1024 * 1024):
2121
if self.chunk_size == 0:
22-
line = yield from self.content.readline()
22+
line = await self.content.readline()
2323
# print("chunk line:", l)
2424
line = line.split(b";", 1)[0]
2525
self.chunk_size = int(line, 16)
2626
# print("chunk size:", self.chunk_size)
2727
if self.chunk_size == 0:
2828
# End of message
29-
sep = yield from self.content.read(2)
29+
sep = await self.content.read(2)
3030
assert sep == b"\r\n"
3131
return b""
32-
data = yield from self.content.read(min(sz, self.chunk_size))
32+
data = await self.content.read(min(sz, self.chunk_size))
3333
self.chunk_size -= len(data)
3434
if self.chunk_size == 0:
35-
sep = yield from self.content.read(2)
35+
sep = await self.content.read(2)
3636
assert sep == b"\r\n"
3737
return data
3838

3939
def __repr__(self):
4040
return "<ChunkedClientResponse %d %s>" % (self.status, self.headers)
4141

4242

43-
def request_raw(method, url):
43+
async def request_raw(method, url):
4444
try:
4545
proto, dummy, host, path = url.split("/", 3)
4646
except ValueError:
@@ -55,7 +55,7 @@ def request_raw(method, url):
5555

5656
if proto != "http:":
5757
raise ValueError("Unsupported protocol: " + proto)
58-
reader, writer = yield from asyncio.open_connection(host, port)
58+
reader, writer = await asyncio.open_connection(host, port)
5959
# Use protocol 1.0, because 1.1 always allows to use chunked
6060
# transfer-encoding But explicitly set Connection: close, even
6161
# though this should be default for 1.0, because some servers
@@ -65,22 +65,21 @@ def request_raw(method, url):
6565
path,
6666
host,
6767
)
68-
yield from writer.awrite(query.encode("latin-1"))
69-
# yield from writer.aclose()
68+
await writer.awrite(query.encode("latin-1"))
7069
return reader
7170

7271

73-
def request(method, url):
72+
async def request(method, url):
7473
redir_cnt = 0
7574
while redir_cnt < 2:
76-
reader = yield from request_raw(method, url)
75+
reader = await request_raw(method, url)
7776
headers = []
78-
sline = yield from reader.readline()
77+
sline = await reader.readline()
7978
sline = sline.split(None, 2)
8079
status = int(sline[1])
8180
chunked = False
8281
while True:
83-
line = yield from reader.readline()
82+
line = await reader.readline()
8483
if not line or line == b"\r\n":
8584
break
8685
headers.append(line)
@@ -92,7 +91,7 @@ def request(method, url):
9291

9392
if 301 <= status <= 303:
9493
redir_cnt += 1
95-
yield from reader.aclose()
94+
await reader.aclose()
9695
continue
9796
break
9897

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