Skip to content

Commit 9ac1428

Browse files
authored
gh-141968: use bytearray.take_bytes in encodings.idna (#141975)
1 parent 9dbf77b commit 9ac1428

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Lib/encodings/idna.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ def encode(self, input, errors='strict'):
226226
offset + exc.end,
227227
exc.reason,
228228
)
229-
return bytes(result+trailing_dot), len(input)
229+
result += trailing_dot
230+
return result.take_bytes(), len(input)
230231

231232
def decode(self, input, errors='strict'):
232233

@@ -311,7 +312,7 @@ def _buffer_encode(self, input, errors, final):
311312

312313
result += trailing_dot
313314
size += len(trailing_dot)
314-
return (bytes(result), size)
315+
return (result.take_bytes(), size)
315316

316317
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
317318
def _buffer_decode(self, input, errors, final):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove data copy from :mod:`encodings.idna` :meth:`~codecs.Codec.encode` and
2+
:meth:`~codecs.IncrementalEncoder.encode` by using :func:`bytearray.take_bytes`.

0 commit comments

Comments
 (0)