ALT Linux Team development discussions
 help / color / mirror / Atom feed
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 04:52:03 +0300
Message-ID: <20071118015203.GF4801@solemn.turbinal> (raw)
In-Reply-To: <20071118004113.GE4801@solemn.turbinal>

[-- Attachment #1: Type: text/plain, Size: 4071 bytes --]

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 <at@altlinux>
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) :

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

      reply	other threads:[~2007-11-18  1:52 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
2007-11-18  1:52       ` Alexey Tourbin [this message]

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=20071118015203.GF4801@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