MCPcopy Index your code
hub / github.com/python/cpython / _parse_localename

Function _parse_localename

Lib/locale.py:471–508  ·  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

469 return localename
470
471def _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
510def _build_localename(localetuple):
511

Callers 2

_getdefaultlocaleFunction · 0.85
getlocaleFunction · 0.85

Calls 2

normalizeFunction · 0.70
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…