Commit 3eec12b3 authored by Benjamin Peterson's avatar Benjamin Peterson

merge heads

parents a2f028c1 d0948df3
This diff is collapsed.
...@@ -2248,7 +2248,7 @@ features: ...@@ -2248,7 +2248,7 @@ features:
dirs.remove('CVS') # don't visit CVS directories dirs.remove('CVS') # don't visit CVS directories
In the next example, walking the tree bottom-up is essential: In the next example, walking the tree bottom-up is essential:
:func:`unlinkat` doesn't allow deleting a directory before the directory is :func:`rmdir` doesn't allow deleting a directory before the directory is
empty:: empty::
# Delete everything reachable from the directory named in "top", # Delete everything reachable from the directory named in "top",
...@@ -2258,9 +2258,9 @@ features: ...@@ -2258,9 +2258,9 @@ features:
import os import os
for root, dirs, files, rootfd in os.fwalk(top, topdown=False): for root, dirs, files, rootfd in os.fwalk(top, topdown=False):
for name in files: for name in files:
os.unlinkat(rootfd, name) os.unlink(name, dir_fd=rootfd)
for name in dirs: for name in dirs:
os.unlinkat(rootfd, name, os.AT_REMOVEDIR) os.rmdir(name, dir_fd=rootfd)
Availability: Unix. Availability: Unix.
......
This diff is collapsed.
...@@ -413,8 +413,10 @@ class GzipFile(io.BufferedIOBase): ...@@ -413,8 +413,10 @@ class GzipFile(io.BufferedIOBase):
if self.fileobj is None: if self.fileobj is None:
return b'' return b''
try: try:
# 1024 is the same buffering heuristic used in read() # Ensure that we don't return b"" if we haven't reached EOF.
self._read(max(n, 1024)) while self.extrasize == 0:
# 1024 is the same buffering heuristic used in read()
self._read(max(n, 1024))
except EOFError: except EOFError:
pass pass
offset = self.offset - self.extrastart offset = self.offset - self.extrastart
......
This diff is collapsed.
...@@ -313,6 +313,8 @@ class CGIHTTPServerTestCase(BaseTestCase): ...@@ -313,6 +313,8 @@ class CGIHTTPServerTestCase(BaseTestCase):
class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler): class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler):
pass pass
linesep = os.linesep.encode('ascii')
def setUp(self): def setUp(self):
BaseTestCase.setUp(self) BaseTestCase.setUp(self)
self.cwd = os.getcwd() self.cwd = os.getcwd()
...@@ -410,7 +412,7 @@ class CGIHTTPServerTestCase(BaseTestCase): ...@@ -410,7 +412,7 @@ class CGIHTTPServerTestCase(BaseTestCase):
def test_headers_and_content(self): def test_headers_and_content(self):
res = self.request('/cgi-bin/file1.py') res = self.request('/cgi-bin/file1.py')
self.assertEqual((b'Hello World\n', 'text/html', 200), self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200),
(res.read(), res.getheader('Content-type'), res.status)) (res.read(), res.getheader('Content-type'), res.status))
def test_post(self): def test_post(self):
...@@ -419,7 +421,7 @@ class CGIHTTPServerTestCase(BaseTestCase): ...@@ -419,7 +421,7 @@ class CGIHTTPServerTestCase(BaseTestCase):
headers = {'Content-type' : 'application/x-www-form-urlencoded'} headers = {'Content-type' : 'application/x-www-form-urlencoded'}
res = self.request('/cgi-bin/file2.py', 'POST', params, headers) res = self.request('/cgi-bin/file2.py', 'POST', params, headers)
self.assertEqual(res.read(), b'1, python, 123456\n') self.assertEqual(res.read(), b'1, python, 123456' + self.linesep)
def test_invaliduri(self): def test_invaliduri(self):
res = self.request('/cgi-bin/invalid') res = self.request('/cgi-bin/invalid')
...@@ -430,20 +432,20 @@ class CGIHTTPServerTestCase(BaseTestCase): ...@@ -430,20 +432,20 @@ class CGIHTTPServerTestCase(BaseTestCase):
headers = {b'Authorization' : b'Basic ' + headers = {b'Authorization' : b'Basic ' +
base64.b64encode(b'username:pass')} base64.b64encode(b'username:pass')}
res = self.request('/cgi-bin/file1.py', 'GET', headers=headers) res = self.request('/cgi-bin/file1.py', 'GET', headers=headers)
self.assertEqual((b'Hello World\n', 'text/html', 200), self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200),
(res.read(), res.getheader('Content-type'), res.status)) (res.read(), res.getheader('Content-type'), res.status))
def test_no_leading_slash(self): def test_no_leading_slash(self):
# http://bugs.python.org/issue2254 # http://bugs.python.org/issue2254
res = self.request('cgi-bin/file1.py') res = self.request('cgi-bin/file1.py')
self.assertEqual((b'Hello World\n', 'text/html', 200), self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200),
(res.read(), res.getheader('Content-type'), res.status)) (res.read(), res.getheader('Content-type'), res.status))
def test_os_environ_is_not_altered(self): def test_os_environ_is_not_altered(self):
signature = "Test CGI Server" signature = "Test CGI Server"
os.environ['SERVER_SOFTWARE'] = signature os.environ['SERVER_SOFTWARE'] = signature
res = self.request('/cgi-bin/file1.py') res = self.request('/cgi-bin/file1.py')
self.assertEqual((b'Hello World\n', 'text/html', 200), self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200),
(res.read(), res.getheader('Content-type'), res.status)) (res.read(), res.getheader('Content-type'), res.status))
self.assertEqual(os.environ['SERVER_SOFTWARE'], signature) self.assertEqual(os.environ['SERVER_SOFTWARE'], signature)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import unittest import unittest
import re import re
import contextlib import contextlib
import operator
import ipaddress import ipaddress
class BaseTestCase(unittest.TestCase): class BaseTestCase(unittest.TestCase):
...@@ -72,6 +73,14 @@ class CommonTestMixin: ...@@ -72,6 +73,14 @@ class CommonTestMixin:
with self.assertAddressError(re.escape(repr("1.0"))): with self.assertAddressError(re.escape(repr("1.0"))):
self.factory(1.0) self.factory(1.0)
def test_not_an_index_issue15559(self):
# Implementing __index__ makes for a very nasty interaction with the
# bytes constructor. Thus, we disallow implicit use as an integer
self.assertRaises(TypeError, operator.index, self.factory(1))
self.assertRaises(TypeError, hex, self.factory(1))
self.assertRaises(TypeError, bytes, self.factory(1))
class CommonTestMixin_v4(CommonTestMixin): class CommonTestMixin_v4(CommonTestMixin):
def test_leading_zeros(self): def test_leading_zeros(self):
...@@ -599,7 +608,6 @@ class IpaddrUnitTest(unittest.TestCase): ...@@ -599,7 +608,6 @@ class IpaddrUnitTest(unittest.TestCase):
self.assertEqual(first, last) self.assertEqual(first, last)
self.assertEqual(128, ipaddress._count_righthand_zero_bits(0, 128)) self.assertEqual(128, ipaddress._count_righthand_zero_bits(0, 128))
self.assertEqual("IPv4Network('1.2.3.0/24')", repr(self.ipv4_network)) self.assertEqual("IPv4Network('1.2.3.0/24')", repr(self.ipv4_network))
self.assertEqual('0x1020318', hex(self.ipv4_network))
def testMissingAddressVersion(self): def testMissingAddressVersion(self):
class Broken(ipaddress._BaseAddress): class Broken(ipaddress._BaseAddress):
...@@ -639,8 +647,8 @@ class IpaddrUnitTest(unittest.TestCase): ...@@ -639,8 +647,8 @@ class IpaddrUnitTest(unittest.TestCase):
ipv4 = ipaddress.ip_network('1.2.3.4') ipv4 = ipaddress.ip_network('1.2.3.4')
ipv6 = ipaddress.ip_network('2001:658:22a:cafe:200:0:0:1') ipv6 = ipaddress.ip_network('2001:658:22a:cafe:200:0:0:1')
self.assertEqual(ipv4, ipaddress.ip_network(int(ipv4))) self.assertEqual(ipv4, ipaddress.ip_network(int(ipv4.network_address)))
self.assertEqual(ipv6, ipaddress.ip_network(int(ipv6))) self.assertEqual(ipv6, ipaddress.ip_network(int(ipv6.network_address)))
v6_int = 42540616829182469433547762482097946625 v6_int = 42540616829182469433547762482097946625
self.assertEqual(self.ipv6_interface._ip, self.assertEqual(self.ipv6_interface._ip,
...@@ -723,8 +731,8 @@ class IpaddrUnitTest(unittest.TestCase): ...@@ -723,8 +731,8 @@ class IpaddrUnitTest(unittest.TestCase):
'2001:658:22a:cafe:ffff:ffff:ffff:ffff') '2001:658:22a:cafe:ffff:ffff:ffff:ffff')
def testGetPrefixlen(self): def testGetPrefixlen(self):
self.assertEqual(self.ipv4_interface.prefixlen, 24) self.assertEqual(self.ipv4_interface.network.prefixlen, 24)
self.assertEqual(self.ipv6_interface.prefixlen, 64) self.assertEqual(self.ipv6_interface.network.prefixlen, 64)
def testGetSupernet(self): def testGetSupernet(self):
self.assertEqual(self.ipv4_network.supernet().prefixlen, 23) self.assertEqual(self.ipv4_network.supernet().prefixlen, 23)
...@@ -1545,13 +1553,6 @@ class IpaddrUnitTest(unittest.TestCase): ...@@ -1545,13 +1553,6 @@ class IpaddrUnitTest(unittest.TestCase):
self.assertEqual(42540616829182469433547762482097946625, self.assertEqual(42540616829182469433547762482097946625,
int(self.ipv6_address)) int(self.ipv6_address))
def testHexRepresentation(self):
self.assertEqual(hex(0x1020304),
hex(self.ipv4_address))
self.assertEqual(hex(0x20010658022ACAFE0200000000000001),
hex(self.ipv6_address))
def testForceVersion(self): def testForceVersion(self):
self.assertEqual(ipaddress.ip_network(1).version, 4) self.assertEqual(ipaddress.ip_network(1).version, 4)
self.assertEqual(ipaddress.IPv6Network(1).version, 6) self.assertEqual(ipaddress.IPv6Network(1).version, 6)
......
...@@ -77,8 +77,12 @@ Core and Builtins ...@@ -77,8 +77,12 @@ Core and Builtins
Library Library
------- -------
- Issue #15546: Fix handling of pathological input data in the read1() method of - Issue #15559: To avoid a problematic failure mode when passed to the bytes
the BZ2File, GzipFile and LZMAFile classes. constructor, objects in the ipaddress module no longer implement __index__
(they still implement __int__ as appropriate)
- Issue #15546: Fix handling of pathological input data in the peek() and
read1() methods of the BZ2File, GzipFile and LZMAFile classes.
- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog - Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog
ended with '\'. Patch by Roger Serwy. ended with '\'. Patch by Roger Serwy.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment