summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-07-28 21:08:11 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-07-28 21:08:11 (GMT)
commitcf534817adc49b2562d175fabd3e3992d25063fe (patch)
treed2cb18e71d6b5cc25384146751b00c2172a327b6 /Lib
parent9e1af03fbb2a9fc1472ac866add02c99b0c88b16 (diff)
parentfc662ddda2bfd43b10c0a4f8a814e36445f22515 (diff)
downloadcpython-cf534817adc49b2562d175fabd3e3992d25063fe.zip
cpython-cf534817adc49b2562d175fabd3e3992d25063fe.tar.gz
cpython-cf534817adc49b2562d175fabd3e3992d25063fe.tar.bz2
Branch merge
Diffstat (limited to 'Lib')
-rw-r--r--Lib/idlelib/IOBinding.py2
-rw-r--r--Lib/pstats.py4
-rw-r--r--Lib/subprocess.py8
-rw-r--r--Lib/test/test_codecs.py2
-rw-r--r--Lib/test/test_locale.py6
-rw-r--r--Lib/test/test_posix.py4
-rw-r--r--Lib/test/test_subprocess.py58
-rw-r--r--Lib/test/test_urllib2net.py16
-rw-r--r--Lib/urllib/request.py8
9 files changed, 94 insertions, 14 deletions
diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py
index 3f5d556..d20c708 100644
--- a/Lib/idlelib/IOBinding.py
+++ b/Lib/idlelib/IOBinding.py
@@ -232,7 +232,7 @@ class IOBinding:
# before being able to execute the code
self.set_saved(False)
self.text.mark_set("insert", "1.0")
- self.text.see("insert")
+ self.text.yview("insert")
self.updaterecentfileslist(filename)
return True
diff --git a/Lib/pstats.py b/Lib/pstats.py
index 8a025cd..3f0add2 100644
--- a/Lib/pstats.py
+++ b/Lib/pstats.py
@@ -1,13 +1,9 @@
"""Class for printing reports on profiled python code."""
-# Class for printing reports on profiled python code. rev 1.0 4/1/94
-#
# Written by James Roskind
# Based on prior profile module by Sjoerd Mullender...
# which was hacked somewhat by: Guido van Rossum
-"""Class for profiling Python code."""
-
# Copyright Disney Enterprises, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement
#
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index ddbca6a..2d85b50 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1219,6 +1219,14 @@ class Popen(object):
os.close(errread)
os.close(errpipe_read)
+ # When duping fds, if there arises a situation
+ # where one of the fds is either 0, 1 or 2, it
+ # is possible that it is overwritten (#12607).
+ if c2pwrite == 0:
+ c2pwrite = os.dup(c2pwrite)
+ if errwrite == 0 or errwrite == 1:
+ errwrite = os.dup(errwrite)
+
# Dup fds for child
def _dup2(a, b):
# dup2() removes the CLOEXEC flag but
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 6b84023..4899a59 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -1234,7 +1234,7 @@ class CodecsModuleTest(unittest.TestCase):
def test_lookup_issue1813(self):
# Issue #1813: under Turkish locales, lookup of some codecs failed
# because 'I' is lowercased as "ı" (dotless i)
- oldlocale = locale.getlocale(locale.LC_CTYPE)
+ oldlocale = locale.setlocale(locale.LC_CTYPE)
self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
try:
locale.setlocale(locale.LC_CTYPE, 'tr_TR')
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
index 5155923..46e228e 100644
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -393,16 +393,16 @@ class TestMiscellaneous(unittest.TestCase):
def test_getsetlocale_issue1813(self):
# Issue #1813: setting and getting the locale under a Turkish locale
- oldlocale = locale.getlocale()
+ oldlocale = locale.setlocale(locale.LC_CTYPE)
self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
try:
locale.setlocale(locale.LC_CTYPE, 'tr_TR')
except locale.Error:
# Unsupported locale on this system
self.skipTest('test needs Turkish locale')
- loc = locale.getlocale()
+ loc = locale.getlocale(locale.LC_CTYPE)
locale.setlocale(locale.LC_CTYPE, loc)
- self.assertEqual(loc, locale.getlocale())
+ self.assertEqual(loc, locale.getlocale(locale.LC_CTYPE))
def test_main():
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 5563050..09f04ec 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -12,10 +12,12 @@ import os
import pwd
import shutil
import stat
+import tempfile
import unittest
import warnings
-_DUMMY_SYMLINK = '%s/dummy-symlink' % os.getenv('TMPDIR', '/tmp')
+_DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(),
+ support.TESTFN + '-dummy-symlink')
class PosixTester(unittest.TestCase):
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 3440b45..8382c72 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1106,6 +1106,64 @@ class POSIXProcessTestCase(BaseTestCase):
for fd in temp_fds:
os.close(fd)
+ def check_swap_fds(self, stdin_no, stdout_no, stderr_no):
+ # open up some temporary files
+ temps = [mkstemp() for i in range(3)]
+ temp_fds = [fd for fd, fname in temps]
+ try:
+ # unlink the files -- we won't need to reopen them
+ for fd, fname in temps:
+ os.unlink(fname)
+
+ # save a copy of the standard file descriptors
+ saved_fds = [os.dup(fd) for fd in range(3)]
+ try:
+ # duplicate the temp files over the standard fd's 0, 1, 2
+ for fd, temp_fd in enumerate(temp_fds):
+ os.dup2(temp_fd, fd)
+
+ # write some data to what will become stdin, and rewind
+ os.write(stdin_no, b"STDIN")
+ os.lseek(stdin_no, 0, 0)
+
+ # now use those files in the given order, so that subprocess
+ # has to rearrange them in the child
+ p = subprocess.Popen([sys.executable, "-c",
+ 'import sys; got = sys.stdin.read();'
+ 'sys.stdout.write("got %s"%got); sys.stderr.write("err")'],
+ stdin=stdin_no,
+ stdout=stdout_no,
+ stderr=stderr_no)
+ p.wait()
+
+ for fd in temp_fds:
+ os.lseek(fd, 0, 0)
+
+ out = os.read(stdout_no, 1024)
+ err = support.strip_python_stderr(os.read(stderr_no, 1024))
+ finally:
+ for std, saved in enumerate(saved_fds):
+ os.dup2(saved, std)
+ os.close(saved)
+
+ self.assertEqual(out, b"got STDIN")
+ self.assertEqual(err, b"err")
+
+ finally:
+ for fd in temp_fds:
+ os.close(fd)
+
+ # When duping fds, if there arises a situation where one of the fds is
+ # either 0, 1 or 2, it is possible that it is overwritten (#12607).
+ # This tests all combinations of this.
+ def test_swap_fds(self):
+ self.check_swap_fds(0, 1, 2)
+ self.check_swap_fds(0, 2, 1)
+ self.check_swap_fds(1, 0, 2)
+ self.check_swap_fds(1, 2, 0)
+ self.check_swap_fds(2, 0, 1)
+ self.check_swap_fds(2, 1, 0)
+
def test_surrogates_error_message(self):
def prepare():
raise ValueError("surrogate:\uDCff")
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py
index a475f56..cd225c9 100644
--- a/Lib/test/test_urllib2net.py
+++ b/Lib/test/test_urllib2net.py
@@ -174,6 +174,22 @@ class OtherNetworkTests(unittest.TestCase):
opener.open(request)
self.assertEqual(request.get_header('User-agent'),'Test-Agent')
+ def test_sites_no_connection_close(self):
+ # Some sites do not send Connection: close header.
+ # Verify that those work properly. (#issue12576)
+
+ try:
+ with urllib.request.urlopen('http://www.imdb.com') as res:
+ pass
+ except ValueError as e:
+ self.fail("urlopen failed for sites not sending Connection:close")
+ else:
+ self.assertTrue(res)
+
+ req = urllib.request.urlopen('http://www.imdb.com')
+ res = req.read()
+ self.assertTrue(res)
+
def _test_urls(self, urls, handlers, retry=True):
import time
import logging
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index a09a353..1dda966 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1134,11 +1134,11 @@ class AbstractHTTPHandler(BaseHandler):
try:
h.request(req.get_method(), req.selector, req.data, headers)
- r = h.getresponse() # an HTTPResponse instance
- except socket.error as err:
- raise URLError(err)
- finally:
+ except socket.error as err: # timeout error
h.close()
+ raise URLError(err)
+ else:
+ r = h.getresponse()
r.url = req.get_full_url()
# This line replaces the .msg attribute of the HTTPResponse