Parses the locale code for localename and returns the result as tuple (language code, encoding). The localename is normalized and passed through the locale alias engine. A ValueError is raised in case the locale name cannot be parsed. The language code corr
(localename)
| 467 | return localename |
| 468 | |
| 469 | def _parse_localename(localename): |
| 470 | |
| 471 | """ Parses the locale code for localename and returns the |
| 472 | result as tuple (language code, encoding). |
| 473 | |
| 474 | The localename is normalized and passed through the locale |
| 475 | alias engine. A ValueError is raised in case the locale name |
| 476 | cannot be parsed. |
| 477 | |
| 478 | The language code corresponds to RFC 1766. code and encoding |
| 479 | can be None in case the values cannot be determined or are |
| 480 | unknown to this implementation. |
| 481 | |
| 482 | """ |
| 483 | code = normalize(localename) |
| 484 | if '@' in code: |
| 485 | # Deal with locale modifiers |
| 486 | code, modifier = code.split('@', 1) |
| 487 | if modifier == 'euro' and '.' not in code: |
| 488 | # Assume Latin-9 for @euro locales. This is bogus, |
| 489 | # since some systems may use other encodings for these |
| 490 | # locales. Also, we ignore other modifiers. |
| 491 | return code, 'iso-8859-15' |
| 492 | |
| 493 | if '.' in code: |
| 494 | return tuple(code.split('.')[:2]) |
| 495 | elif code == 'C': |
| 496 | return None, None |
| 497 | elif code == 'UTF-8': |
| 498 | # On macOS "LC_CTYPE=UTF-8" is a valid locale setting |
| 499 | # for getting UTF-8 handling for text. |
| 500 | return None, 'UTF-8' |
| 501 | raise ValueError('unknown locale: %s' % localename) |
| 502 | |
| 503 | def _build_localename(localetuple): |
| 504 |
no test coverage detected