From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1MNAj0-0005Mn-9s for garchives@archives.gentoo.org; Sat, 04 Jul 2009 19:16:38 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id ECB0DE0561; Sat, 4 Jul 2009 19:16:36 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id B1538E0561 for ; Sat, 4 Jul 2009 19:16:36 +0000 (UTC) Received: from stork.gentoo.org (stork.gentoo.org [64.127.104.133]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTP id 4FB33B48B0 for ; Sat, 4 Jul 2009 19:16:36 +0000 (UTC) Received: from zmedico by stork.gentoo.org with local (Exim 4.69) (envelope-from ) id 1MNAix-0005VK-Ti for gentoo-commits@lists.gentoo.org; Sat, 04 Jul 2009 19:16:35 +0000 To: gentoo-commits@lists.gentoo.org From: "Zac Medico (zmedico)" Subject: [gentoo-commits] portage r13779 - main/trunk/pym/portage X-VCS-Repository: portage X-VCS-Revision: 13779 X-VCS-Files: main/trunk/pym/portage/util.py X-VCS-Directories: main/trunk/pym/portage X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico Content-Type: text/plain; charset=UTF-8 Message-Id: Sender: Zac Medico Date: Sat, 04 Jul 2009 19:16:35 +0000 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 0a9d4f88-9130-4bf4-9a09-39faa29788a1 X-Archives-Hash: b618331a65f54da845e3e88dfab3e870 Author: zmedico Date: 2009-07-04 19:16:35 +0000 (Sat, 04 Jul 2009) New Revision: 13779 Modified: main/trunk/pym/portage/util.py Log: As a performance optimization, use StringIO instead of _insert_newline_eo= f to solve bug #228117. Thanks to Marat Radchenko for this patch. Modified: main/trunk/pym/portage/util.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- main/trunk/pym/portage/util.py 2009-07-04 19:11:51 UTC (rev 13778) +++ main/trunk/pym/portage/util.py 2009-07-04 19:16:35 UTC (rev 13779) @@ -353,65 +353,6 @@ (self.infile, str(e)), noiselevel=3D-1) return (newfile, StringIO()) =20 -class _insert_newline_eof(ObjectProxy): - """ - Read functions insert anywhere from 0 and 2 newlines just before eof. - This is useful as a workaround for avoiding a silent error in shlex tha= t - is triggered by a source statement at the end of the file without a - trailing newline after the source statement. - """ - - def __init__(self, *pargs, **kargs): - ObjectProxy.__init__(self) - object.__setattr__(self, '_file', open(*pargs, **kargs)) - - def _get_target(self): - return object.__getattribute__(self, '_file') - - def __getattribute__(self, attr): - if attr in ('read', 'readline', 'readlines'): - return object.__getattribute__(self, attr) - return getattr(object.__getattribute__(self, '_file'), attr) - - def read(self, *args): - try: - object.__getattribute__(self, '_got_eof') - return "" - except AttributeError: - pass - rval =3D object.__getattribute__(self, '_file').read(*args) - if rval and not args and rval[-1:] !=3D "\n": - rval +=3D "\n" - if not rval: - object.__setattr__(self, '_got_eof', True) - return "\n" - return rval - - def readline(self, *args): - try: - object.__getattribute__(self, '_got_eof') - return "" - except AttributeError: - pass - rval =3D object.__getattribute__(self, '_file').readline(*args) - if rval and rval[-1:] !=3D "\n": - rval +=3D "\n" - if not rval: - object.__setattr__(self, '_got_eof', True) - rval =3D "\n" - return rval - - def readlines(self, *args): - try: - object.__getattribute__(self, '_got_eof') - return [] - except AttributeError: - pass - lines =3D object.__getattribute__(self, '_file').readlines(*args) - if lines and lines[-1][-1:] !=3D "\n": - lines[-1] +=3D "\n" - return lines - def getconfig(mycfg, tolerant=3D0, allow_sourcing=3DFalse, expand=3DTrue= ): if isinstance(expand, dict): # Some existing variable definitions have been @@ -422,7 +363,10 @@ expand_map =3D {} mykeys =3D {} try: - f =3D _insert_newline_eof(mycfg) + # Workaround for avoiding a silent error in shlex that + # is triggered by a source statement at the end of the file without a + # trailing newline after the source statement + f =3D StringIO("\n".join(open(mycfg, 'r').readlines()) + "\n") except IOError, e: if e.errno =3D=3D PermissionDenied.errno: raise PermissionDenied(mycfg)