1 |
On 5/19/16 9:38 AM, Michał Górny wrote: |
2 |
> Dnia 19 maja 2016 14:43:38 CEST, "Anthony G. Basile" <basile@××××××××××××××.edu> napisał(a): |
3 |
>> From: "Anthony G. Basile" <blueness@g.o> |
4 |
>> |
5 |
>> The current method to check for the system locale is to use python's |
6 |
>> ctypes.util.find_library() to construct a full library path to the |
7 |
>> system libc.so which is then passed to ctypes.CDLL(). However, |
8 |
>> this gets bogged down in implementation dependant details and |
9 |
>> fails with musl. |
10 |
>> |
11 |
>> We work around this design flaw in ctypes with a small python module |
12 |
>> written in C called 'portage_c_check_locale', and only fall back on |
13 |
>> the current ctypes-based check when this module is not available. |
14 |
>> |
15 |
>> This has been tested on glibc, uClibc and musl systems. |
16 |
>> |
17 |
>> X-Gentoo-bug: 571444 |
18 |
>> X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=571444 |
19 |
>> Signed-off-by: Anthony G. Basile <blueness@g.o> |
20 |
> |
21 |
> To be honest, I don't like this. Do we really want to duplicate all this, including duplicating the complete messages? This really looks messy and unmaintainable. |
22 |
> |
23 |
> The only reason libc functions were being used was to workaround the hacky built-in case conversion functions. And this is the only part where CDLL was really used. |
24 |
> |
25 |
> So please change this to provide trivial wrappers around the C library functions, and use them alternatively to ones obtained using CDLL. With a single common code doing all the check logic and messaging. |
26 |
> |
27 |
> |
28 |
|
29 |
ctypes is itself a problem and so hacky python built-ins were replaced |
30 |
by more hacky python. CDLL shouldn't be used at all. The other problem |
31 |
is that non utf-8 encodings cause problems much earlier in the portage |
32 |
codebase than the test for a sane environment, which is a bigger problem |
33 |
than this small issue. No one checked what happens with python2.7 + |
34 |
portage + exotic locale. Since I don't know where this might head in |
35 |
the future, I kinda like the standalone potential. The only repeated |
36 |
code here is the message. Nonetheless, I can reduce this to just two |
37 |
functions, and do something like the following. I assume that's what |
38 |
you're suggesting: |
39 |
|
40 |
try: |
41 |
from portage_c_convert_case import _c_toupper, _c_tolower |
42 |
libc_toupper = _c_toupper |
43 |
libc_lolower = _c_tolower |
44 |
except ImportError: |
45 |
libc_fn = find_library("c") |
46 |
if libc_fn is None: |
47 |
return None |
48 |
libc = LoadLibrary(libc_fn) |
49 |
if libc is None: |
50 |
return None |
51 |
libc_toupper = libc.toupper |
52 |
libc_tolower = libc.tolower |
53 |
|
54 |
|
55 |
Incidentally, another approach, one that I use in bash is as follows. I |
56 |
think it requires bash4, and I'm not sure how to pull this into python |
57 |
gracefully. |
58 |
|
59 |
l="abcdefghijklmnopqrstuvwxyz" |
60 |
u="ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
61 |
ru=${l^^} |
62 |
rl=${u,,} |
63 |
[[ $l == $rl ]] && echo "lower case okay" || echo "lower case bad" |
64 |
[[ $u == $ru ]] && echo "upper case okay" || echo "upper case bad" |
65 |
|
66 |
-- |
67 |
Anthony G. Basile, Ph. D. |
68 |
Chair of Information Technology |
69 |
D'Youville College |
70 |
Buffalo, NY 14201 |
71 |
(716) 829-8197 |