mirror of
https://github.com/python/cpython.git
synced 2025-09-25 17:59:57 +00:00
Merge
This commit is contained in:
commit
41da10e62c
8 changed files with 222 additions and 24 deletions
|
@ -135,9 +135,9 @@ def header_encode(header_bytes, charset='iso-8859-1'):
|
||||||
charset names the character set to use in the RFC 2046 header. It
|
charset names the character set to use in the RFC 2046 header. It
|
||||||
defaults to iso-8859-1.
|
defaults to iso-8859-1.
|
||||||
"""
|
"""
|
||||||
# Return empty headers unchanged
|
# Return empty headers as an empty string.
|
||||||
if not header_bytes:
|
if not header_bytes:
|
||||||
return str(header_bytes)
|
return ''
|
||||||
# Iterate over every byte, encoding if necessary.
|
# Iterate over every byte, encoding if necessary.
|
||||||
encoded = []
|
encoded = []
|
||||||
for octet in header_bytes:
|
for octet in header_bytes:
|
||||||
|
@ -268,7 +268,7 @@ def decode(encoded, eol=NL):
|
||||||
if i == n:
|
if i == n:
|
||||||
decoded += eol
|
decoded += eol
|
||||||
# Special case if original string did not end with eol
|
# Special case if original string did not end with eol
|
||||||
if not encoded.endswith(eol) and decoded.endswith(eol):
|
if encoded[-1] not in '\r\n' and decoded.endswith(eol):
|
||||||
decoded = decoded[:-1]
|
decoded = decoded[:-1]
|
||||||
return decoded
|
return decoded
|
||||||
|
|
||||||
|
|
|
@ -374,6 +374,13 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
|
||||||
forever = True
|
forever = True
|
||||||
elif o in ('-j', '--multiprocess'):
|
elif o in ('-j', '--multiprocess'):
|
||||||
use_mp = int(a)
|
use_mp = int(a)
|
||||||
|
if use_mp <= 0:
|
||||||
|
try:
|
||||||
|
import multiprocessing
|
||||||
|
# Use all cores + extras for tests that like to sleep
|
||||||
|
use_mp = 2 + multiprocessing.cpu_count()
|
||||||
|
except (ImportError, NotImplementedError):
|
||||||
|
use_mp = 3
|
||||||
elif o == '--header':
|
elif o == '--header':
|
||||||
header = True
|
header = True
|
||||||
elif o == '--slaveargs':
|
elif o == '--slaveargs':
|
||||||
|
|
|
@ -1389,9 +1389,8 @@ def args_from_interpreter_flags():
|
||||||
v = getattr(sys.flags, flag)
|
v = getattr(sys.flags, flag)
|
||||||
if v > 0:
|
if v > 0:
|
||||||
args.append('-' + opt * v)
|
args.append('-' + opt * v)
|
||||||
if sys.warnoptions:
|
for opt in sys.warnoptions:
|
||||||
args.append('-W')
|
args.append('-W' + opt)
|
||||||
args.extend(sys.warnoptions)
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
#============================================================
|
#============================================================
|
||||||
|
|
|
@ -3344,21 +3344,200 @@ class TestQuopri(unittest.TestCase):
|
||||||
c = chr(x)
|
c = chr(x)
|
||||||
self.assertEqual(quoprimime.unquote(quoprimime.quote(c)), c)
|
self.assertEqual(quoprimime.unquote(quoprimime.quote(c)), c)
|
||||||
|
|
||||||
def test_header_encode(self):
|
def _test_header_encode(self, header, expected_encoded_header, charset=None):
|
||||||
eq = self.assertEqual
|
if charset is None:
|
||||||
he = quoprimime.header_encode
|
encoded_header = quoprimime.header_encode(header)
|
||||||
eq(he(b'hello'), '=?iso-8859-1?q?hello?=')
|
else:
|
||||||
eq(he(b'hello', charset='iso-8859-2'), '=?iso-8859-2?q?hello?=')
|
encoded_header = quoprimime.header_encode(header, charset)
|
||||||
eq(he(b'hello\nworld'), '=?iso-8859-1?q?hello=0Aworld?=')
|
self.assertEqual(encoded_header, expected_encoded_header)
|
||||||
# Test a non-ASCII character
|
|
||||||
eq(he(b'hello\xc7there'), '=?iso-8859-1?q?hello=C7there?=')
|
|
||||||
|
|
||||||
def test_decode(self):
|
def test_header_encode_null(self):
|
||||||
eq = self.assertEqual
|
self._test_header_encode(b'', '')
|
||||||
eq(quoprimime.decode(''), '')
|
|
||||||
eq(quoprimime.decode('hello'), 'hello')
|
def test_header_encode_one_word(self):
|
||||||
eq(quoprimime.decode('hello', 'X'), 'hello')
|
self._test_header_encode(b'hello', '=?iso-8859-1?q?hello?=')
|
||||||
eq(quoprimime.decode('hello\nworld', 'X'), 'helloXworld')
|
|
||||||
|
def test_header_encode_two_lines(self):
|
||||||
|
self._test_header_encode(b'hello\nworld',
|
||||||
|
'=?iso-8859-1?q?hello=0Aworld?=')
|
||||||
|
|
||||||
|
def test_header_encode_non_ascii(self):
|
||||||
|
self._test_header_encode(b'hello\xc7there',
|
||||||
|
'=?iso-8859-1?q?hello=C7there?=')
|
||||||
|
|
||||||
|
def test_header_encode_alt_charset(self):
|
||||||
|
self._test_header_encode(b'hello', '=?iso-8859-2?q?hello?=',
|
||||||
|
charset='iso-8859-2')
|
||||||
|
|
||||||
|
def _test_header_decode(self, encoded_header, expected_decoded_header):
|
||||||
|
decoded_header = quoprimime.header_decode(encoded_header)
|
||||||
|
self.assertEqual(decoded_header, expected_decoded_header)
|
||||||
|
|
||||||
|
def test_header_decode_null(self):
|
||||||
|
self._test_header_decode('', '')
|
||||||
|
|
||||||
|
def test_header_decode_one_word(self):
|
||||||
|
self._test_header_decode('hello', 'hello')
|
||||||
|
|
||||||
|
def test_header_decode_two_lines(self):
|
||||||
|
self._test_header_decode('hello=0Aworld', 'hello\nworld')
|
||||||
|
|
||||||
|
def test_header_decode_non_ascii(self):
|
||||||
|
self._test_header_decode('hello=C7there', 'hello\xc7there')
|
||||||
|
|
||||||
|
def _test_decode(self, encoded, expected_decoded, eol=None):
|
||||||
|
if eol is None:
|
||||||
|
decoded = quoprimime.decode(encoded)
|
||||||
|
else:
|
||||||
|
decoded = quoprimime.decode(encoded, eol=eol)
|
||||||
|
self.assertEqual(decoded, expected_decoded)
|
||||||
|
|
||||||
|
def test_decode_null_word(self):
|
||||||
|
self._test_decode('', '')
|
||||||
|
|
||||||
|
def test_decode_null_line_null_word(self):
|
||||||
|
self._test_decode('\r\n', '\n')
|
||||||
|
|
||||||
|
def test_decode_one_word(self):
|
||||||
|
self._test_decode('hello', 'hello')
|
||||||
|
|
||||||
|
def test_decode_one_word_eol(self):
|
||||||
|
self._test_decode('hello', 'hello', eol='X')
|
||||||
|
|
||||||
|
def test_decode_one_line(self):
|
||||||
|
self._test_decode('hello\r\n', 'hello\n')
|
||||||
|
|
||||||
|
def test_decode_one_line_lf(self):
|
||||||
|
self._test_decode('hello\n', 'hello\n')
|
||||||
|
|
||||||
|
def test_decode_one_line_cr(self):
|
||||||
|
self._test_decode('hello\r', 'hello\n')
|
||||||
|
|
||||||
|
def test_decode_one_line_nl(self):
|
||||||
|
self._test_decode('hello\n', 'helloX', eol='X')
|
||||||
|
|
||||||
|
def test_decode_one_line_crnl(self):
|
||||||
|
self._test_decode('hello\r\n', 'helloX', eol='X')
|
||||||
|
|
||||||
|
def test_decode_one_line_one_word(self):
|
||||||
|
self._test_decode('hello\r\nworld', 'hello\nworld')
|
||||||
|
|
||||||
|
def test_decode_one_line_one_word_eol(self):
|
||||||
|
self._test_decode('hello\r\nworld', 'helloXworld', eol='X')
|
||||||
|
|
||||||
|
def test_decode_two_lines(self):
|
||||||
|
self._test_decode('hello\r\nworld\r\n', 'hello\nworld\n')
|
||||||
|
|
||||||
|
def test_decode_two_lines_eol(self):
|
||||||
|
self._test_decode('hello\r\nworld\r\n', 'helloXworldX', eol='X')
|
||||||
|
|
||||||
|
def test_decode_one_long_line(self):
|
||||||
|
self._test_decode('Spam' * 250, 'Spam' * 250)
|
||||||
|
|
||||||
|
def test_decode_one_space(self):
|
||||||
|
self._test_decode(' ', '')
|
||||||
|
|
||||||
|
def test_decode_multiple_spaces(self):
|
||||||
|
self._test_decode(' ' * 5, '')
|
||||||
|
|
||||||
|
def test_decode_one_line_trailing_spaces(self):
|
||||||
|
self._test_decode('hello \r\n', 'hello\n')
|
||||||
|
|
||||||
|
def test_decode_two_lines_trailing_spaces(self):
|
||||||
|
self._test_decode('hello \r\nworld \r\n', 'hello\nworld\n')
|
||||||
|
|
||||||
|
def test_decode_quoted_word(self):
|
||||||
|
self._test_decode('=22quoted=20words=22', '"quoted words"')
|
||||||
|
|
||||||
|
def test_decode_uppercase_quoting(self):
|
||||||
|
self._test_decode('ab=CD=EF', 'ab\xcd\xef')
|
||||||
|
|
||||||
|
def test_decode_lowercase_quoting(self):
|
||||||
|
self._test_decode('ab=cd=ef', 'ab\xcd\xef')
|
||||||
|
|
||||||
|
def test_decode_soft_line_break(self):
|
||||||
|
self._test_decode('soft line=\r\nbreak', 'soft linebreak')
|
||||||
|
|
||||||
|
def test_decode_false_quoting(self):
|
||||||
|
self._test_decode('A=1,B=A ==> A+B==2', 'A=1,B=A ==> A+B==2')
|
||||||
|
|
||||||
|
def _test_encode(self, body, expected_encoded_body, maxlinelen=None, eol=None):
|
||||||
|
kwargs = {}
|
||||||
|
if maxlinelen is None:
|
||||||
|
# Use body_encode's default.
|
||||||
|
maxlinelen = 76
|
||||||
|
else:
|
||||||
|
kwargs['maxlinelen'] = maxlinelen
|
||||||
|
if eol is None:
|
||||||
|
# Use body_encode's default.
|
||||||
|
eol = '\n'
|
||||||
|
else:
|
||||||
|
kwargs['eol'] = eol
|
||||||
|
encoded_body = quoprimime.body_encode(body, **kwargs)
|
||||||
|
self.assertEqual(encoded_body, expected_encoded_body)
|
||||||
|
if eol == '\n' or eol == '\r\n':
|
||||||
|
# We know how to split the result back into lines, so maxlinelen
|
||||||
|
# can be checked.
|
||||||
|
for line in encoded_body.splitlines():
|
||||||
|
self.assertLessEqual(len(line), maxlinelen)
|
||||||
|
|
||||||
|
def test_encode_null(self):
|
||||||
|
self._test_encode('', '')
|
||||||
|
|
||||||
|
def test_encode_null_lines(self):
|
||||||
|
self._test_encode('\n\n', '\n\n')
|
||||||
|
|
||||||
|
def test_encode_one_line(self):
|
||||||
|
self._test_encode('hello\n', 'hello\n')
|
||||||
|
|
||||||
|
def test_encode_one_line_crlf(self):
|
||||||
|
self._test_encode('hello\r\n', 'hello\n')
|
||||||
|
|
||||||
|
def test_encode_one_line_eol(self):
|
||||||
|
self._test_encode('hello\n', 'hello\r\n', eol='\r\n')
|
||||||
|
|
||||||
|
def test_encode_one_space(self):
|
||||||
|
self._test_encode(' ', '=20')
|
||||||
|
|
||||||
|
def test_encode_one_line_one_space(self):
|
||||||
|
self._test_encode(' \n', '=20\n')
|
||||||
|
|
||||||
|
def test_encode_one_word_trailing_spaces(self):
|
||||||
|
self._test_encode('hello ', 'hello =20')
|
||||||
|
|
||||||
|
def test_encode_one_line_trailing_spaces(self):
|
||||||
|
self._test_encode('hello \n', 'hello =20\n')
|
||||||
|
|
||||||
|
def test_encode_one_word_trailing_tab(self):
|
||||||
|
self._test_encode('hello \t', 'hello =09')
|
||||||
|
|
||||||
|
def test_encode_one_line_trailing_tab(self):
|
||||||
|
self._test_encode('hello \t\n', 'hello =09\n')
|
||||||
|
|
||||||
|
def test_encode_trailing_space_before_maxlinelen(self):
|
||||||
|
self._test_encode('abcd \n1234', 'abcd =\n\n1234', maxlinelen=6)
|
||||||
|
|
||||||
|
def test_encode_trailing_space_beyond_maxlinelen(self):
|
||||||
|
self._test_encode('abcd \n1234', 'abc=\nd =\n\n1234', maxlinelen=4)
|
||||||
|
|
||||||
|
def test_encode_quoted_equals(self):
|
||||||
|
self._test_encode('a = b', 'a =3D b')
|
||||||
|
|
||||||
|
def test_encode_one_long_string(self):
|
||||||
|
self._test_encode('x' * 100, 'x' * 75 + '=\n' + 'x' * 25)
|
||||||
|
|
||||||
|
def test_encode_one_long_line(self):
|
||||||
|
self._test_encode('x' * 100 + '\n', 'x' * 75 + '=\n' + 'x' * 25 + '\n')
|
||||||
|
|
||||||
|
def test_encode_one_very_long_line(self):
|
||||||
|
self._test_encode('x' * 200 + '\n',
|
||||||
|
2 * ('x' * 75 + '=\n') + 'x' * 50 + '\n')
|
||||||
|
|
||||||
|
def test_encode_one_long_line(self):
|
||||||
|
self._test_encode('x' * 100 + '\n', 'x' * 75 + '=\n' + 'x' * 25 + '\n')
|
||||||
|
|
||||||
|
def test_encode_shortest_maxlinelen(self):
|
||||||
|
self._test_encode('=' * 5, '=3D=\n' * 4 + '=3D', maxlinelen=4)
|
||||||
|
|
||||||
def test_encode(self):
|
def test_encode(self):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
|
|
|
@ -3,6 +3,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
import unittest
|
import unittest
|
||||||
|
from math import copysign
|
||||||
|
|
||||||
def disassemble(func):
|
def disassemble(func):
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
|
@ -207,6 +208,9 @@ class TestTranforms(unittest.TestCase):
|
||||||
def test_folding_of_unaryops_on_constants(self):
|
def test_folding_of_unaryops_on_constants(self):
|
||||||
for line, elem in (
|
for line, elem in (
|
||||||
('-0.5', '(-0.5)'), # unary negative
|
('-0.5', '(-0.5)'), # unary negative
|
||||||
|
('-0.0', '(-0.0)'), # -0.0
|
||||||
|
('-(1.0-1.0)','(-0.0)'), # -0.0 after folding
|
||||||
|
('-0', '(0)'), # -0
|
||||||
('~-2', '(1)'), # unary invert
|
('~-2', '(1)'), # unary invert
|
||||||
('+1', '(1)'), # unary positive
|
('+1', '(1)'), # unary positive
|
||||||
):
|
):
|
||||||
|
@ -214,6 +218,13 @@ class TestTranforms(unittest.TestCase):
|
||||||
self.assertIn(elem, asm, asm)
|
self.assertIn(elem, asm, asm)
|
||||||
self.assertNotIn('UNARY_', asm)
|
self.assertNotIn('UNARY_', asm)
|
||||||
|
|
||||||
|
# Check that -0.0 works after marshaling
|
||||||
|
def negzero():
|
||||||
|
return -(1.0-1.0)
|
||||||
|
|
||||||
|
self.assertNotIn('UNARY_', disassemble(negzero))
|
||||||
|
self.assertTrue(copysign(1.0, negzero()) < 0)
|
||||||
|
|
||||||
# Verify that unfoldables are skipped
|
# Verify that unfoldables are skipped
|
||||||
for line, elem in (
|
for line, elem in (
|
||||||
('-"abc"', "('abc')"), # unary negative
|
('-"abc"', "('abc')"), # unary negative
|
||||||
|
|
|
@ -867,6 +867,7 @@ Christian Tismer
|
||||||
Frank J. Tobin
|
Frank J. Tobin
|
||||||
R Lindsay Todd
|
R Lindsay Todd
|
||||||
Bennett Todd
|
Bennett Todd
|
||||||
|
Eugene Toder
|
||||||
Matias Torchinsky
|
Matias Torchinsky
|
||||||
Sandro Tosi
|
Sandro Tosi
|
||||||
Richard Townsend
|
Richard Townsend
|
||||||
|
|
|
@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #11244: Remove an unnecessary peepholer check that was preventing
|
||||||
|
negative zeros from being constant-folded properly.
|
||||||
|
|
||||||
- Issue #11395: io.FileIO().write() clamps the data length to 32,767 bytes on
|
- Issue #11395: io.FileIO().write() clamps the data length to 32,767 bytes on
|
||||||
Windows if the file is a TTY to workaround a Windows bug. The Windows console
|
Windows if the file is a TTY to workaround a Windows bug. The Windows console
|
||||||
returns an error (12: not enough space error) on writing into stdout if
|
returns an error (12: not enough space error) on writing into stdout if
|
||||||
|
|
|
@ -238,7 +238,7 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts, PyObject **ob
|
||||||
static int
|
static int
|
||||||
fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts, PyObject *v)
|
fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts, PyObject *v)
|
||||||
{
|
{
|
||||||
PyObject *newconst=NULL/*, *v*/;
|
PyObject *newconst;
|
||||||
Py_ssize_t len_consts;
|
Py_ssize_t len_consts;
|
||||||
int opcode;
|
int opcode;
|
||||||
|
|
||||||
|
@ -250,8 +250,6 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts, PyObject *v
|
||||||
opcode = codestr[3];
|
opcode = codestr[3];
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case UNARY_NEGATIVE:
|
case UNARY_NEGATIVE:
|
||||||
/* Preserve the sign of -0.0 */
|
|
||||||
if (PyObject_IsTrue(v) == 1)
|
|
||||||
newconst = PyNumber_Negative(v);
|
newconst = PyNumber_Negative(v);
|
||||||
break;
|
break;
|
||||||
case UNARY_INVERT:
|
case UNARY_INVERT:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue