Skip to content

Commit

Permalink
Renamed max_size parameters to max_bytes
Browse files Browse the repository at this point in the history
Fixes #123.
  • Loading branch information
agronholm committed Jul 14, 2020
1 parent 4c80c9a commit f5f2ef5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
object with a new one rather than clear the old one.
- **BACKWARDS INCOMPATIBLE** Removed the ``anyio.create_queue`` function and the ``Queue`` class.
Use memory object streams instead.
- **BACKWARDS INCOMPATIBLE** Renamed the ``max_size`` parameter to ``max_bytes`` wherever it
occurred (this was inconsistently named ``max_bytes`` in some subclasses before)
- Unified checkpoint behavior: a cancellation check now calls ``sleep(0)`` on asyncio and curio,
allowing the scheduler to switch to a different task
- Added memory object streams
Expand Down
16 changes: 8 additions & 8 deletions src/anyio/_networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ async def receive_exactly(self, nbytes: int) -> bytes:
self._buffer = self._buffer[nbytes:]
return result

async def receive_until(self, delimiter: bytes, max_size: int) -> bytes:
async def receive_until(self, delimiter: bytes, max_bytes: int) -> bytes:
delimiter_size = len(delimiter)
offset = 0
while True:
Expand All @@ -271,11 +271,11 @@ async def receive_until(self, delimiter: bytes, max_size: int) -> bytes:
return found

# Check if the buffer is already at or over the limit
if len(self._buffer) >= max_size:
raise DelimiterNotFound(max_size)
if len(self._buffer) >= max_bytes:
raise DelimiterNotFound(max_bytes)

# Read more data into the buffer from the socket
read_size = max_size - len(self._buffer)
read_size = max_bytes - len(self._buffer)
data = await self._socket.recv(read_size)
if not data:
raise IncompleteRead
Expand All @@ -284,9 +284,9 @@ async def receive_until(self, delimiter: bytes, max_size: int) -> bytes:
offset = max(len(self._buffer) - delimiter_size + 1, 0)
self._buffer += data

async def receive_chunks(self, max_size: int):
async def receive_chunks(self, max_bytes: int):
while True:
data = await self.receive(max_size)
data = await self.receive(max_bytes)
if data:
yield data
else:
Expand Down Expand Up @@ -447,9 +447,9 @@ async def receive(self, max_bytes: int) -> Tuple[bytes, Tuple[str, int]]:
data, addr = await self._socket.recvfrom(max_bytes)
return data, addr[:2]

async def receive_packets(self, max_size: int):
async def receive_packets(self, max_bytes: int):
while self._socket.fileno() != -1:
packet, address = await self.receive(max_size)
packet, address = await self.receive(max_bytes)
if packet:
yield (packet, address)
else:
Expand Down
3 changes: 2 additions & 1 deletion src/anyio/abc/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,13 @@ async def receive(self, max_bytes: int) -> Tuple[bytes, Tuple[str, int]]:
"""

@abstractmethod
def receive_packets(self, max_size: int) -> AsyncIterable[Tuple[bytes, str]]:
def receive_packets(self, max_bytes: int) -> AsyncIterable[Tuple[bytes, str]]:
"""
Return an async iterable which yields packets read from the socket.
The iterable exits if the socket is closed.
:param max_bytes: maximum number of bytes to return
:return: an async iterable yielding (bytes, source address) tuples
"""

Expand Down

0 comments on commit f5f2ef5

Please sign in to comment.