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)
| 469 | return localename |
| 470 | |
| 471 | def _parse_localename(localename): |
| 472 | |
| 473 | """ Parses the locale code for localename and returns the |
| 474 | result as tuple (language code, encoding). |
| 475 | |
| 476 | The localename is normalized and passed through the locale |
| 477 | alias engine. A ValueError is raised in case the locale name |
| 478 | cannot be parsed. |
| 479 | |
| 480 | The language code corresponds to RFC 1766. code and encoding |
| 481 | can be None in case the values cannot be determined or are |
| 482 | unknown to this implementation. |
| 483 | |
| 484 | """ |
| 485 | code = normalize(localename) |
| 486 | if '@' in code: |
| 487 | # Deal with locale modifiers |
| 488 | code, modifier = code.split('@', 1) |
| 489 | if modifier == 'euro' and '.' not in code: |
| 490 | # Assume ISO8859-15 for @euro locales. Do note that some systems |
| 491 | # may use other encodings for these locales, so this may not always |
| 492 | # be correct. |
| 493 | return code + '@euro', 'ISO8859-15' |
| 494 | else: |
| 495 | modifier = '' |
| 496 | |
| 497 | if '.' in code: |
| 498 | code, encoding = code.split('.')[:2] |
| 499 | if modifier: |
| 500 | code += '@' + modifier |
| 501 | return code, encoding |
| 502 | elif code == 'C': |
| 503 | return None, None |
| 504 | elif code == 'UTF-8': |
| 505 | # On macOS "LC_CTYPE=UTF-8" is a valid locale setting |
| 506 | # for getting UTF-8 handling for text. |
| 507 | return None, 'UTF-8' |
| 508 | raise ValueError('unknown locale: %s' % localename) |
| 509 | |
| 510 | def _build_localename(localetuple): |
| 511 |
no test coverage detected
searching dependent graphs…