From: Alexey Tourbin <at@altlinux.ru>
To: ALT Devel discussion list <devel@lists.altlinux.org>
Subject: Re: [devel] python encodings
Date: Sun, 18 Nov 2007 03:41:13 +0300
Message-ID: <20071118004113.GE4801@solemn.turbinal> (raw)
In-Reply-To: <473E9A73.2000300@altlinux.com>
[-- Attachment #1: Type: text/plain, Size: 4413 bytes --]
On Sat, Nov 17, 2007 at 10:38:27AM +0300, Anton Farygin wrote:
> Мне кажется, что достаточно было бы вывести вменяемую диагностику. По
> крайней мере в моём случае.
Я сделал вменяемую диагностику, насколько это возможно.
$ hsh --init
..
rpm-build-python-0.32-alt1
...
$ hsh-shell
$$ cd
$$ echo '# coding: utf8' >test.py
$$ /usr/lib/rpm/python.req test.py
python.req: test.py: non-standard encoding: utf8
python2.4(encodings)
python.req: ERROR: test.py:
python.req: maybe you need python-modules-encodings
Traceback (most recent call last):
File "/usr/lib/rpm/python.req.py", line 178, in ?
import encodings
ImportError: No module named encodings
$$
Вообще-то MemoryError в данном случае -- это питоновский баг
http://bugs.python.org/issue979739
> > Думаю, захачить на эту тему python-base или нет. То есть чтобы он
> > понимал побольше настандартных алиасов для стандартных кодировок,
> > без заглядывания в encodings.
>
> Если нестантартные алиасы являются стандартом де-факто (т.е. -
> значительно распространены), то видимо стоит хачить питон. В обратном
> случаае - выводить вменяемую диагностику и патчить приложения.
Посмотрим, насколько они распространены.
Parser/tokenizer.c:
183 static char *
184 get_normal_name(char *s) /* for utf-8 and latin-1 */
185 {
186 char buf[13];
187 int i;
188 for (i = 0; i < 12; i++) {
189 int c = s[i];
190 if (c == '\0') break;
191 else if (c == '_') buf[i] = '-';
192 else buf[i] = tolower(c);
193 }
194 buf[i] = '\0';
195 if (i > 3) { /* at least 4 characters */
196 const char *p = NULL;
197 switch (buf[0]) {
198 case 'u':
199 if (strncmp(buf, "utf-8", 5) == 0)
200 p = buf + 5;
201 else if (strncmp(buf, "utf8", 4) == 0)
202 p = buf + 4;
203 if (p && (*p == '\0' || *p == '-'))
204 return "utf-8";
205 break;
206 case 'i':
207 if (strncmp(buf, "utf-8") == 0)
208 p = buf + 5;
209
210
211
212 if (strcmp(buf, "utf-8") == 0 ||
213 strncmp(buf, "utf-8-", 6) == 0) return "utf-8";
214 else if (strcmp(buf, "latin-1") == 0 ||
215 strcmp(buf, "iso-8859-1") == 0 ||
216 strcmp(buf, "iso-latin-1") == 0 ||
217 strncmp(buf, "latin-1-", 8) == 0 ||
218 strncmp(buf, "iso-8859-1-", 11) == 0 ||
219 strncmp(buf, "iso-latin-1-", 12) == 0) return "iso-8859-1";
220 else return s;gg
221 }
То есть у питона есть две стандартные кодировки, для которых почти
ничего не нужно -- utf-8 и iso-8859-1. Но в модуле encodings
определяются дополнительные алиасы, в том числе для стандартных
кодировок.
Lib/encodings/aliases.py:
395 # latin_1 codec
396 '8859' : 'latin_1',
397 'cp819' : 'latin_1',
398 'csisolatin1' : 'latin_1',
399 'ibm819' : 'latin_1',
400 'iso8859' : 'latin_1',
401 'iso_8859_1' : 'latin_1',
402 'iso_8859_1_1987' : 'latin_1',
403 'iso_ir_100' : 'latin_1',
404 'l1' : 'latin_1',
405 'latin' : 'latin_1',
406 'latin1' : 'latin_1',
...
486 # utf_8 codec
487 'u8' : 'utf_8',
488 'utf' : 'utf_8',
489 'utf8' : 'utf_8',
490 'utf8_ucs2' : 'utf_8',
491 'utf8_ucs4' : 'utf_8',
Есть искушение внести некоторые из этих алисов в Parser/tokenizer.c,
чтобы уменьшить число падений при отсутствии encodings/aliases.py.
Посмотрим, что будет по результатам пересборки с новым rpm-build-python.
Потому что теперь в python.req.py будет диагностика "non-standard encoding:",
которая мимикрирует проверку в Parser/tokenizer.c.
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2007-11-18 0:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-16 21:29 [devel] help me! python.req! Anton Farygin
2007-11-16 21:46 ` Anton Farygin
2007-11-16 22:04 ` Alexey Tourbin
2007-11-16 22:04 ` Anton Farygin
2007-11-17 5:01 ` [devel] python encodings Alexey Tourbin
2007-11-17 7:38 ` Anton Farygin
2007-11-18 0:41 ` Alexey Tourbin [this message]
2007-11-18 1:52 ` Alexey Tourbin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071118004113.GE4801@solemn.turbinal \
--to=at@altlinux.ru \
--cc=devel@lists.altlinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
ALT Linux Team development discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
public-inbox-index devel
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.devel
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git