MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _parse_localename

Function _parse_localename

tools/python-3.11.9-amd64/Lib/locale.py:479–511  ·  view source on GitHub ↗

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 co

(localename)

Source from the content-addressed store, hash-verified

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

Callers 2

getdefaultlocaleFunction · 0.85
getlocaleFunction · 0.85

Calls 3

tupleClass · 0.85
normalizeFunction · 0.70
splitMethod · 0.45

Tested by

no test coverage detected