Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
41da10e6
Commit
41da10e6
authored
Mar 23, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
2ebea41d
5839b963
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
222 additions
and
24 deletions
+222
-24
Lib/email/quoprimime.py
Lib/email/quoprimime.py
+3
-3
Lib/test/regrtest.py
Lib/test/regrtest.py
+7
-0
Lib/test/support.py
Lib/test/support.py
+2
-3
Lib/test/test_email/test_email.py
Lib/test/test_email/test_email.py
+193
-14
Lib/test/test_peepholer.py
Lib/test/test_peepholer.py
+11
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
Python/peephole.c
Python/peephole.c
+2
-4
No files found.
Lib/email/quoprimime.py
View file @
41da10e6
...
...
@@ -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
defaults to iso-8859-1.
"""
# Return empty headers
unchanged
# Return empty headers
as an empty string.
if
not
header_bytes
:
return
str
(
header_bytes
)
return
''
# Iterate over every byte, encoding if necessary.
encoded
=
[]
for
octet
in
header_bytes
:
...
...
@@ -268,7 +268,7 @@ def decode(encoded, eol=NL):
if
i
==
n
:
decoded
+=
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
]
return
decoded
...
...
Lib/test/regrtest.py
View file @
41da10e6
...
...
@@ -374,6 +374,13 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
forever
=
True
elif
o
in
(
'-j'
,
'--multiprocess'
):
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'
:
header
=
True
elif
o
==
'--slaveargs'
:
...
...
Lib/test/support.py
View file @
41da10e6
...
...
@@ -1389,9 +1389,8 @@ def args_from_interpreter_flags():
v
=
getattr
(
sys
.
flags
,
flag
)
if
v
>
0
:
args
.
append
(
'-'
+
opt
*
v
)
if
sys
.
warnoptions
:
args
.
append
(
'-W'
)
args
.
extend
(
sys
.
warnoptions
)
for
opt
in
sys
.
warnoptions
:
args
.
append
(
'-W'
+
opt
)
return
args
#============================================================
...
...
Lib/test/test_email/test_email.py
View file @
41da10e6
...
...
@@ -3344,21 +3344,200 @@ class TestQuopri(unittest.TestCase):
c
=
chr
(
x
)
self
.
assertEqual
(
quoprimime
.
unquote
(
quoprimime
.
quote
(
c
)),
c
)
def
test_header_encode
(
self
):
eq
=
self
.
assertEqual
he
=
quoprimime
.
header_encode
eq
(
he
(
b'hello'
),
'=?iso-8859-1?q?hello?='
)
eq
(
he
(
b'hello'
,
charset
=
'iso-8859-2'
),
'=?iso-8859-2?q?hello?='
)
eq
(
he
(
b'hello
\
n
world'
),
'=?iso-8859-1?q?hello=0Aworld?='
)
# Test a non-ASCII character
eq
(
he
(
b'hello
\
xc7
there'
),
'=?iso-8859-1?q?hello=C7there?='
)
def
_test_header_encode
(
self
,
header
,
expected_encoded_header
,
charset
=
None
):
if
charset
is
None
:
encoded_header
=
quoprimime
.
header_encode
(
header
)
else
:
encoded_header
=
quoprimime
.
header_encode
(
header
,
charset
)
self
.
assertEqual
(
encoded_header
,
expected_encoded_header
)
def
test_decode
(
self
):
eq
=
self
.
assertEqual
eq
(
quoprimime
.
decode
(
''
),
''
)
eq
(
quoprimime
.
decode
(
'hello'
),
'hello'
)
eq
(
quoprimime
.
decode
(
'hello'
,
'X'
),
'hello'
)
eq
(
quoprimime
.
decode
(
'hello
\
n
world'
,
'X'
),
'helloXworld'
)
def
test_header_encode_null
(
self
):
self
.
_test_header_encode
(
b''
,
''
)
def
test_header_encode_one_word
(
self
):
self
.
_test_header_encode
(
b'hello'
,
'=?iso-8859-1?q?hello?='
)
def
test_header_encode_two_lines
(
self
):
self
.
_test_header_encode
(
b'hello
\
n
world'
,
'=?iso-8859-1?q?hello=0Aworld?='
)
def
test_header_encode_non_ascii
(
self
):
self
.
_test_header_encode
(
b'hello
\
xc7
there'
,
'=?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
\
n
world'
)
def
test_header_decode_non_ascii
(
self
):
self
.
_test_header_decode
(
'hello=C7there'
,
'hello
\
xc7
there'
)
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
\
n
world'
,
'hello
\
n
world'
)
def
test_decode_one_line_one_word_eol
(
self
):
self
.
_test_decode
(
'hello
\
r
\
n
world'
,
'helloXworld'
,
eol
=
'X'
)
def
test_decode_two_lines
(
self
):
self
.
_test_decode
(
'hello
\
r
\
n
world
\
r
\
n
'
,
'hello
\
n
world
\
n
'
)
def
test_decode_two_lines_eol
(
self
):
self
.
_test_decode
(
'hello
\
r
\
n
world
\
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
\
n
world
\
r
\
n
'
,
'hello
\
n
world
\
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
\
n
break'
,
'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
\
n
1234'
,
'abcd =
\
n
\
n
1234'
,
maxlinelen
=
6
)
def
test_encode_trailing_space_beyond_maxlinelen
(
self
):
self
.
_test_encode
(
'abcd
\
n
1234'
,
'abc=
\
n
d =
\
n
\
n
1234'
,
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
):
eq
=
self
.
assertEqual
...
...
Lib/test/test_peepholer.py
View file @
41da10e6
...
...
@@ -3,6 +3,7 @@ import re
import
sys
from
io
import
StringIO
import
unittest
from
math
import
copysign
def
disassemble
(
func
):
f
=
StringIO
()
...
...
@@ -207,6 +208,9 @@ class TestTranforms(unittest.TestCase):
def
test_folding_of_unaryops_on_constants
(
self
):
for
line
,
elem
in
(
(
'-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
(
'+1'
,
'(1)'
),
# unary positive
):
...
...
@@ -214,6 +218,13 @@ class TestTranforms(unittest.TestCase):
self
.
assertIn
(
elem
,
asm
,
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
for
line
,
elem
in
(
(
'-"abc"'
,
"('abc')"
),
# unary negative
...
...
Misc/ACKS
View file @
41da10e6
...
...
@@ -867,6 +867,7 @@ Christian Tismer
Frank J. Tobin
R Lindsay Todd
Bennett Todd
Eugene Toder
Matias Torchinsky
Sandro Tosi
Richard Townsend
...
...
Misc/NEWS
View file @
41da10e6
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
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
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
...
...
Python/peephole.c
View file @
41da10e6
...
...
@@ -238,7 +238,7 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts, PyObject **ob
static
int
fold_unaryops_on_constants
(
unsigned
char
*
codestr
,
PyObject
*
consts
,
PyObject
*
v
)
{
PyObject
*
newconst
=
NULL
/*, *v*/
;
PyObject
*
newconst
;
Py_ssize_t
len_consts
;
int
opcode
;
...
...
@@ -250,9 +250,7 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts, PyObject *v
opcode
=
codestr
[
3
];
switch
(
opcode
)
{
case
UNARY_NEGATIVE
:
/* Preserve the sign of -0.0 */
if
(
PyObject_IsTrue
(
v
)
==
1
)
newconst
=
PyNumber_Negative
(
v
);
newconst
=
PyNumber_Negative
(
v
);
break
;
case
UNARY_INVERT
:
newconst
=
PyNumber_Invert
(
v
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment