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

Method decode

Lib/encodings/idna.py:232–271  ·  view source on GitHub ↗
(self, input, errors='strict')

Source from the content-addressed store, hash-verified

230 return result.take_bytes(), len(input)
231
232 def decode(self, input, errors='strict'):
233
234 if errors != 'strict':
235 raise UnicodeError(f"Unsupported error handling: {errors}")
236
237 if not input:
238 return "", 0
239
240 # IDNA allows decoding to operate on Unicode strings, too.
241 if not isinstance(input, bytes):
242 # XXX obviously wrong, see #3232
243 input = bytes(input)
244
245 if ace_prefix not in input.lower():
246 # Fast path
247 try:
248 return input.decode('ascii'), len(input)
249 except UnicodeDecodeError:
250 pass
251
252 labels = input.split(b".")
253
254 if labels and len(labels[-1]) == 0:
255 trailing_dot = '.'
256 del labels[-1]
257 else:
258 trailing_dot = ''
259
260 result = []
261 for i, label in enumerate(labels):
262 try:
263 u_label = ToUnicode(label)
264 except (UnicodeEncodeError, UnicodeDecodeError) as exc:
265 offset = sum(len(x) for x in labels[:i]) + len(labels[:i])
266 raise UnicodeDecodeError(
267 "idna", input, offset+exc.start, offset+exc.end, exc.reason)
268 else:
269 result.append(u_label)
270
271 return ".".join(result)+trailing_dot, len(input)
272
273class IncrementalEncoder(codecs.BufferedIncrementalEncoder):
274 def _buffer_encode(self, input, errors, final):

Callers 15

ToUnicodeFunction · 0.45
_ipaddr_infoFunction · 0.45
feedMethod · 0.45
header_encodeFunction · 0.45
encode_7or8bitFunction · 0.45
body_encodeMethod · 0.45
_sanitizeFunction · 0.45
parsebytesMethod · 0.45
decode_headerFunction · 0.45
__str__Method · 0.45
appendMethod · 0.45
_encoded_words.pyFile · 0.45

Calls 6

enumerateFunction · 0.85
ToUnicodeFunction · 0.85
lowerMethod · 0.45
splitMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected