MCPcopy Index your code
hub / github.com/RustPython/RustPython / _parse_localename

Function _parse_localename

Lib/locale.py:469–501  ·  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 code corr

(localename)

Source from the content-addressed store, hash-verified

467 return localename
468
469def _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
503def _build_localename(localetuple):
504

Callers 2

_getdefaultlocaleFunction · 0.85
getlocaleFunction · 0.85

Calls 2

normalizeFunction · 0.70
splitMethod · 0.45

Tested by

no test coverage detected