From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Sun, 18 Nov 2007 04:52:03 +0300 From: Alexey Tourbin To: ALT Devel discussion list Message-ID: <20071118015203.GF4801@solemn.turbinal> Mail-Followup-To: ALT Devel discussion list References: <473E0BD7.9080704@altlinux.com> <20071117050109.GJ31452@solemn.turbinal> <473E9A73.2000300@altlinux.com> <20071118004113.GE4801@solemn.turbinal> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ExXT7PjY8AI4Hyfa" Content-Disposition: inline In-Reply-To: <20071118004113.GE4801@solemn.turbinal> Subject: Re: [devel] python encodings X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.9 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Nov 2007 01:52:04 -0000 Archived-At: List-Archive: List-Post: --ExXT7PjY8AI4Hyfa Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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:=20 > 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 > $$=20 >=20 > =F7=CF=CF=C2=DD=C5-=D4=CF MemoryError =D7 =C4=C1=CE=CE=CF=CD =D3=CC=D5=DE= =C1=C5 -- =DC=D4=CF =D0=C9=D4=CF=CE=CF=D7=D3=CB=C9=CA =C2=C1=C7 > http://bugs.python.org/issue979739 =FA=C4=C5=D3=D8 =CE=C1 =D3=C1=CD=CF=CD =C4=C5=CC=C5 =CE=C5=D4=D5 MemoryErro= r, =D0=CF=D4=CF=CD=D5 =DE=D4=CF =DA=C4=C5=D3=D8 =C5=D3=D4=D8 =CF=DB=C9=C2= =CF=DE=CB=C1 =D7 =D0=CF=D7=D4=CF=D2=CE=CF=CD =D7=D9=C2=D2=CF=D3=C5 =C9=D3=CB=CC=C0=DE=C5= =CE=C9=D1. =F1 =D4=CF=CC=D8=CB=CF =DE=D4=CF =DC=D4=CF =D0=CF=DE=C9=CE=C9= =CC =C9 =DA=C1=CF=C4=CE=CF =D3=C4=C5=CC=C1=CC =C2=CF=CC=C5=C5 =D4=CF=DE=CE=CF=C5 =CF=D0=D2=C5=C4=C5=CC= =C5=CE=C9=C5 =CD=CF=C4=D5=CC=D1 =CB=CF=C4=C9=D2=CF=D7=CB=C9, =C8=CF=D4=D1 = =DC=D4=CF =D7=D2=D1=C4 =CC=C9 =D2=C5=C1=CC=D8=CE=CF =C7=C4=C5-=CE=C9=C2=D5=C4=D8 =D0=CF=D4=D2=C5=C2=D5=C5= =D4=D3=D1. =F7=D0=D2=CF=DE=C5=CD, =D0=CF=D3=CD=CF=D4=D2=C9=CD. commit 683c7b2a82e80aeacf1ca1dcc7bc76470f58483a Author: Alexey Tourbin Date: Sun Nov 18 04:45:01 2007 +0300 python.req.py: implemented search for particular encodings module =20 $ 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=3Dcp1251 module=3Dencodings.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 =20 - def need_encoding(line): + missing_encodings =3D None + def get_encoding_module(enc) : + mod =3D 'encodings' + try : + from encodings import search_function + except : + missing_encodings =3D True + return mod + try : + mod =3D search_function(enc)[1].im_class.__module__ + print >> sys.stderr, "python.req: %s: encoding=3D%s module= =3D%s" % (src,enc,mod) + except : + pass + return mod + + def need_encoding_module(line): enc =3D get_raw_encoding(line) if enc : enc =3D get_enc_normal_name(enc) if enc not in ['utf-8','iso-8859-1'] : print >>sys.stderr, "python.req: %s: non-standard enco= ding: %s" % (src,enc) - return enc + mod =3D get_encoding_module(enc) + return mod =20 for src in files : ext =3D os.path.splitext(basename(src))[1] if ext not in ['.so','.pyc','.pyo','.pth'] : lines =3D [ line.rstrip().replace('\r','') for line in ope= n(src).readlines() ] - enc =3D None + encmod =3D None if len(lines) > 0 : - enc =3D need_encoding(lines[0]) - if not enc and len(lines) > 1 : - enc =3D need_encoding(lines[1]) - if enc : - print "%s(%s)" % (prefix,'encodings') + encmod =3D need_encoding_module(lines[0]) + if not encmod and len(lines) > 1 : + encmod =3D need_encoding_module(lines[1]) + if encmod : + print "%s(%s)" % (prefix,encmod) try : lis =3D parser.suite('\n'.join(lines)+'\n').tolist(lin= e_info=3D1) except StandardError,msg : print >> sys.stderr, 'python.req: ERROR: %s: %s' % (sr= c,msg) - if enc : - try : - import encodings - except : + if encmod and missing_encodings : print >> sys.stderr, "python.req: maybe you ne= ed python-modules-encodings" raise for item in match(lis) : --ExXT7PjY8AI4Hyfa Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFHP5rDfBKgtDjnu0YRAv0iAJ95CoEbH9JU2WpMTfbLnMsFG03p6gCdHKm6 MQOHwgbccMN+sTpzbuMPq6M= =GF5J -----END PGP SIGNATURE----- --ExXT7PjY8AI4Hyfa--