[Python-checkins] r81439 - in python/branches/release26-maint: Lib/linecache.py Lib/test/test_linecache.py Misc/NEWS

benjamin.peterson python-checkins at python.org
Fri May 21 23:45:16 CEST 2010


Author: benjamin.peterson
Date: Fri May 21 23:45:16 2010
New Revision: 81439
Log:
Merged revisions 81432 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk
........
 r81432 | benjamin.peterson | 2010年05月21日 16:31:24 -0500 (2010年5月21日) | 1 line
 
 ensure the last line has a trailing newline #8782
........
Modified:
 python/branches/release26-maint/ (props changed)
 python/branches/release26-maint/Lib/linecache.py
 python/branches/release26-maint/Lib/test/test_linecache.py
 python/branches/release26-maint/Misc/NEWS
Modified: python/branches/release26-maint/Lib/linecache.py
==============================================================================
--- python/branches/release26-maint/Lib/linecache.py	(original)
+++ python/branches/release26-maint/Lib/linecache.py	Fri May 21 23:45:16 2010
@@ -133,6 +133,8 @@
 except IOError, msg:
 ## print '*** Cannot open', fullname, ':', msg
 return []
+ if lines and not lines[-1].endswith('\n'):
+ lines[-1] += '\n'
 size, mtime = stat.st_size, stat.st_mtime
 cache[filename] = size, mtime, lines, fullname
 return lines
Modified: python/branches/release26-maint/Lib/test/test_linecache.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_linecache.py	(original)
+++ python/branches/release26-maint/Lib/test/test_linecache.py	Fri May 21 23:45:16 2010
@@ -31,6 +31,11 @@
 
 '''
 
+SOURCE_3 = '''
+def f():
+ return 3''' # No ending newline
+
+
 class LineCacheTests(unittest.TestCase):
 
 def test_getline(self):
@@ -63,6 +68,15 @@
 empty = linecache.getlines('a/b/c/__init__.py')
 self.assertEquals(empty, [])
 
+ def test_no_ending_newline(self):
+ try:
+ with open(support.TESTFN, "w") as fp:
+ fp.write(SOURCE_3)
+ lines = linecache.getlines(support.TESTFN)
+ self.assertEqual(lines, ["\n", "def f():\n", " return 3\n"])
+ finally:
+ support.unlink(support.TESTFN)
+
 def test_clearcache(self):
 cached = []
 for entry in TESTS:
Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Fri May 21 23:45:16 2010
@@ -55,6 +55,9 @@
 Library
 -------
 
+- Issue #8782: Add a trailing newline in linecache.updatecache to the last line
+ of files without one.
+
 - Issue #8729: Return NotImplemented from collections.Mapping.__eq__ when
 comparing to a non-mapping.
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /