(line)
| 327 | return b'' |
| 328 | |
| 329 | def find_cookie(line): |
| 330 | try: |
| 331 | # Decode as UTF-8. Either the line is an encoding declaration, |
| 332 | # in which case it should be pure ASCII, or it must be UTF-8 |
| 333 | # per default encoding. |
| 334 | line_string = line.decode('utf-8') |
| 335 | except UnicodeDecodeError: |
| 336 | msg = "invalid or missing encoding declaration" |
| 337 | if filename is not None: |
| 338 | msg = '{} for {!r}'.format(msg, filename) |
| 339 | raise SyntaxError(msg) |
| 340 | |
| 341 | match = cookie_re.match(line_string) |
| 342 | if not match: |
| 343 | return None |
| 344 | encoding = _get_normal_name(match.group(1)) |
| 345 | try: |
| 346 | codec = lookup(encoding) |
| 347 | except LookupError: |
| 348 | # This behaviour mimics the Python interpreter |
| 349 | if filename is None: |
| 350 | msg = "unknown encoding: " + encoding |
| 351 | else: |
| 352 | msg = "unknown encoding for {!r}: {}".format(filename, |
| 353 | encoding) |
| 354 | raise SyntaxError(msg) |
| 355 | |
| 356 | if bom_found: |
| 357 | if encoding != 'utf-8': |
| 358 | # This behaviour mimics the Python interpreter |
| 359 | if filename is None: |
| 360 | msg = 'encoding problem: utf-8' |
| 361 | else: |
| 362 | msg = 'encoding problem for {!r}: utf-8'.format(filename) |
| 363 | raise SyntaxError(msg) |
| 364 | encoding += '-sig' |
| 365 | return encoding |
| 366 | |
| 367 | first = read_or_stop() |
| 368 | if first.startswith(BOM_UTF8): |
no test coverage detected