Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbe741d

Browse files
committed
Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r61981 | amaury.forgeotdarc | 2008-03-28 01:21:34 +0100 (Fri, 28 Mar 2008) | 2 lines test_future3.py is a regular test file, and should be part of the test suite ........ r61984 | jeffrey.yasskin | 2008-03-28 05:11:18 +0100 (Fri, 28 Mar 2008) | 6 lines Kill a race in test_threading in which the exception info in a thread finishing up after it was joined had a traceback pointing to that thread's (deleted) target attribute, while the test was trying to check that the target was destroyed. Big thanks to Antoine Pitrou for diagnosing the race and pointing out sys.exc_clear() to kill the exception early. This fixes issue 2496. ........ r61985 | neal.norwitz | 2008-03-28 05:41:34 +0100 (Fri, 28 Mar 2008) | 1 line Allow use of other ports so the test can pass if 9091 is in use ........ r61986 | jeffrey.yasskin | 2008-03-28 05:53:10 +0100 (Fri, 28 Mar 2008) | 2 lines Print more information the next time test_socket throws the wrong exception. ........ r61987 | neal.norwitz | 2008-03-28 05:58:51 +0100 (Fri, 28 Mar 2008) | 5 lines Revert r61969 which added casts to Py_CHARMASK to avoid compiler warnings. Rather than sprinkle casts throughout the code, change Py_CHARMASK to always cast it's result to an unsigned char. This should ensure we do the right thing when accessing an array with the result. ........ r61992 | neal.norwitz | 2008-03-28 06:34:59 +0100 (Fri, 28 Mar 2008) | 2 lines Fix compiler warning about finite() missing on Solaris. ........ r61993 | neal.norwitz | 2008-03-28 07:34:03 +0100 (Fri, 28 Mar 2008) | 11 lines Bug 1503: Get the test to pass on OSX. This should make the test more reliable, but I'm not convinced it is the right solution. We need to determine if this causes the test to hang on any platforms or do other bad things. Even if it gets the test to pass reliably, it might be that we want to fix this in socket. The socket returned from accept() is different on different platforms (inheriting attributes or not) and we might want to ensure that the attributes (at least blocking) is the same across all platforms. ........ r61997 | neal.norwitz | 2008-03-28 08:36:31 +0100 (Fri, 28 Mar 2008) | 1 line Name the main method correctly so the test is run ........ r61998 | gregory.p.smith | 2008-03-28 09:00:44 +0100 (Fri, 28 Mar 2008) | 7 lines This patch moves some tests from test_urllib2_net to test_urllib2_localnet. The moved tests use a local server rather than going out to external servers. Accepts patch from issue2429. Contributed by Jerry Seutter & Michael Foord (fuzzyman) at PyCon 2008. ........ r61999 | georg.brandl | 2008-03-28 09:06:56 +0100 (Fri, 28 Mar 2008) | 2 lines #2406: add examples to gzip docs. ........ r62000 | gregory.p.smith | 2008-03-28 09:32:09 +0100 (Fri, 28 Mar 2008) | 4 lines Accept patch issue2426 by Paul Kippes (kippesp). Adds sqlite3.Connection.iterdump to allow dumping of databases. ........
1 parent 75d43c8 commit bbe741d

25 files changed

Lines changed: 446 additions & 162 deletions

Doc/library/gzip.rst

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
21
:mod:`gzip` --- Support for :program:`gzip` files
32
=================================================
43

54
.. module:: gzip
65
:synopsis: Interfaces for gzip compression and decompression using file objects.
76

7+
This module provides a simple interface to compress and decompress files just
8+
like the GNU programs :program:`gzip` and :program:`gunzip` would.
9+
10+
The data compression is provided by the :mod:``zlib`` module.
811

9-
The data compression provided by the ``zlib`` module is compatible with that
10-
used by the GNU compression program :program:`gzip`. Accordingly, the
11-
:mod:`gzip` module provides the :class:`GzipFile` class to read and write
12+
The :mod:`gzip` module provides the :class:`GzipFile` class which is modeled
13+
after Python's File Object. The :class:`GzipFile` class reads and writes
1214
:program:`gzip`\ -format files, automatically compressing or decompressing the
13-
data so it looks like an ordinary file object. Note that additional file
14-
formats which can be decompressed by the :program:`gzip` and :program:`gunzip`
15-
programs, such as those produced by :program:`compress` and :program:`pack`,
16-
are not supported by this module.
15+
data so that it looks like an ordinary file object.
16+
17+
Note that additional file formats which can be decompressed by the
18+
:program:`gzip` and :program:`gunzip` programs, such as those produced by
19+
:program:`compress` and :program:`pack`, are not supported by this module.
1720

1821
For other archive formats, see the :mod:`bz2`, :mod:`zipfile`, and
1922
:mod:`tarfile` modules.
@@ -63,6 +66,36 @@ The module defines the following items:
6366
*compresslevel* defaults to ``9``.
6467

6568

69+
.. _gzip-usage-examples:
70+
71+
Examples of usage
72+
-----------------
73+
74+
Example of how to read a compressed file::
75+
76+
import gzip
77+
f = gzip.open('/home/joe/file.txt.gz', 'rb')
78+
file_content = f.read()
79+
f.close()
80+
81+
Example of how to create a compressed GZIP file::
82+
83+
import gzip
84+
content = "Lots of content here"
85+
f = gzip.open('/home/joe/file.txt.gz', 'wb')
86+
f.write(content)
87+
f.close()
88+
89+
Example of how to GZIP compress an existing file::
90+
91+
import gzip
92+
f_in = open('/home/joe/file.txt', 'rb')
93+
f_out = gzip.open('/home/joe/file.txt.gz', 'wb')
94+
f_out.writelines(f_in)
95+
f_out.close()
96+
f_in.close()
97+
98+
6699
.. seealso::
67100

68101
Module :mod:`zlib`

Doc/library/sqlite3.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,27 @@ A :class:`Connection` instance has the following attributes and methods:
376376
deleted since the database connection was opened.
377377

378378

379+
.. attribute:: Connection.iterdump
380+
381+
Returns an iterator to dump the database in an SQL text format. Useful when
382+
saving an in-memory database for later restoration. This function provides
383+
the same capabilities as the :kbd:`.dump` command in the :program:`sqlite3`
384+
shell.
385+
386+
.. versionadded:: 2.6
387+
388+
Example::
389+
390+
# Convert file existing_db.db to SQL dump file dump.sql
391+
import sqlite3, os
392+
393+
con = sqlite3.connect('existing_db.db')
394+
full_dump = os.linesep.join([line for line in con.iterdump()])
395+
f = open('dump.sql', 'w')
396+
f.writelines(full_dump)
397+
f.close()
398+
399+
379400
.. _sqlite3-cursor-objects:
380401

381402
Cursor Objects

Include/Python.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
124124
#ifdef __CHAR_UNSIGNED__
125125
#define Py_CHARMASK(c) (c)
126126
#else
127-
#define Py_CHARMASK(c) ((c) & 0xff)
127+
#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
128128
#endif
129129

130130
#include "pyfpe.h"

Include/bytes_methods.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ extern const char _Py_swapcase__doc__[];
4444

4545
extern const unsigned int _Py_ctype_table[256];
4646

47-
#define ISLOWER(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_LOWER)
48-
#define ISUPPER(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_UPPER)
49-
#define ISALPHA(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_ALPHA)
50-
#define ISDIGIT(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_DIGIT)
51-
#define ISXDIGIT(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_XDIGIT)
52-
#define ISALNUM(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_ALNUM)
53-
#define ISSPACE(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_SPACE)
47+
#define ISLOWER(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_LOWER)
48+
#define ISUPPER(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_UPPER)
49+
#define ISALPHA(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_ALPHA)
50+
#define ISDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_DIGIT)
51+
#define ISXDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_XDIGIT)
52+
#define ISALNUM(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_ALNUM)
53+
#define ISSPACE(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_SPACE)
5454

5555
#undef islower
5656
#define islower(c) undefined_islower(c)

Lib/test/regrtest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,6 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
529529
'test_support',
530530
'test_future1',
531531
'test_future2',
532-
'test_future3',
533532
}
534533

535534
def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):

Lib/test/test_sax.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ def test_expat_nsattrs_wattr(self):
446446

447447
# ===== InputSource support
448448

449-
def test_expat_inpsource_filename(self):
449+
def XXXtest_expat_inpsource_filename(self):
450+
# FIXME: test blocks indefinitely
450451
parser = create_parser()
451452
result = StringIO()
452453
xmlgen = XMLGenerator(result)
@@ -456,7 +457,8 @@ def test_expat_inpsource_filename(self):
456457

457458
self.assertEquals(result.getvalue(), xml_test_out)
458459

459-
def test_expat_inpsource_sysid(self):
460+
def XXXtest_expat_inpsource_sysid(self):
461+
# FIXME: test blocks indefinitely
460462
parser = create_parser()
461463
result = StringIO()
462464
xmlgen = XMLGenerator(result)
@@ -529,7 +531,8 @@ def test_expat_locator_noinfo(self):
529531
self.assertEquals(parser.getPublicId(), None)
530532
self.assertEquals(parser.getLineNumber(), 1)
531533

532-
def test_expat_locator_withinfo(self):
534+
def XXXtest_expat_locator_withinfo(self):
535+
# FIXME: test blocks indefinitely
533536
result = StringIO()
534537
xmlgen = XMLGenerator(result)
535538
parser = create_parser()
@@ -684,7 +687,7 @@ def test_sf_1513611(self):
684687
self.assertRaises(SAXParseException, parser.parse, sio)
685688

686689

687-
def unittest_main():
690+
def test_main():
688691
run_unittest(MakeParserTest,
689692
SaxutilsTest,
690693
XmlgenTest,
@@ -693,4 +696,4 @@ def unittest_main():
693696
XmlReaderTest)
694697

695698
if __name__ == "__main__":
696-
unittest_main()
699+
test_main()

Lib/test/test_socket.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
import socket
77
import select
8-
import time
98
import thread, threading
9+
import time
10+
import traceback
1011
import Queue
1112
import sys
1213
import os
@@ -1016,10 +1017,13 @@ def alarm_handler(signal, frame):
10161017
except Alarm:
10171018
pass
10181019
except:
1019-
self.fail("caught other exception instead of Alarm")
1020+
self.fail("caught other exception instead of Alarm:"
1021+
" %s(%s):\n%s" %
1022+
(sys.exc_info()[:2] + (traceback.format_exc(),)))
10201023
else:
10211024
self.fail("nothing caught")
1022-
signal.alarm(0) # shut off alarm
1025+
finally:
1026+
signal.alarm(0) # shut off alarm
10231027
except Alarm:
10241028
self.fail("got Alarm in wrong place")
10251029
finally:

Lib/test/test_sqlite.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
except ImportError:
66
raise TestSkipped('no sqlite available')
77
from sqlite3.test import (dbapi, types, userfunctions,
8-
factory, transactions, hooks, regression)
8+
factory, transactions, hooks, regression,
9+
dump)
910

1011
def test_main():
1112
run_unittest(dbapi.suite(), types.suite(), userfunctions.suite(),
12-
factory.suite(), transactions.suite(), hooks.suite(),
13-
regression.suite())
13+
factory.suite(), transactions.suite(),
14+
hooks.suite(), regression.suite(), dump.suite())
1415

1516
if __name__ == "__main__":
1617
test_main()

Lib/test/test_telnetlib.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
from unittest import TestCase
77
from test import test_support
88

9+
PORT = 9091
910

1011
def server(evt):
1112
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1213
serv.settimeout(3)
1314
serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
14-
serv.bind(("", 9091))
15+
global PORT
16+
PORT = test_support.bind_port(serv, "", PORT)
1517
serv.listen(5)
1618
evt.set()
1719
try:
@@ -36,24 +38,24 @@ def tearDown(self):
3638

3739
def testBasic(self):
3840
# connects
39-
telnet = telnetlib.Telnet("localhost", 9091)
41+
telnet = telnetlib.Telnet("localhost", PORT)
4042
telnet.sock.close()
4143

4244
def testTimeoutDefault(self):
4345
# default
44-
telnet = telnetlib.Telnet("localhost", 9091)
46+
telnet = telnetlib.Telnet("localhost", PORT)
4547
self.assertTrue(telnet.sock.gettimeout() is None)
4648
telnet.sock.close()
4749

4850
def testTimeoutValue(self):
4951
# a value
50-
telnet = telnetlib.Telnet("localhost", 9091, timeout=30)
52+
telnet = telnetlib.Telnet("localhost", PORT, timeout=30)
5153
self.assertEqual(telnet.sock.gettimeout(), 30)
5254
telnet.sock.close()
5355

5456
def testTimeoutDifferentOrder(self):
5557
telnet = telnetlib.Telnet(timeout=30)
56-
telnet.open("localhost", 9091)
58+
telnet.open("localhost", PORT)
5759
self.assertEqual(telnet.sock.gettimeout(), 30)
5860
telnet.sock.close()
5961

@@ -62,7 +64,7 @@ def testTimeoutNone(self):
6264
previous = socket.getdefaulttimeout()
6365
socket.setdefaulttimeout(30)
6466
try:
65-
telnet = telnetlib.Telnet("localhost", 9091, timeout=None)
67+
telnet = telnetlib.Telnet("localhost", PORT, timeout=None)
6668
finally:
6769
socket.setdefaulttimeout(previous)
6870
self.assertEqual(telnet.sock.gettimeout(), 30)

Lib/test/test_threading.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,17 @@ def _run(self, other_ref, yet_another):
271271
weak_cyclic_object = weakref.ref(cyclic_object)
272272
cyclic_object.thread.join()
273273
del cyclic_object
274-
self.assertEquals(None, weak_cyclic_object())
274+
self.assertEquals(None, weak_cyclic_object(),
275+
msg=('%d references still around' %
276+
sys.getrefcount(weak_cyclic_object())))
275277

276278
raising_cyclic_object = RunSelfFunction(should_raise=True)
277279
weak_raising_cyclic_object = weakref.ref(raising_cyclic_object)
278280
raising_cyclic_object.thread.join()
279281
del raising_cyclic_object
280-
self.assertEquals(None, weak_raising_cyclic_object())
282+
self.assertEquals(None, weak_raising_cyclic_object(),
283+
msg=('%d references still around' %
284+
sys.getrefcount(weak_raising_cyclic_object())))
281285

282286

283287
class ThreadingExceptionTests(unittest.TestCase):

0 commit comments

Comments
 (0)