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
b9b7b481
Commit
b9b7b481
authored
Jun 21, 2012
by
Brian Curtin
Browse files
Options
Browse Files
Download
Plain Diff
Merge /features/pep397 changes
parents
d383212f
72c7d82c
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
221 additions
and
72 deletions
+221
-72
Doc/library/zlib.rst
Doc/library/zlib.rst
+24
-7
Lib/test/test_fileio.py
Lib/test/test_fileio.py
+11
-0
Lib/test/test_zlib.py
Lib/test/test_zlib.py
+30
-0
Misc/NEWS
Misc/NEWS
+8
-0
Modules/Setup.dist
Modules/Setup.dist
+3
-4
Modules/_decimal/libmpdec/mpdecimal.c
Modules/_decimal/libmpdec/mpdecimal.c
+16
-24
Modules/_io/fileio.c
Modules/_io/fileio.c
+6
-6
Modules/md5module.c
Modules/md5module.c
+6
-4
Modules/sha1module.c
Modules/sha1module.c
+6
-3
Modules/zlibmodule.c
Modules/zlibmodule.c
+96
-22
Objects/stringlib/localeutil.h
Objects/stringlib/localeutil.h
+1
-1
Python/formatter_unicode.c
Python/formatter_unicode.c
+1
-1
setup.py
setup.py
+13
-0
No files found.
Doc/library/zlib.rst
View file @
b9b7b481
...
@@ -58,12 +58,19 @@ The available exception and functions in this module are:
...
@@ -58,12 +58,19 @@ The available exception and functions in this module are:
exception if any error occurs.
exception if any error occurs.
.. function:: compressobj([level])
.. function:: compressobj([level
[, method[, wbits[, memlevel[, strategy[, zdict]]]]]
])
Returns a compression object, to be used for compressing data streams that won't
Returns a compression object, to be used for compressing data streams that won't
fit into memory at once. *level* is an integer from ``1`` to ``9`` controlling
fit into memory at once.
the level of compression; ``1`` is fastest and produces the least compression,
``9`` is slowest and produces the most. The default value is ``6``.
*level* is an integer from ``1`` to ``9`` controlling the level of
compression; ``1`` is fastest and produces the least compression, ``9`` is
slowest and produces the most. The default value is ``6``.
*zdict* is a predefined compression dictionary. This is a sequence of bytes
(such as a :class:`bytes` object) containing subsequences that are expected
to occur frequently in the data that is to be compressed. Those subsequences
that are expected to be most common should come at the end of the dictionary.
.. function:: crc32(data[, value])
.. function:: crc32(data[, value])
...
@@ -114,11 +121,21 @@ The available exception and functions in this module are:
...
@@ -114,11 +121,21 @@ The available exception and functions in this module are:
to :c:func:`malloc`. The default size is 16384.
to :c:func:`malloc`. The default size is 16384.
.. function:: decompressobj([wbits])
.. function:: decompressobj([wbits
[, zdict]
])
Returns a decompression object, to be used for decompressing data streams that
Returns a decompression object, to be used for decompressing data streams that
won't fit into memory at once. The *wbits* parameter controls the size of the
won't fit into memory at once.
window buffer.
The *wbits* parameter controls the size of the window buffer.
The *zdict* parameter specifies a predefined compression dictionary. If
provided, this must be the same dictionary as was used by the compressor that
produced the data that is to be decompressed.
.. note::
If *zdict* is a mutable object (such as a :class:`bytearray`), you must not
modify its contents between the call to :func:`decompressobj` and the first
call to the decompressor's ``decompress()`` method.
Compression objects support the following methods:
Compression objects support the following methods:
...
...
Lib/test/test_fileio.py
View file @
b9b7b481
...
@@ -404,6 +404,17 @@ class OtherFileTests(unittest.TestCase):
...
@@ -404,6 +404,17 @@ class OtherFileTests(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
_FileIO
,
"/some/invalid/name"
,
"rt"
)
self
.
assertRaises
(
ValueError
,
_FileIO
,
"/some/invalid/name"
,
"rt"
)
self
.
assertEqual
(
w
.
warnings
,
[])
self
.
assertEqual
(
w
.
warnings
,
[])
def
testUnclosedFDOnException
(
self
):
class
MyException
(
Exception
):
pass
class
MyFileIO
(
_FileIO
):
def
__setattr__
(
self
,
name
,
value
):
if
name
==
"name"
:
raise
MyException
(
"blocked setting name"
)
return
super
(
MyFileIO
,
self
).
__setattr__
(
name
,
value
)
fd
=
os
.
open
(
__file__
,
os
.
O_RDONLY
)
self
.
assertRaises
(
MyException
,
MyFileIO
,
fd
)
os
.
close
(
fd
)
# should not raise OSError(EBADF)
def
test_main
():
def
test_main
():
# Historically, these tests have been sloppy about removing TESTFN.
# Historically, these tests have been sloppy about removing TESTFN.
...
...
Lib/test/test_zlib.py
View file @
b9b7b481
...
@@ -425,6 +425,36 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
...
@@ -425,6 +425,36 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
dco
=
zlib
.
decompressobj
()
dco
=
zlib
.
decompressobj
()
self
.
assertEqual
(
dco
.
flush
(),
b""
)
# Returns nothing
self
.
assertEqual
(
dco
.
flush
(),
b""
)
# Returns nothing
def
test_dictionary
(
self
):
h
=
HAMLET_SCENE
# build a simulated dictionary out of the words in HAMLET
words
=
h
.
split
()
random
.
shuffle
(
words
)
zdict
=
b''
.
join
(
words
)
# use it to compress HAMLET
co
=
zlib
.
compressobj
(
zdict
=
zdict
)
cd
=
co
.
compress
(
h
)
+
co
.
flush
()
# verify that it will decompress with the dictionary
dco
=
zlib
.
decompressobj
(
zdict
=
zdict
)
self
.
assertEqual
(
dco
.
decompress
(
cd
)
+
dco
.
flush
(),
h
)
# verify that it fails when not given the dictionary
dco
=
zlib
.
decompressobj
()
self
.
assertRaises
(
zlib
.
error
,
dco
.
decompress
,
cd
)
def
test_dictionary_streaming
(
self
):
# this is simulating the needs of SPDY to be able to reuse the same
# stream object (with its compression state) between sets of compressed
# headers.
co
=
zlib
.
compressobj
(
zdict
=
HAMLET_SCENE
)
do
=
zlib
.
decompressobj
(
zdict
=
HAMLET_SCENE
)
piece
=
HAMLET_SCENE
[
1000
:
1500
]
d0
=
co
.
compress
(
piece
)
+
co
.
flush
(
zlib
.
Z_SYNC_FLUSH
)
d1
=
co
.
compress
(
piece
[
100
:])
+
co
.
flush
(
zlib
.
Z_SYNC_FLUSH
)
d2
=
co
.
compress
(
piece
[:
-
100
])
+
co
.
flush
(
zlib
.
Z_SYNC_FLUSH
)
self
.
assertEqual
(
do
.
decompress
(
d0
),
piece
)
self
.
assertEqual
(
do
.
decompress
(
d1
),
piece
[
100
:])
self
.
assertEqual
(
do
.
decompress
(
d2
),
piece
[:
-
100
])
def
test_decompress_incomplete_stream
(
self
):
def
test_decompress_incomplete_stream
(
self
):
# This is 'foo', deflated
# This is 'foo', deflated
x
=
b'x
\
x9c
K
\
xcb
\
xcf
\
x07
\
x00
\
x02
\
x82
\
x01
E'
x
=
b'x
\
x9c
K
\
xcb
\
xcf
\
x07
\
x00
\
x02
\
x82
\
x01
E'
...
...
Misc/NEWS
View file @
b9b7b481
...
@@ -10,6 +10,9 @@ What's New in Python 3.3.0 Beta 1?
...
@@ -10,6 +10,9 @@ What's New in Python 3.3.0 Beta 1?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #10053: Don'
t
close
FDs
when
FileIO
.
__init__
fails
.
Loosely
based
on
the
work
by
Hirokazu
Yamamoto
.
-
Issue
#
15096
:
Removed
support
for
ur
''
as
the
raw
notation
isn
't
-
Issue
#
15096
:
Removed
support
for
ur
''
as
the
raw
notation
isn
't
compatible with Python 2.x'
s
raw
unicode
strings
.
compatible with Python 2.x'
s
raw
unicode
strings
.
...
@@ -34,6 +37,9 @@ Core and Builtins
...
@@ -34,6 +37,9 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
14684
:
zlib
.
compressobj
()
and
zlib
.
decompressobj
()
now
support
the
use
of
predefined
compression
dictionaries
.
Original
patch
by
Sam
Rushing
.
-
Fix
GzipFile
's handling of filenames given as bytes objects.
-
Fix
GzipFile
's handling of filenames given as bytes objects.
- Issue #14772: Return destination values from some shutil functions.
- Issue #14772: Return destination values from some shutil functions.
...
@@ -162,6 +168,8 @@ Tests
...
@@ -162,6 +168,8 @@ Tests
Build
Build
-----
-----
-
Issue
#
14225
:
Fix
Unicode
support
for
curses
(#
12567
)
on
OS
X
-
Issue
#
14928
:
Fix
importlib
bootstrap
issues
by
using
a
custom
executable
-
Issue
#
14928
:
Fix
importlib
bootstrap
issues
by
using
a
custom
executable
(
Modules
/
_freeze_importlib
)
to
build
Python
/
importlib
.
h
.
(
Modules
/
_freeze_importlib
)
to
build
Python
/
importlib
.
h
.
...
...
Modules/Setup.dist
View file @
b9b7b481
...
@@ -234,15 +234,14 @@ _symtable symtablemodule.c
...
@@ -234,15 +234,14 @@ _symtable symtablemodule.c
# system does not have the OpenSSL libs containing an optimized version.
# system does not have the OpenSSL libs containing an optimized version.
# The _md5 module implements the RSA Data Security, Inc. MD5
# The _md5 module implements the RSA Data Security, Inc. MD5
# Message-Digest Algorithm, described in RFC 1321. The necessary files
# Message-Digest Algorithm, described in RFC 1321.
# md5.c and md5.h are included here.
#_md5 md5module.c
md5.c
#_md5 md5module.c
# The _sha module implements the SHA checksum algorithms.
# The _sha module implements the SHA checksum algorithms.
# (NIST's Secure Hash Algorithms.)
# (NIST's Secure Hash Algorithms.)
#_sha
sha
module.c
#_sha
1 sha1
module.c
#_sha256 sha256module.c
#_sha256 sha256module.c
#_sha512 sha512module.c
#_sha512 sha512module.c
...
...
Modules/_decimal/libmpdec/mpdecimal.c
View file @
b9b7b481
...
@@ -6679,7 +6679,7 @@ mpd_qrem_near(mpd_t *r, const mpd_t *a, const mpd_t *b,
...
@@ -6679,7 +6679,7 @@ mpd_qrem_near(mpd_t *r, const mpd_t *a, const mpd_t *b,
mpd_context_t
workctx
;
mpd_context_t
workctx
;
MPD_NEW_STATIC
(
btmp
,
0
,
0
,
0
,
0
);
MPD_NEW_STATIC
(
btmp
,
0
,
0
,
0
,
0
);
MPD_NEW_STATIC
(
q
,
0
,
0
,
0
,
0
);
MPD_NEW_STATIC
(
q
,
0
,
0
,
0
,
0
);
mpd_ssize_t
expdiff
,
floor
digits
;
mpd_ssize_t
expdiff
,
q
digits
;
int
cmp
,
isodd
,
allnine
;
int
cmp
,
isodd
,
allnine
;
if
(
mpd_isspecial
(
a
)
||
mpd_isspecial
(
b
))
{
if
(
mpd_isspecial
(
a
)
||
mpd_isspecial
(
b
))
{
...
@@ -6716,53 +6716,45 @@ mpd_qrem_near(mpd_t *r, const mpd_t *a, const mpd_t *b,
...
@@ -6716,53 +6716,45 @@ mpd_qrem_near(mpd_t *r, const mpd_t *a, const mpd_t *b,
b
=
&
btmp
;
b
=
&
btmp
;
}
}
workctx
=
*
ctx
;
_mpd_qdivmod
(
&
q
,
r
,
a
,
b
,
ctx
,
status
);
workctx
.
prec
=
a
->
digits
;
if
(
mpd_isnan
(
&
q
)
||
mpd_isnan
(
r
))
{
workctx
.
prec
=
(
workctx
.
prec
>
ctx
->
prec
)
?
workctx
.
prec
:
ctx
->
prec
;
_mpd_qdivmod
(
&
q
,
r
,
a
,
b
,
&
workctx
,
status
);
if
(
mpd_isnan
(
&
q
)
||
mpd_isnan
(
r
)
||
q
.
digits
>
ctx
->
prec
)
{
mpd_seterror
(
r
,
MPD_Division_impossible
,
status
);
goto
finish
;
goto
finish
;
}
}
if
(
mpd_iszerocoeff
(
r
))
{
if
(
mpd_iszerocoeff
(
r
))
{
goto
finish
;
goto
finish
;
}
}
/* Deal with cases like rmnx078:
* remaindernear 999999999.5 1 -> NaN Division_impossible */
expdiff
=
mpd_adjexp
(
b
)
-
mpd_adjexp
(
r
);
expdiff
=
mpd_adjexp
(
b
)
-
mpd_adjexp
(
r
);
if
(
-
1
<=
expdiff
&&
expdiff
<=
1
)
{
if
(
-
1
<=
expdiff
&&
expdiff
<=
1
)
{
mpd_qtrunc
(
&
q
,
&
q
,
&
workctx
,
&
workctx
.
status
);
allnine
=
mpd_coeff_isallnine
(
&
q
);
allnine
=
mpd_coeff_isallnine
(
&
q
);
floor
digits
=
q
.
digits
;
q
digits
=
q
.
digits
;
isodd
=
mpd_isodd
(
&
q
);
isodd
=
mpd_isodd
(
&
q
);
mpd_maxcontext
(
&
workctx
);
mpd_maxcontext
(
&
workctx
);
if
(
mpd_sign
(
a
)
==
mpd_sign
(
b
))
{
if
(
mpd_sign
(
a
)
==
mpd_sign
(
b
))
{
/* sign(r) == sign(b) */
_mpd_qsub
(
&
q
,
r
,
b
,
&
workctx
,
&
workctx
.
status
);
_mpd_qsub
(
&
q
,
r
,
b
,
&
workctx
,
&
workctx
.
status
);
if
(
workctx
.
status
&
MPD_Errors
)
{
mpd_seterror
(
r
,
workctx
.
status
&
MPD_Errors
,
status
);
goto
finish
;
}
}
}
else
{
else
{
/* sign(r) != sign(b) */
_mpd_qadd
(
&
q
,
r
,
b
,
&
workctx
,
&
workctx
.
status
);
_mpd_qadd
(
&
q
,
r
,
b
,
&
workctx
,
&
workctx
.
status
);
if
(
workctx
.
status
&
MPD_Errors
)
{
mpd_seterror
(
r
,
workctx
.
status
&
MPD_Errors
,
status
);
goto
finish
;
}
}
}
cmp
=
mpd_cmp_total_mag
(
&
q
,
r
);
if
(
workctx
.
status
&
MPD_Errors
)
{
mpd_seterror
(
r
,
workctx
.
status
&
MPD_Errors
,
status
);
goto
finish
;
}
cmp
=
_mpd_cmp_abs
(
&
q
,
r
);
if
(
cmp
<
0
||
(
cmp
==
0
&&
isodd
))
{
if
(
cmp
<
0
||
(
cmp
==
0
&&
isodd
))
{
if
(
allnine
&&
floordigits
==
ctx
->
prec
)
{
/* abs(r) > abs(b)/2 or abs(r) == abs(b)/2 and isodd(quotient) */
if
(
allnine
&&
qdigits
==
ctx
->
prec
)
{
/* abs(quotient) + 1 == 10**prec */
mpd_seterror
(
r
,
MPD_Division_impossible
,
status
);
mpd_seterror
(
r
,
MPD_Division_impossible
,
status
);
goto
finish
;
goto
finish
;
}
}
mpd_qcopy
(
r
,
&
q
,
status
);
mpd_qcopy
(
r
,
&
q
,
status
);
*
status
&=
~
MPD_Rounded
;
}
}
}
}
...
@@ -7088,7 +7080,7 @@ _mpd_qreciprocal(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx,
...
@@ -7088,7 +7080,7 @@ _mpd_qreciprocal(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx,
* q, r = divmod(coeff(a), coeff(b))
* q, r = divmod(coeff(a), coeff(b))
*
*
* Strategy: Multiply the dividend by the reciprocal of the divisor. The
* Strategy: Multiply the dividend by the reciprocal of the divisor. The
* inexact result is fixed by a small loop, using at most
2 iterations
.
* inexact result is fixed by a small loop, using at most
one iteration
.
*
*
* ACL2 proofs:
* ACL2 proofs:
* ------------
* ------------
...
...
Modules/_io/fileio.c
View file @
b9b7b481
...
@@ -227,6 +227,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -227,6 +227,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
int
flags
=
0
;
int
flags
=
0
;
int
fd
=
-
1
;
int
fd
=
-
1
;
int
closefd
=
1
;
int
closefd
=
1
;
int
fd_is_own
=
0
;
assert
(
PyFileIO_Check
(
oself
));
assert
(
PyFileIO_Check
(
oself
));
if
(
self
->
fd
>=
0
)
{
if
(
self
->
fd
>=
0
)
{
...
@@ -376,6 +377,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -376,6 +377,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
#endif
#endif
self
->
fd
=
open
(
name
,
flags
,
0666
);
self
->
fd
=
open
(
name
,
flags
,
0666
);
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
fd_is_own
=
1
;
}
else
{
}
else
{
PyObject
*
fdobj
=
PyObject_CallFunction
(
PyObject
*
fdobj
=
PyObject_CallFunction
(
opener
,
"Oi"
,
nameobj
,
flags
);
opener
,
"Oi"
,
nameobj
,
flags
);
...
@@ -393,6 +395,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -393,6 +395,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
if
(
self
->
fd
==
-
1
)
{
if
(
self
->
fd
==
-
1
)
{
goto
error
;
goto
error
;
}
}
fd_is_own
=
1
;
}
}
if
(
self
->
fd
<
0
)
{
if
(
self
->
fd
<
0
)
{
...
@@ -421,13 +424,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -421,13 +424,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
end of file (otherwise, it might be done only on the
end of file (otherwise, it might be done only on the
first write()). */
first write()). */
PyObject
*
pos
=
portable_lseek
(
self
->
fd
,
NULL
,
2
);
PyObject
*
pos
=
portable_lseek
(
self
->
fd
,
NULL
,
2
);
if
(
pos
==
NULL
)
{
if
(
pos
==
NULL
)
if
(
closefd
)
{
close
(
self
->
fd
);
self
->
fd
=
-
1
;
}
goto
error
;
goto
error
;
}
Py_DECREF
(
pos
);
Py_DECREF
(
pos
);
}
}
...
@@ -435,6 +433,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -435,6 +433,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
error:
error:
ret
=
-
1
;
ret
=
-
1
;
if
(
!
fd_is_own
)
self
->
fd
=
-
1
;
if
(
self
->
fd
>=
0
)
if
(
self
->
fd
>=
0
)
internal_close
(
self
);
internal_close
(
self
);
...
...
Modules/md5module.c
View file @
b9b7b481
...
@@ -210,7 +210,8 @@ static void md5_compress(struct md5_state *md5, unsigned char *buf)
...
@@ -210,7 +210,8 @@ static void md5_compress(struct md5_state *md5, unsigned char *buf)
Initialize the hash state
Initialize the hash state
@param sha1 The hash state you wish to initialize
@param sha1 The hash state you wish to initialize
*/
*/
void
md5_init
(
struct
md5_state
*
md5
)
static
void
md5_init
(
struct
md5_state
*
md5
)
{
{
assert
(
md5
!=
NULL
);
assert
(
md5
!=
NULL
);
md5
->
state
[
0
]
=
0x67452301UL
;
md5
->
state
[
0
]
=
0x67452301UL
;
...
@@ -227,8 +228,8 @@ void md5_init(struct md5_state *md5)
...
@@ -227,8 +228,8 @@ void md5_init(struct md5_state *md5)
@param in The data to hash
@param in The data to hash
@param inlen The length of the data (octets)
@param inlen The length of the data (octets)
*/
*/
void
md5_process
(
struct
md5_state
*
md5
,
static
void
const
unsigned
char
*
in
,
Py_ssize_t
inlen
)
md5_process
(
struct
md5_state
*
md5
,
const
unsigned
char
*
in
,
Py_ssize_t
inlen
)
{
{
Py_ssize_t
n
;
Py_ssize_t
n
;
...
@@ -262,7 +263,8 @@ void md5_process(struct md5_state *md5,
...
@@ -262,7 +263,8 @@ void md5_process(struct md5_state *md5,
@param sha1 The hash state
@param sha1 The hash state
@param out [out] The destination of the hash (16 bytes)
@param out [out] The destination of the hash (16 bytes)
*/
*/
void
md5_done
(
struct
md5_state
*
md5
,
unsigned
char
*
out
)
static
void
md5_done
(
struct
md5_state
*
md5
,
unsigned
char
*
out
)
{
{
int
i
;
int
i
;
...
...
Modules/sha1module.c
View file @
b9b7b481
...
@@ -184,7 +184,8 @@ static void sha1_compress(struct sha1_state *sha1, unsigned char *buf)
...
@@ -184,7 +184,8 @@ static void sha1_compress(struct sha1_state *sha1, unsigned char *buf)
Initialize the hash state
Initialize the hash state
@param sha1 The hash state you wish to initialize
@param sha1 The hash state you wish to initialize
*/
*/
void
sha1_init
(
struct
sha1_state
*
sha1
)
static
void
sha1_init
(
struct
sha1_state
*
sha1
)
{
{
assert
(
sha1
!=
NULL
);
assert
(
sha1
!=
NULL
);
sha1
->
state
[
0
]
=
0x67452301UL
;
sha1
->
state
[
0
]
=
0x67452301UL
;
...
@@ -202,7 +203,8 @@ void sha1_init(struct sha1_state *sha1)
...
@@ -202,7 +203,8 @@ void sha1_init(struct sha1_state *sha1)
@param in The data to hash
@param in The data to hash
@param inlen The length of the data (octets)
@param inlen The length of the data (octets)
*/
*/
void
sha1_process
(
struct
sha1_state
*
sha1
,
static
void
sha1_process
(
struct
sha1_state
*
sha1
,
const
unsigned
char
*
in
,
Py_ssize_t
inlen
)
const
unsigned
char
*
in
,
Py_ssize_t
inlen
)
{
{
Py_ssize_t
n
;
Py_ssize_t
n
;
...
@@ -237,7 +239,8 @@ void sha1_process(struct sha1_state *sha1,
...
@@ -237,7 +239,8 @@ void sha1_process(struct sha1_state *sha1,
@param sha1 The hash state
@param sha1 The hash state
@param out [out] The destination of the hash (20 bytes)
@param out [out] The destination of the hash (20 bytes)
*/
*/
void
sha1_done
(
struct
sha1_state
*
sha1
,
unsigned
char
*
out
)
static
void
sha1_done
(
struct
sha1_state
*
sha1
,
unsigned
char
*
out
)
{
{
int
i
;
int
i
;
...
...
Modules/zlibmodule.c
View file @
b9b7b481
...
@@ -45,6 +45,7 @@ typedef struct
...
@@ -45,6 +45,7 @@ typedef struct
PyObject
*
unconsumed_tail
;
PyObject
*
unconsumed_tail
;
char
eof
;
char
eof
;
int
is_initialised
;
int
is_initialised
;
PyObject
*
zdict
;
#ifdef WITH_THREAD
#ifdef WITH_THREAD
PyThread_type_lock
lock
;
PyThread_type_lock
lock
;
#endif
#endif
...
@@ -80,14 +81,21 @@ zlib_error(z_stream zst, int err, char *msg)
...
@@ -80,14 +81,21 @@ zlib_error(z_stream zst, int err, char *msg)
}
}
PyDoc_STRVAR
(
compressobj__doc__
,
PyDoc_STRVAR
(
compressobj__doc__
,
"compressobj([level]) -- Return a compressor object.
\n
"
"compressobj([level[, method[, wbits[, memlevel[, strategy[, zdict]]]]]])
\n
"
" -- Return a compressor object.
\n
"
"
\n
"
"
\n
"
"Optional arg level is the compression level, in 1-9."
);
"Optional arg level is the compression level, in 1-9.
\n
"
"
\n
"
"Optional arg zdict is the predefined compression dictionary - a sequence of
\n
"
"bytes containing subsequences that are likely to occur in the input data."
);
PyDoc_STRVAR
(
decompressobj__doc__
,
PyDoc_STRVAR
(
decompressobj__doc__
,
"decompressobj([wbits]) -- Return a decompressor object.
\n
"
"decompressobj([wbits[, zdict]]) -- Return a decompressor object.
\n
"
"
\n
"
"Optional arg wbits is the window buffer size.
\n
"
"
\n
"
"
\n
"
"Optional arg wbits is the window buffer size."
);
"Optional arg zdict is the predefined compression dictionary. This must be
\n
"
"the same dictionary as used by the compressor that produced the input data."
);
static
compobject
*
static
compobject
*
newcompobject
(
PyTypeObject
*
type
)
newcompobject
(
PyTypeObject
*
type
)
...
@@ -98,6 +106,7 @@ newcompobject(PyTypeObject *type)
...
@@ -98,6 +106,7 @@ newcompobject(PyTypeObject *type)
return
NULL
;
return
NULL
;
self
->
eof
=
0
;
self
->
eof
=
0
;
self
->
is_initialised
=
0
;
self
->
is_initialised
=
0
;
self
->
zdict
=
NULL
;
self
->
unused_data
=
PyBytes_FromStringAndSize
(
""
,
0
);
self
->
unused_data
=
PyBytes_FromStringAndSize
(
""
,
0
);
if
(
self
->
unused_data
==
NULL
)
{
if
(
self
->
unused_data
==
NULL
)
{
Py_DECREF
(
self
);
Py_DECREF
(
self
);
...
@@ -316,19 +325,24 @@ PyZlib_decompress(PyObject *self, PyObject *args)
...
@@ -316,19 +325,24 @@ PyZlib_decompress(PyObject *self, PyObject *args)
}
}
static
PyObject
*
static
PyObject
*
PyZlib_compressobj
(
PyObject
*
selfptr
,
PyObject
*
args
)
PyZlib_compressobj
(
PyObject
*
selfptr
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
{
compobject
*
self
;
compobject
*
self
;
int
level
=
Z_DEFAULT_COMPRESSION
,
method
=
DEFLATED
;
int
level
=
Z_DEFAULT_COMPRESSION
,
method
=
DEFLATED
;
int
wbits
=
MAX_WBITS
,
memLevel
=
DEF_MEM_LEVEL
,
strategy
=
0
,
err
;
int
wbits
=
MAX_WBITS
,
memLevel
=
DEF_MEM_LEVEL
,
strategy
=
0
,
err
;
Py_buffer
zdict
;
if
(
!
PyArg_ParseTuple
(
args
,
"|iiiii:compressobj"
,
&
level
,
&
method
,
&
wbits
,
static
char
*
kwlist
[]
=
{
"level"
,
"method"
,
"wbits"
,
&
memLevel
,
&
strategy
))
"memLevel"
,
"strategy"
,
"zdict"
,
NULL
};
zdict
.
buf
=
NULL
;
/* Sentinel, so we can tell whether zdict was supplied. */
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"|iiiiiy*:compressobj"
,
kwlist
,
&
level
,
&
method
,
&
wbits
,
&
memLevel
,
&
strategy
,
&
zdict
))
return
NULL
;
return
NULL
;
self
=
newcompobject
(
&
Comptype
);
self
=
newcompobject
(
&
Comptype
);
if
(
self
==
NULL
)
if
(
self
==
NULL
)
return
(
NULL
)
;
goto
error
;
self
->
zst
.
zalloc
=
(
alloc_func
)
NULL
;
self
->
zst
.
zalloc
=
(
alloc_func
)
NULL
;
self
->
zst
.
zfree
=
(
free_func
)
Z_NULL
;
self
->
zst
.
zfree
=
(
free_func
)
Z_NULL
;
self
->
zst
.
next_in
=
NULL
;
self
->
zst
.
next_in
=
NULL
;
...
@@ -337,30 +351,58 @@ PyZlib_compressobj(PyObject *selfptr, PyObject *args)
...
@@ -337,30 +351,58 @@ PyZlib_compressobj(PyObject *selfptr, PyObject *args)
switch
(
err
)
{
switch
(
err
)
{
case
(
Z_OK
):
case
(
Z_OK
):
self
->
is_initialised
=
1
;
self
->
is_initialised
=
1
;
return
(
PyObject
*
)
self
;
if
(
zdict
.
buf
==
NULL
)
{
goto
success
;
}
else
{
err
=
deflateSetDictionary
(
&
self
->
zst
,
zdict
.
buf
,
zdict
.
len
);
switch
(
err
)
{
case
(
Z_OK
):
goto
success
;
case
(
Z_STREAM_ERROR
):
PyErr_SetString
(
PyExc_ValueError
,
"Invalid dictionary"
);
goto
error
;
default:
PyErr_SetString
(
PyExc_ValueError
,
"deflateSetDictionary()"
);
goto
error
;
}
}
case
(
Z_MEM_ERROR
):
case
(
Z_MEM_ERROR
):
Py_DECREF
(
self
);
PyErr_SetString
(
PyExc_MemoryError
,
PyErr_SetString
(
PyExc_MemoryError
,
"Can't allocate memory for compression object"
);
"Can't allocate memory for compression object"
);
return
NULL
;
goto
error
;
case
(
Z_STREAM_ERROR
):
case
(
Z_STREAM_ERROR
):
Py_DECREF
(
self
);
PyErr_SetString
(
PyExc_ValueError
,
"Invalid initialization option"
);
PyErr_SetString
(
PyExc_ValueError
,
"Invalid initialization option"
);
return
NULL
;
goto
error
;
default:
default:
zlib_error
(
self
->
zst
,
err
,
"while creating compression object"
);
zlib_error
(
self
->
zst
,
err
,
"while creating compression object"
);
Py_DECREF
(
self
);
goto
error
;
return
NULL
;
}
}
error:
Py_XDECREF
(
self
);
self
=
NULL
;
success:
if
(
zdict
.
buf
!=
NULL
)
PyBuffer_Release
(
&
zdict
);
return
(
PyObject
*
)
self
;
}
}
static
PyObject
*
static
PyObject
*
PyZlib_decompressobj
(
PyObject
*
selfptr
,
PyObject
*
args
)
PyZlib_decompressobj
(
PyObject
*
selfptr
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
{
static
char
*
kwlist
[]
=
{
"wbits"
,
"zdict"
,
NULL
};
int
wbits
=
DEF_WBITS
,
err
;
int
wbits
=
DEF_WBITS
,
err
;
compobject
*
self
;
compobject
*
self
;
if
(
!
PyArg_ParseTuple
(
args
,
"|i:decompressobj"
,
&
wbits
))
PyObject
*
zdict
=
NULL
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"|iO:decompressobj"
,
kwlist
,
&
wbits
,
&
zdict
))
return
NULL
;
if
(
zdict
!=
NULL
&&
!
PyObject_CheckBuffer
(
zdict
))
{
PyErr_SetString
(
PyExc_TypeError
,
"zdict argument must support the buffer protocol"
);
return
NULL
;
return
NULL
;
}
self
=
newcompobject
(
&
Decomptype
);
self
=
newcompobject
(
&
Decomptype
);
if
(
self
==
NULL
)
if
(
self
==
NULL
)
...
@@ -369,6 +411,10 @@ PyZlib_decompressobj(PyObject *selfptr, PyObject *args)
...
@@ -369,6 +411,10 @@ PyZlib_decompressobj(PyObject *selfptr, PyObject *args)
self
->
zst
.
zfree
=
(
free_func
)
Z_NULL
;
self
->
zst
.
zfree
=
(
free_func
)
Z_NULL
;
self
->
zst
.
next_in
=
NULL
;
self
->
zst
.
next_in
=
NULL
;
self
->
zst
.
avail_in
=
0
;
self
->
zst
.
avail_in
=
0
;
if
(
zdict
!=
NULL
)
{
Py_INCREF
(
zdict
);
self
->
zdict
=
zdict
;
}
err
=
inflateInit2
(
&
self
->
zst
,
wbits
);
err
=
inflateInit2
(
&
self
->
zst
,
wbits
);
switch
(
err
)
{
switch
(
err
)
{
case
(
Z_OK
):
case
(
Z_OK
):
...
@@ -398,6 +444,7 @@ Dealloc(compobject *self)
...
@@ -398,6 +444,7 @@ Dealloc(compobject *self)
#endif
#endif
Py_XDECREF
(
self
->
unused_data
);
Py_XDECREF
(
self
->
unused_data
);
Py_XDECREF
(
self
->
unconsumed_tail
);
Py_XDECREF
(
self
->
unconsumed_tail
);
Py_XDECREF
(
self
->
zdict
);
PyObject_Del
(
self
);
PyObject_Del
(
self
);
}
}
...
@@ -557,6 +604,27 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
...
@@ -557,6 +604,27 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
err
=
inflate
(
&
(
self
->
zst
),
Z_SYNC_FLUSH
);
err
=
inflate
(
&
(
self
->
zst
),
Z_SYNC_FLUSH
);
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
if
(
err
==
Z_NEED_DICT
&&
self
->
zdict
!=
NULL
)
{
Py_buffer
zdict_buf
;
if
(
PyObject_GetBuffer
(
self
->
zdict
,
&
zdict_buf
,
PyBUF_SIMPLE
)
==
-
1
)
{
Py_DECREF
(
RetVal
);
RetVal
=
NULL
;
goto
error
;
}
err
=
inflateSetDictionary
(
&
(
self
->
zst
),
zdict_buf
.
buf
,
zdict_buf
.
len
);
PyBuffer_Release
(
&
zdict_buf
);
if
(
err
!=
Z_OK
)
{
zlib_error
(
self
->
zst
,
err
,
"while decompressing data"
);
Py_DECREF
(
RetVal
);
RetVal
=
NULL
;
goto
error
;
}
/* repeat the call to inflate! */
Py_BEGIN_ALLOW_THREADS
err
=
inflate
(
&
(
self
->
zst
),
Z_SYNC_FLUSH
);
Py_END_ALLOW_THREADS
}
/* While Z_OK and the output buffer is full, there might be more output.
/* While Z_OK and the output buffer is full, there might be more output.
So extend the output buffer and try again.
So extend the output buffer and try again.
*/
*/
...
@@ -770,10 +838,13 @@ PyZlib_copy(compobject *self)
...
@@ -770,10 +838,13 @@ PyZlib_copy(compobject *self)
}
}
Py_INCREF
(
self
->
unused_data
);
Py_INCREF
(
self
->
unused_data
);
Py_INCREF
(
self
->
unconsumed_tail
);
Py_INCREF
(
self
->
unconsumed_tail
);
Py_XINCREF
(
self
->
zdict
);
Py_XDECREF
(
retval
->
unused_data
);
Py_XDECREF
(
retval
->
unused_data
);
Py_XDECREF
(
retval
->
unconsumed_tail
);
Py_XDECREF
(
retval
->
unconsumed_tail
);
Py_XDECREF
(
retval
->
zdict
);
retval
->
unused_data
=
self
->
unused_data
;
retval
->
unused_data
=
self
->
unused_data
;
retval
->
unconsumed_tail
=
self
->
unconsumed_tail
;
retval
->
unconsumed_tail
=
self
->
unconsumed_tail
;
retval
->
zdict
=
self
->
zdict
;
retval
->
eof
=
self
->
eof
;
retval
->
eof
=
self
->
eof
;
/* Mark it as being initialized */
/* Mark it as being initialized */
...
@@ -822,10 +893,13 @@ PyZlib_uncopy(compobject *self)
...
@@ -822,10 +893,13 @@ PyZlib_uncopy(compobject *self)
Py_INCREF
(
self
->
unused_data
);
Py_INCREF
(
self
->
unused_data
);
Py_INCREF
(
self
->
unconsumed_tail
);
Py_INCREF
(
self
->
unconsumed_tail
);
Py_XINCREF
(
self
->
zdict
);
Py_XDECREF
(
retval
->
unused_data
);
Py_XDECREF
(
retval
->
unused_data
);
Py_XDECREF
(
retval
->
unconsumed_tail
);
Py_XDECREF
(
retval
->
unconsumed_tail
);
Py_XDECREF
(
retval
->
zdict
);
retval
->
unused_data
=
self
->
unused_data
;
retval
->
unused_data
=
self
->
unused_data
;
retval
->
unconsumed_tail
=
self
->
unconsumed_tail
;
retval
->
unconsumed_tail
=
self
->
unconsumed_tail
;
retval
->
zdict
=
self
->
zdict
;
retval
->
eof
=
self
->
eof
;
retval
->
eof
=
self
->
eof
;
/* Mark it as being initialized */
/* Mark it as being initialized */
...
@@ -1032,13 +1106,13 @@ static PyMethodDef zlib_methods[] =
...
@@ -1032,13 +1106,13 @@ static PyMethodDef zlib_methods[] =
adler32__doc__
},
adler32__doc__
},
{
"compress"
,
(
PyCFunction
)
PyZlib_compress
,
METH_VARARGS
,
{
"compress"
,
(
PyCFunction
)
PyZlib_compress
,
METH_VARARGS
,
compress__doc__
},
compress__doc__
},
{
"compressobj"
,
(
PyCFunction
)
PyZlib_compressobj
,
METH_VARARGS
,
{
"compressobj"
,
(
PyCFunction
)
PyZlib_compressobj
,
METH_VARARGS
|
METH_KEYWORDS
,
compressobj__doc__
},
compressobj__doc__
},
{
"crc32"
,
(
PyCFunction
)
PyZlib_crc32
,
METH_VARARGS
,
{
"crc32"
,
(
PyCFunction
)
PyZlib_crc32
,
METH_VARARGS
,
crc32__doc__
},
crc32__doc__
},
{
"decompress"
,
(
PyCFunction
)
PyZlib_decompress
,
METH_VARARGS
,
{
"decompress"
,
(
PyCFunction
)
PyZlib_decompress
,
METH_VARARGS
,
decompress__doc__
},
decompress__doc__
},
{
"decompressobj"
,
(
PyCFunction
)
PyZlib_decompressobj
,
METH_VARARGS
,
{
"decompressobj"
,
(
PyCFunction
)
PyZlib_decompressobj
,
METH_VARARGS
|
METH_KEYWORDS
,
decompressobj__doc__
},
decompressobj__doc__
},
{
NULL
,
NULL
}
{
NULL
,
NULL
}
};
};
...
@@ -1112,10 +1186,10 @@ PyDoc_STRVAR(zlib_module_documentation,
...
@@ -1112,10 +1186,10 @@ PyDoc_STRVAR(zlib_module_documentation,
"
\n
"
"
\n
"
"adler32(string[, start]) -- Compute an Adler-32 checksum.
\n
"
"adler32(string[, start]) -- Compute an Adler-32 checksum.
\n
"
"compress(string[, level]) -- Compress string, with compression level in 1-9.
\n
"
"compress(string[, level]) -- Compress string, with compression level in 1-9.
\n
"
"compressobj([level]) -- Return a compressor object.
\n
"
"compressobj([level
[, ...]
]) -- Return a compressor object.
\n
"
"crc32(string[, start]) -- Compute a CRC-32 checksum.
\n
"
"crc32(string[, start]) -- Compute a CRC-32 checksum.
\n
"
"decompress(string,[wbits],[bufsize]) -- Decompresses a compressed string.
\n
"
"decompress(string,[wbits],[bufsize]) -- Decompresses a compressed string.
\n
"
"decompressobj([wbits]) -- Return a decompressor object.
\n
"
"decompressobj([wbits
[, zdict]]
]) -- Return a decompressor object.
\n
"
"
\n
"
"
\n
"
"'wbits' is window buffer size.
\n
"
"'wbits' is window buffer size.
\n
"
"Compressor objects support compress() and flush() methods; decompressor
\n
"
"Compressor objects support compress() and flush() methods; decompressor
\n
"
...
...
Objects/stringlib/localeutil.h
View file @
b9b7b481
...
@@ -99,7 +99,7 @@ STRINGLIB(fill)(STRINGLIB_CHAR **digits_end, STRINGLIB_CHAR **buffer_end,
...
@@ -99,7 +99,7 @@ STRINGLIB(fill)(STRINGLIB_CHAR **digits_end, STRINGLIB_CHAR **buffer_end,
* As closely as possible, this code mimics the logic in decimal.py's
* As closely as possible, this code mimics the logic in decimal.py's
_insert_thousands_sep().
_insert_thousands_sep().
**/
**/
Py_ssize_t
static
Py_ssize_t
STRINGLIB
(
InsertThousandsGrouping
)(
STRINGLIB
(
InsertThousandsGrouping
)(
STRINGLIB_CHAR
*
buffer
,
STRINGLIB_CHAR
*
buffer
,
Py_ssize_t
n_buffer
,
Py_ssize_t
n_buffer
,
...
...
Python/formatter_unicode.c
View file @
b9b7b481
...
@@ -1347,7 +1347,7 @@ done:
...
@@ -1347,7 +1347,7 @@ done:
/************************************************************************/
/************************************************************************/
/*********** built in formatters ****************************************/
/*********** built in formatters ****************************************/
/************************************************************************/
/************************************************************************/
int
static
int
format_obj
(
PyObject
*
obj
,
_PyUnicodeWriter
*
writer
)
format_obj
(
PyObject
*
obj
,
_PyUnicodeWriter
*
writer
)
{
{
PyObject
*
str
;
PyObject
*
str
;
...
...
setup.py
View file @
b9b7b481
...
@@ -1185,6 +1185,18 @@ class PyBuildExt(build_ext):
...
@@ -1185,6 +1185,18 @@ class PyBuildExt(build_ext):
# Bug 1464056: If _curses.so links with ncursesw,
# Bug 1464056: If _curses.so links with ncursesw,
# _curses_panel.so must link with panelw.
# _curses_panel.so must link with panelw.
panel_library
=
'panelw'
panel_library
=
'panelw'
if
platform
==
'darwin'
:
# On OS X, there is no separate /usr/lib/libncursesw nor
# libpanelw. If we are here, we found a locally-supplied
# version of libncursesw. There should be also be a
# libpanelw. _XOPEN_SOURCE defines are usually excluded
# for OS X but we need _XOPEN_SOURCE_EXTENDED here for
# ncurses wide char support
curses_defines
.
append
((
'_XOPEN_SOURCE_EXTENDED'
,
'1'
))
elif
platform
==
'darwin'
and
curses_library
==
'ncurses'
:
# Building with the system-suppied combined libncurses/libpanel
curses_defines
.
append
((
'HAVE_NCURSESW'
,
'1'
))
curses_defines
.
append
((
'_XOPEN_SOURCE_EXTENDED'
,
'1'
))
if
curses_library
.
startswith
(
'ncurses'
):
if
curses_library
.
startswith
(
'ncurses'
):
curses_libs
=
[
curses_library
]
curses_libs
=
[
curses_library
]
...
@@ -1213,6 +1225,7 @@ class PyBuildExt(build_ext):
...
@@ -1213,6 +1225,7 @@ class PyBuildExt(build_ext):
self
.
compiler
.
find_library_file
(
lib_dirs
,
panel_library
)):
self
.
compiler
.
find_library_file
(
lib_dirs
,
panel_library
)):
exts
.
append
(
Extension
(
'_curses_panel'
,
[
'_curses_panel.c'
],
exts
.
append
(
Extension
(
'_curses_panel'
,
[
'_curses_panel.c'
],
include_dirs
=
curses_includes
,
include_dirs
=
curses_includes
,
define_macros
=
curses_defines
,
libraries
=
[
panel_library
]
+
curses_libs
)
)
libraries
=
[
panel_library
]
+
curses_libs
)
)
else
:
else
:
missing
.
append
(
'_curses_panel'
)
missing
.
append
(
'_curses_panel'
)
...
...
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