MCPcopy Index your code
hub / github.com/RustPython/RustPython / decode

Method decode

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

Source from the content-addressed store, hash-verified

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

isinstanceFunction · 0.85
lenFunction · 0.85
enumerateFunction · 0.85
ToUnicodeFunction · 0.85
sumFunction · 0.50
lowerMethod · 0.45
splitMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected