File: _unicodefun.py

package info (click to toggle)
python-dynaconf 3.1.7-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,116 kB
  • sloc: python: 12,959; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 1,659 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import codecs,os
def _verify_python_env():
	M='.utf8';L='.utf-8';J=None;I='ascii'
	try:import locale as A;G=codecs.lookup(A.getpreferredencoding()).name
	except Exception:G=I
	if G!=I:return
	B=''
	if os.name=='posix':
		import subprocess as D
		try:C=D.Popen(['locale','-a'],stdout=D.PIPE,stderr=D.PIPE).communicate()[0]
		except OSError:C=b''
		E=set();H=False
		if isinstance(C,bytes):C=C.decode(I,'replace')
		for K in C.splitlines():
			A=K.strip()
			if A.lower().endswith((L,M)):
				E.add(A)
				if A.lower()in('c.utf8','c.utf-8'):H=True
		B+='\n\n'
		if not E:B+='Additional information: on this system no suitable UTF-8 locales were discovered. This most likely requires resolving by reconfiguring the locale system.'
		elif H:B+='This system supports the C.UTF-8 locale which is recommended. You might be able to resolve your issue by exporting the following environment variables:\n\n    export LC_ALL=C.UTF-8\n    export LANG=C.UTF-8'
		else:B+=f"This system lists some UTF-8 supporting locales that you can pick from. The following suitable locales were discovered: {', '.join(sorted(E))}"
		F=J
		for A in (os.environ.get('LC_ALL'),os.environ.get('LANG')):
			if A and A.lower().endswith((L,M)):F=A
			if A is not J:break
		if F is not J:B+=f"\n\nClick discovered that you exported a UTF-8 locale but the locale system could not pick up from it because it does not exist. The exported locale is {F!r} but it is not supported"
	raise RuntimeError(f"Click will abort further execution because Python was configured to use ASCII as encoding for the environment. Consult https://click.palletsprojects.com/unicode-support/ for mitigation steps.{B}")