(self, input, errors='strict')
| 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 | |
| 273 | class IncrementalEncoder(codecs.BufferedIncrementalEncoder): |
| 274 | def _buffer_encode(self, input, errors, final): |
no test coverage detected