public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] portage r13779 - main/trunk/pym/portage
@ 2009-07-04 19:16 Zac Medico (zmedico)
  0 siblings, 0 replies; only message in thread
From: Zac Medico (zmedico) @ 2009-07-04 19:16 UTC (permalink / raw
  To: gentoo-commits

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_eof to
solve bug #228117. Thanks to Marat Radchenko <slonopotamusorama@gmail.com>
for this patch.


Modified: main/trunk/pym/portage/util.py
===================================================================
--- 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=-1)
 			return (newfile, StringIO())
 
-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 that
-	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 = object.__getattribute__(self, '_file').read(*args)
-		if rval and not args and rval[-1:] != "\n":
-			rval += "\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 = object.__getattribute__(self, '_file').readline(*args)
-		if rval and rval[-1:] != "\n":
-			rval += "\n"
-		if not rval:
-			object.__setattr__(self, '_got_eof', True)
-			rval = "\n"
-		return rval
-
-	def readlines(self, *args):
-		try:
-			object.__getattribute__(self, '_got_eof')
-			return []
-		except AttributeError:
-			pass
-		lines = object.__getattribute__(self, '_file').readlines(*args)
-		if lines and lines[-1][-1:] != "\n":
-			lines[-1] += "\n"
-		return lines
-
 def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
 	if isinstance(expand, dict):
 		# Some existing variable definitions have been
@@ -422,7 +363,10 @@
 		expand_map = {}
 	mykeys = {}
 	try:
-		f = _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 = StringIO("\n".join(open(mycfg, 'r').readlines()) + "\n")
 	except IOError, e:
 		if e.errno == PermissionDenied.errno:
 			raise PermissionDenied(mycfg)




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-07-04 19:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-04 19:16 [gentoo-commits] portage r13779 - main/trunk/pym/portage Zac Medico (zmedico)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox