MCPcopy Index your code
hub / github.com/python/cpython / _buffer_decode

Method _buffer_decode

Lib/encodings/idna.py:318–369  ·  view source on GitHub ↗
(self, input, errors, final)

Source from the content-addressed store, hash-verified

316
317class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
318 def _buffer_decode(self, input, errors, final):
319 if errors != 'strict':
320 raise UnicodeError(f"Unsupported error handling: {errors}")
321
322 if not input:
323 return ("", 0)
324
325 # IDNA allows decoding to operate on Unicode strings, too.
326 if isinstance(input, str):
327 labels = dots.split(input)
328 else:
329 # Must be ASCII string
330 try:
331 input = str(input, "ascii")
332 except (UnicodeEncodeError, UnicodeDecodeError) as exc:
333 raise UnicodeDecodeError("idna", input,
334 exc.start, exc.end, exc.reason)
335 labels = input.split(".")
336
337 trailing_dot = ''
338 if labels:
339 if not labels[-1]:
340 trailing_dot = '.'
341 del labels[-1]
342 elif not final:
343 # Keep potentially unfinished label until the next call
344 del labels[-1]
345 if labels:
346 trailing_dot = '.'
347
348 result = []
349 size = 0
350 for label in labels:
351 try:
352 u_label = ToUnicode(label)
353 except (UnicodeEncodeError, UnicodeDecodeError) as exc:
354 raise UnicodeDecodeError(
355 "idna",
356 input.encode("ascii", errors="backslashreplace"),
357 size + exc.start,
358 size + exc.end,
359 exc.reason,
360 )
361 else:
362 result.append(u_label)
363 if size:
364 size += 1
365 size += len(label)
366
367 result = ".".join(result) + trailing_dot
368 size += len(trailing_dot)
369 return (result, size)
370
371class StreamWriter(Codec,codecs.StreamWriter):
372 pass

Callers

nothing calls this directly

Calls 6

strFunction · 0.85
ToUnicodeFunction · 0.85
splitMethod · 0.45
encodeMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected