Skip to content

Commit ae4fa7f

Browse files
committed
asyncio_micro: Rename StreamWriter.write() to awrite().
This method has different semantics than original asyncio, so rename to avoid confusion. Original asyncio's is not a coroutine, while ours is.
1 parent fe23bdf commit ae4fa7f

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

asyncio_micro/asyncio_micro.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,26 @@ class StreamWriter:
222222
def __init__(self, s):
223223
self.s = s
224224

225-
def write(self, buf):
225+
def awrite(self, buf):
226+
# This method is called awrite (async write) to not proliferate
227+
# incompatibility with original asyncio. Unlike original asyncio
228+
# whose .write() method is both not a coroutine and guaranteed
229+
# to return immediately (which means it has to buffer all the
230+
# data), this method is a coroutine.
226231
sz = len(buf)
227232
while True:
228233
res = self.s.write(buf)
229-
log.debug("StreamWriter.write(): %d", res)
230-
# If we spooled everything, (just) return
234+
# If we spooled everything, return immediately
231235
if res == sz:
236+
log.debug("StreamWriter.awrite(): completed spooling %d bytes", res)
232237
return
233238
if res is None:
234239
res = 0
240+
log.debug("StreamWriter.awrite(): spooled partial %d bytes", res)
235241
buf = buf[res:]
236242
sz -= res
237243
s = yield IOWrite(self.s)
238-
log.debug("StreamWriter.write(): can write more")
244+
log.debug("StreamWriter.awrite(): can write more")
239245

240246
def close(self):
241247
yield IODone(IO_WRITE, self.s)

asyncio_micro/test_http_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def print_http_headers(url):
66
print(reader, writer)
77
print("================")
88
query = "GET / HTTP/1.0\r\n\r\n"
9-
yield from writer.write(query.encode('latin-1'))
9+
yield from writer.awrite(query.encode('latin-1'))
1010
while True:
1111
line = yield from reader.readline()
1212
if not line:

asyncio_micro/test_http_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def serve(reader, writer):
55
print(reader, writer)
66
print("================")
77
print((yield from reader.read()))
8-
yield from writer.write("HTTP/1.0 200 OK\r\n\r\nHello.\r\n")
8+
yield from writer.awrite("HTTP/1.0 200 OK\r\n\r\nHello.\r\n")
99
print("After response write")
1010
yield from writer.close()
1111
print("Finished processing request")

0 commit comments

Comments
 (0)