(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'))
| 555 | |
| 556 | |
| 557 | def _getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')): |
| 558 | try: |
| 559 | # check if it's supported by the _locale module |
| 560 | import _locale |
| 561 | code, encoding = _locale._getdefaultlocale() |
| 562 | except (ImportError, AttributeError): |
| 563 | pass |
| 564 | else: |
| 565 | # make sure the code/encoding values are valid |
| 566 | if sys.platform == "win32" and code and code[:2] == "0x": |
| 567 | # map windows language identifier to language name |
| 568 | code = windows_locale.get(int(code, 0)) |
| 569 | # ...add other platform-specific processing here, if |
| 570 | # necessary... |
| 571 | return code, encoding |
| 572 | |
| 573 | # fall back on POSIX behaviour |
| 574 | import os |
| 575 | lookup = os.environ.get |
| 576 | for variable in envvars: |
| 577 | localename = lookup(variable,None) |
| 578 | if localename: |
| 579 | if variable == 'LANGUAGE': |
| 580 | localename = localename.split(':')[0] |
| 581 | break |
| 582 | else: |
| 583 | localename = 'C' |
| 584 | return _parse_localename(localename) |
| 585 | |
| 586 | |
| 587 | def getlocale(category=LC_CTYPE): |
no test coverage detected