Skip to content
Myr

Added missing module

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent cf31c15 · Browse files · 2 files+112 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+112 added−0 removed

  • other:+112 added−0 removed

2 files+112 added−0 removed

added:click/_unicodefun.py+108 added
1import os2import sys3import codecs45import click6from ._compat import PY2789def _find_unicode_literals_frame():10 import __future__11 frm = sys._getframe(1)12 idx = 113 while frm is not None:14 if frm.f_globals.get('__name__', '').startswith('click.'):15 frm = frm.f_back16 idx += 117 elif frm.f_code.co_flags & __future__.unicode_literals.compiler_flag:18 return idx19 else:20 break21 return 0222324def _check_for_unicode_literals():25 if not __debug__:26 return27 if not PY2 or click.disable_unicode_literals_warning:28 return29 bad_frame = _find_unicode_literals_frame()30 if bad_frame <= 0:31 return32 from warnings import warn33 warn(Warning('Click detected the use of the unicode_literals '34 '__future__ import. This is heavily discouraged '35 'because it can introduce subtle bugs in your '36 'code. You should instead use explicit u"" literals '37 'for your unicode strings. For more information see '38 'http://click.pocoo.org/python3/'),39 stacklevel=bad_frame)404142def _verify_python3_env():43 """Ensures that the environment is good for unicode on Python 3."""44 if PY2:45 return46 try:47 import locale48 fs_enc = codecs.lookup(locale.getpreferredencoding()).name49 except Exception:50 fs_enc = 'ascii'51 if fs_enc != 'ascii':52 return5354 extra = ''55 if os.name == 'posix':56 import subprocess57 rv = subprocess.Popen(['locale', '-a'], stdout=subprocess.PIPE,58 stderr=subprocess.PIPE).communicate()[0]59 good_locales = set()60 has_c_utf8 = False61 for line in rv.splitlines():62 locale = line.strip()63 if locale.lower().endswith(('.utf-8', '.utf8')):64 good_locales.add(locale)65 if locale.lower() in ('c.utf8', 'c.utf-8'):66 has_c_utf8 = True6768 extra += '\n\n'69 if not good_locales:70 extra += (71 'Additional information: on this system no suitable UTF-8\n'72 'locales were discovered. This most likely requires resolving\n'73 'by reconfiguring the locale system.'74 )75 elif has_c_utf8:76 extra += (77 'This system supports the C.UTF-8 locale which is recommended.\n'78 'You might be able to resolve your issue by exporting the\n'79 'following environment variables:\n\n'80 ' export LC_ALL=C.UTF-8\n'81 ' export LANG=C.UTF-8'82 )83 else:84 extra += (85 'This system lists a couple of UTF-8 supporting locales that\n'86 'you can pick from. The following suitable locales where\n'87 'discovered: %s'88 ) % ', '.join(sorted(good_locales))8990 bad_locale = None91 for locale in os.environ.get('LC_ALL'), os.environ.get('LANG'):92 if locale and locale.lower().endswith(('.utf-8', '.utf8')):93 bad_locale = locale94 if locale is not None:95 break96 if bad_locale is not None:97 extra += (98 '\n\nClick discovered that you exported a UTF-8 locale\n'99 'but the locale system could not pick up from it because\n'100 'it does not exist. The exported locale is "%s" but it\n'101 'is not supported'102 ) % bad_locale103104 raise RuntimeError('Click will abort further execution because Python 3 '105 'was configured to use ASCII as encoding for the '106 'environment. Either run this under Python 2 or '107 'consult http://click.pocoo.org/python3/ for '108 'mitigation steps.' + extra)
modified:docs/python3.rst+4 added
137 unmodified lines
138139 export LC_ALL=C.UTF-8140 export LANG=C.UTF-8141142To see which locales are supported you can invoke ``locale -a``::143144 locale -a145146You need to do this before you invoke your Python script. If you are147curious about the reasons for this, you can join the discussions in the148Python 3 bug tracker:149
32 unmodified lines