On Sun, Nov 18, 2007 at 03:41:13AM +0300, Alexey Tourbin wrote: > $ 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 Здесь на самом деле нету MemoryError, потому что здесь есть ошибочка в повторном выбросе исключения. Я только что это починил и заодно сделал более точное определение модуля кодировки, хотя это вряд ли реально где-нибудь потребуется. Впрочем, посмотрим. commit 683c7b2a82e80aeacf1ca1dcc7bc76470f58483a Author: Alexey Tourbin Date: Sun Nov 18 04:45:01 2007 +0300 python.req.py: implemented search for particular encodings module $ cat test2.py # coding: cp1251 $ ./rpm-build-python/python.req.py test2.py python.req: test2.py: non-standard encoding: cp1251 python.req: test2.py: encoding=cp1251 module=encodings.cp1251 python2.4(encodings.cp1251) $ diff --git a/rpm-build-python/python.req.py b/rpm-build-python/python.req.py index 53b3886..52b7e0c 100755 --- a/rpm-build-python/python.req.py +++ b/rpm-build-python/python.req.py @@ -150,33 +150,46 @@ else : return 'iso-8859-1' return enc - def need_encoding(line): + missing_encodings = None + def get_encoding_module(enc) : + mod = 'encodings' + try : + from encodings import search_function + except : + missing_encodings = True + return mod + try : + mod = search_function(enc)[1].im_class.__module__ + print >> sys.stderr, "python.req: %s: encoding=%s module=%s" % (src,enc,mod) + except : + pass + return mod + + def need_encoding_module(line): enc = get_raw_encoding(line) if enc : enc = get_enc_normal_name(enc) if enc not in ['utf-8','iso-8859-1'] : print >>sys.stderr, "python.req: %s: non-standard encoding: %s" % (src,enc) - return enc + mod = get_encoding_module(enc) + return mod for src in files : ext = os.path.splitext(basename(src))[1] if ext not in ['.so','.pyc','.pyo','.pth'] : lines = [ line.rstrip().replace('\r','') for line in open(src).readlines() ] - enc = None + encmod = None if len(lines) > 0 : - enc = need_encoding(lines[0]) - if not enc and len(lines) > 1 : - enc = need_encoding(lines[1]) - if enc : - print "%s(%s)" % (prefix,'encodings') + encmod = need_encoding_module(lines[0]) + if not encmod and len(lines) > 1 : + encmod = need_encoding_module(lines[1]) + if encmod : + print "%s(%s)" % (prefix,encmod) try : lis = parser.suite('\n'.join(lines)+'\n').tolist(line_info=1) except StandardError,msg : print >> sys.stderr, 'python.req: ERROR: %s: %s' % (src,msg) - if enc : - try : - import encodings - except : + if encmod and missing_encodings : print >> sys.stderr, "python.req: maybe you need python-modules-encodings" raise for item in match(lis) :