]> granicus.if.org Git - python/commitdiff
Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
authorChristian Heimes <christian@cheimes.de>
Fri, 28 Mar 2008 10:53:29 +0000 (10:53 +0000)
committerChristian Heimes <christian@cheimes.de>
Fri, 28 Mar 2008 10:53:29 +0000 (10:53 +0000)
svn+ssh://pythondev@svn.python.org/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.
........

25 files changed:
Doc/library/gzip.rst
Doc/library/sqlite3.rst
Include/Python.h
Include/bytes_methods.h
Lib/test/regrtest.py
Lib/test/test_sax.py
Lib/test/test_socket.py
Lib/test/test_sqlite.py
Lib/test/test_telnetlib.py
Lib/test/test_threading.py
Lib/test/test_urllib2_localnet.py
Lib/test/test_urllib2net.py
Lib/test/test_xmlrpc.py
Lib/threading.py
Misc/ACKS
Modules/_sqlite/connection.c
Objects/complexobject.c
Objects/floatobject.c
Objects/longobject.c
Objects/unicodeobject.c
Parser/tokenizer.c
Python/mystrtoul.c
configure
configure.in
pyconfig.h.in

index d298f8820e3e90395bfc2ccd3eb2311670d299e8..86be3cdd94d368ce5e489b3baf923d0a1aa9e9d3 100644 (file)
@@ -1,19 +1,22 @@
-
 :mod:`gzip` --- Support for :program:`gzip` files
 =================================================
 
 .. module:: gzip
    :synopsis: Interfaces for gzip compression and decompression using file objects.
 
+This module provides a simple interface to compress and decompress files just
+like the GNU programs :program:`gzip` and :program:`gunzip` would.
+
+The data compression is provided by the :mod:``zlib`` module.
 
-The data compression provided by the ``zlib`` module is compatible with that
-used by the GNU compression program :program:`gzip`. Accordingly, the
-:mod:`gzip` module provides the :class:`GzipFile` class to read and write
+The :mod:`gzip` module provides the :class:`GzipFile` class which is modeled
+after Python's File Object. The :class:`GzipFile` class reads and writes
 :program:`gzip`\ -format files, automatically compressing or decompressing the
-data so it looks like an ordinary file object.  Note that additional file
-formats which can be decompressed by the :program:`gzip` and :program:`gunzip`
-programs, such  as those produced by :program:`compress` and :program:`pack`,
-are not supported by this module.
+data so that it looks like an ordinary file object.
+
+Note that additional file formats which can be decompressed by the
+:program:`gzip` and :program:`gunzip` programs, such  as those produced by
+:program:`compress` and :program:`pack`, are not supported by this module.
 
 For other archive formats, see the :mod:`bz2`, :mod:`zipfile`, and
 :mod:`tarfile` modules.
@@ -63,6 +66,36 @@ The module defines the following items:
    *compresslevel* defaults to ``9``.
 
 
+.. _gzip-usage-examples:
+
+Examples of usage
+-----------------
+
+Example of how to read a compressed file::
+
+   import gzip
+   f = gzip.open('/home/joe/file.txt.gz', 'rb')
+   file_content = f.read()
+   f.close()
+
+Example of how to create a compressed GZIP file::
+
+   import gzip
+   content = "Lots of content here"
+   f = gzip.open('/home/joe/file.txt.gz', 'wb')
+   f.write(content)
+   f.close()
+
+Example of how to GZIP compress an existing file::
+
+   import gzip
+   f_in = open('/home/joe/file.txt', 'rb')
+   f_out = gzip.open('/home/joe/file.txt.gz', 'wb')
+   f_out.writelines(f_in)
+   f_out.close()
+   f_in.close()
+
+
 .. seealso::
 
    Module :mod:`zlib`
index 5585934db404961489e553f7c7bdcc67c1674e99..d9ce73ef080939f5052c9ea0a8c6c73ec8a4999f 100644 (file)
@@ -376,6 +376,27 @@ A :class:`Connection` instance has the following attributes and methods:
    deleted since the database connection was opened.
 
 
+.. attribute:: Connection.iterdump
+
+   Returns an iterator to dump the database in an SQL text format.  Useful when
+   saving an in-memory database for later restoration.  This function provides
+   the same capabilities as the :kbd:`.dump` command in the :program:`sqlite3`
+   shell.
+
+   .. versionadded:: 2.6
+
+   Example::
+
+      # Convert file existing_db.db to SQL dump file dump.sql
+      import sqlite3, os
+
+      con = sqlite3.connect('existing_db.db')
+      full_dump = os.linesep.join([line for line in con.iterdump()])
+      f = open('dump.sql', 'w')
+      f.writelines(full_dump)
+      f.close()
+
+
 .. _sqlite3-cursor-objects:
 
 Cursor Objects
index d8c2a56d2dde0a0fe042bb74e756e49cad1bedcd..d16143bb3daeb588615d9e3f1dfba44d79afc33e 100644 (file)
@@ -124,7 +124,7 @@ PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
 #ifdef __CHAR_UNSIGNED__
 #define Py_CHARMASK(c)         (c)
 #else
-#define Py_CHARMASK(c)         ((c) & 0xff)
+#define Py_CHARMASK(c)         ((unsigned char)((c) & 0xff))
 #endif
 
 #include "pyfpe.h"
index a05e11f433dcea28f00a05a8d78716d4f800a924..59873f29a0737849688b935990e0a3b7406e8da2 100644 (file)
@@ -44,13 +44,13 @@ extern const char _Py_swapcase__doc__[];
 
 extern const unsigned int _Py_ctype_table[256];
 
-#define ISLOWER(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_LOWER)
-#define ISUPPER(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_UPPER)
-#define ISALPHA(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_ALPHA)
-#define ISDIGIT(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_DIGIT)
-#define ISXDIGIT(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_XDIGIT)
-#define ISALNUM(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_ALNUM)
-#define ISSPACE(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_SPACE)
+#define ISLOWER(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_LOWER)
+#define ISUPPER(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_UPPER)
+#define ISALPHA(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_ALPHA)
+#define ISDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_DIGIT)
+#define ISXDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_XDIGIT)
+#define ISALNUM(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_ALNUM)
+#define ISSPACE(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_SPACE)
 
 #undef islower
 #define islower(c) undefined_islower(c)
index 9b8b5725ef410fba5b28f9bc9f3cf1503b1543fb..000f241c645af63eb3f1c273fe24377d8db30a7f 100755 (executable)
@@ -529,7 +529,6 @@ NOTTESTS = {
     'test_support',
     'test_future1',
     'test_future2',
-    'test_future3',
 }
 
 def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
index a411bfd8787c6bd8987ab9542909efbd0792b106..eb795813ae77e0233e770340a5597d9b73b2f980 100644 (file)
@@ -446,7 +446,8 @@ class ExpatReaderTest(XmlTestBase):
 
     # ===== InputSource support
 
-    def test_expat_inpsource_filename(self):
+    def XXXtest_expat_inpsource_filename(self):
+        # FIXME: test blocks indefinitely
         parser = create_parser()
         result = StringIO()
         xmlgen = XMLGenerator(result)
@@ -456,7 +457,8 @@ class ExpatReaderTest(XmlTestBase):
 
         self.assertEquals(result.getvalue(), xml_test_out)
 
-    def test_expat_inpsource_sysid(self):
+    def XXXtest_expat_inpsource_sysid(self):
+        # FIXME: test blocks indefinitely
         parser = create_parser()
         result = StringIO()
         xmlgen = XMLGenerator(result)
@@ -529,7 +531,8 @@ class ExpatReaderTest(XmlTestBase):
         self.assertEquals(parser.getPublicId(), None)
         self.assertEquals(parser.getLineNumber(), 1)
 
-    def test_expat_locator_withinfo(self):
+    def XXXtest_expat_locator_withinfo(self):
+        # FIXME: test blocks indefinitely
         result = StringIO()
         xmlgen = XMLGenerator(result)
         parser = create_parser()
@@ -684,7 +687,7 @@ class XmlReaderTest(XmlTestBase):
         self.assertRaises(SAXParseException, parser.parse, sio)
 
 
-def unittest_main():
+def test_main():
     run_unittest(MakeParserTest,
                  SaxutilsTest,
                  XmlgenTest,
@@ -693,4 +696,4 @@ def unittest_main():
                  XmlReaderTest)
 
 if __name__ == "__main__":
-    unittest_main()
+    test_main()
index d3b870f9b8d718b106071d6ed4474d3895cdef0d..2bec373ed965debece65b4d556d86f0fb97ae0b5 100644 (file)
@@ -5,8 +5,9 @@ from test import test_support
 
 import socket
 import select
-import time
 import thread, threading
+import time
+import traceback
 import Queue
 import sys
 import os
@@ -1016,10 +1017,13 @@ class TCPTimeoutTest(SocketTCPTest):
             except Alarm:
                 pass
             except:
-                self.fail("caught other exception instead of Alarm")
+                self.fail("caught other exception instead of Alarm:"
+                          " %s(%s):\n%s" %
+                          (sys.exc_info()[:2] + (traceback.format_exc(),)))
             else:
                 self.fail("nothing caught")
-            signal.alarm(0)         # shut off alarm
+            finally:
+                signal.alarm(0)         # shut off alarm
         except Alarm:
             self.fail("got Alarm in wrong place")
         finally:
index c1523e11ba3522d78f828143c8969c1edd843eaf..945dd511b89b052e73cbe323d6a413f88e6860c8 100644 (file)
@@ -5,12 +5,13 @@ try:
 except ImportError:
     raise TestSkipped('no sqlite available')
 from sqlite3.test import (dbapi, types, userfunctions,
-                                factory, transactions, hooks, regression)
+                                factory, transactions, hooks, regression,
+                                dump)
 
 def test_main():
     run_unittest(dbapi.suite(), types.suite(), userfunctions.suite(),
-                 factory.suite(), transactions.suite(), hooks.suite(),
-                 regression.suite())
+                 factory.suite(), transactions.suite(),
+                 hooks.suite(), regression.suite(), dump.suite())
 
 if __name__ == "__main__":
     test_main()
index 3a53ad9079c0ff9992e662147c6f51ba5a088af6..8eee6667af54112124f3e3d7141d83212ddb836e 100644 (file)
@@ -6,12 +6,14 @@ import time
 from unittest import TestCase
 from test import test_support
 
+PORT = 9091
 
 def server(evt):
     serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     serv.settimeout(3)
     serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-    serv.bind(("", 9091))
+    global PORT
+    PORT = test_support.bind_port(serv, "", PORT)
     serv.listen(5)
     evt.set()
     try:
@@ -36,24 +38,24 @@ class GeneralTests(TestCase):
 
     def testBasic(self):
         # connects
-        telnet = telnetlib.Telnet("localhost", 9091)
+        telnet = telnetlib.Telnet("localhost", PORT)
         telnet.sock.close()
 
     def testTimeoutDefault(self):
         # default
-        telnet = telnetlib.Telnet("localhost", 9091)
+        telnet = telnetlib.Telnet("localhost", PORT)
         self.assertTrue(telnet.sock.gettimeout() is None)
         telnet.sock.close()
 
     def testTimeoutValue(self):
         # a value
-        telnet = telnetlib.Telnet("localhost", 9091, timeout=30)
+        telnet = telnetlib.Telnet("localhost", PORT, timeout=30)
         self.assertEqual(telnet.sock.gettimeout(), 30)
         telnet.sock.close()
 
     def testTimeoutDifferentOrder(self):
         telnet = telnetlib.Telnet(timeout=30)
-        telnet.open("localhost", 9091)
+        telnet.open("localhost", PORT)
         self.assertEqual(telnet.sock.gettimeout(), 30)
         telnet.sock.close()
 
@@ -62,7 +64,7 @@ class GeneralTests(TestCase):
         previous = socket.getdefaulttimeout()
         socket.setdefaulttimeout(30)
         try:
-            telnet = telnetlib.Telnet("localhost", 9091, timeout=None)
+            telnet = telnetlib.Telnet("localhost", PORT, timeout=None)
         finally:
             socket.setdefaulttimeout(previous)
         self.assertEqual(telnet.sock.gettimeout(), 30)
index 67d9ed95374be1a223982f1ab1ff36c60b341a82..ee0b197097b38b3fed3684c773914001ecc7d32f 100644 (file)
@@ -271,13 +271,17 @@ class ThreadTests(unittest.TestCase):
         weak_cyclic_object = weakref.ref(cyclic_object)
         cyclic_object.thread.join()
         del cyclic_object
-        self.assertEquals(None, weak_cyclic_object())
+        self.assertEquals(None, weak_cyclic_object(),
+                          msg=('%d references still around' %
+                               sys.getrefcount(weak_cyclic_object())))
 
         raising_cyclic_object = RunSelfFunction(should_raise=True)
         weak_raising_cyclic_object = weakref.ref(raising_cyclic_object)
         raising_cyclic_object.thread.join()
         del raising_cyclic_object
-        self.assertEquals(None, weak_raising_cyclic_object())
+        self.assertEquals(None, weak_raising_cyclic_object(),
+                          msg=('%d references still around' %
+                               sys.getrefcount(weak_raising_cyclic_object())))
 
 
 class ThreadingExceptionTests(unittest.TestCase):
index 663330ba93faf31b27fe7fecade8f4560727e5d8..0815658602fdd2d7093a4fe6ae5405851ee600ce 100644 (file)
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+import mimetools
 import threading
 import urlparse
 import urllib2
@@ -217,7 +218,7 @@ class FakeProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
 # Test cases
 
 class ProxyAuthTests(unittest.TestCase):
-    URL = "http://www.foo.com"
+    URL = "http://localhost"
 
     USER = "tester"
     PASSWD = "test123"
@@ -279,6 +280,202 @@ class ProxyAuthTests(unittest.TestCase):
                 pass
             result.close()
 
+
+def GetRequestHandler(responses):
+
+    class FakeHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+
+        server_version = "TestHTTP/"
+        requests = []
+        headers_received = []
+        port = 80
+
+        def do_GET(self):
+            body = self.send_head()
+            if body:
+                self.wfile.write(body)
+
+        def do_POST(self):
+            content_length = self.headers['Content-Length']
+            post_data = self.rfile.read(int(content_length))
+            self.do_GET()
+            self.requests.append(post_data)
+
+        def send_head(self):
+            FakeHTTPRequestHandler.headers_received = self.headers
+            self.requests.append(self.path)
+            response_code, headers, body = responses.pop(0)
+
+            self.send_response(response_code)
+
+            for (header, value) in headers:
+                self.send_header(header, value % self.port)
+            if body:
+                self.send_header('Content-type', 'text/plain')
+                self.end_headers()
+                return body
+            self.end_headers()
+
+        def log_message(self, *args):
+            pass
+
+
+    return FakeHTTPRequestHandler
+
+
+class TestUrlopen(unittest.TestCase):
+    """Tests urllib2.urlopen using the network.
+
+    These tests are not exhaustive.  Assuming that testing using files does a
+    good job overall of some of the basic interface features.  There are no
+    tests exercising the optional 'data' and 'proxies' arguments.  No tests
+    for transparent redirection have been written.
+    """
+
+    def start_server(self, responses):
+        handler = GetRequestHandler(responses)
+
+        self.server = LoopbackHttpServerThread(handler)
+        self.server.start()
+        self.server.ready.wait()
+        port = self.server.port
+        handler.port = port
+        return handler
+
+
+    def test_redirection(self):
+        expected_response = b'We got here...'
+        responses = [
+            (302, [('Location', 'http://localhost:%s/somewhere_else')], ''),
+            (200, [], expected_response)
+        ]
+
+        handler = self.start_server(responses)
+
+        try:
+            f = urllib2.urlopen('http://localhost:%s/' % handler.port)
+            data = f.read()
+            f.close()
+
+            self.assertEquals(data, expected_response)
+            self.assertEquals(handler.requests, ['/', '/somewhere_else'])
+        finally:
+            self.server.stop()
+
+
+    def test_404(self):
+        expected_response = b'Bad bad bad...'
+        handler = self.start_server([(404, [], expected_response)])
+
+        try:
+            try:
+                urllib2.urlopen('http://localhost:%s/weeble' % handler.port)
+            except urllib2.URLError as f:
+                data = f.read()
+                f.close()
+            else:
+                self.fail('404 should raise URLError')
+
+            self.assertEquals(data, expected_response)
+            self.assertEquals(handler.requests, ['/weeble'])
+        finally:
+            self.server.stop()
+
+
+    def test_200(self):
+        expected_response = b'pycon 2008...'
+        handler = self.start_server([(200, [], expected_response)])
+
+        try:
+            f = urllib2.urlopen('http://localhost:%s/bizarre' % handler.port)
+            data = f.read()
+            f.close()
+
+            self.assertEquals(data, expected_response)
+            self.assertEquals(handler.requests, ['/bizarre'])
+        finally:
+            self.server.stop()
+
+    def test_200_with_parameters(self):
+        expected_response = b'pycon 2008...'
+        handler = self.start_server([(200, [], expected_response)])
+
+        try:
+            f = urllib2.urlopen('http://localhost:%s/bizarre' % handler.port, b'get=with_feeling')
+            data = f.read()
+            f.close()
+
+            self.assertEquals(data, expected_response)
+            self.assertEquals(handler.requests, ['/bizarre', b'get=with_feeling'])
+        finally:
+            self.server.stop()
+
+
+    def test_sending_headers(self):
+        handler = self.start_server([(200, [], b"we don't care")])
+
+        try:
+            req = urllib2.Request("http://localhost:%s/" % handler.port,
+                                  headers={'Range': 'bytes=20-39'})
+            urllib2.urlopen(req)
+            self.assertEqual(handler.headers_received['Range'], 'bytes=20-39')
+        finally:
+            self.server.stop()
+
+    def test_basic(self):
+        handler = self.start_server([(200, [], b"we don't care")])
+
+        try:
+            open_url = urllib2.urlopen("http://localhost:%s" % handler.port)
+            for attr in ("read", "close", "info", "geturl"):
+                self.assert_(hasattr(open_url, attr), "object returned from "
+                             "urlopen lacks the %s attribute" % attr)
+            try:
+                self.assert_(open_url.read(), "calling 'read' failed")
+            finally:
+                open_url.close()
+        finally:
+            self.server.stop()
+
+    def test_info(self):
+        handler = self.start_server([(200, [], b"we don't care")])
+
+        try:
+            open_url = urllib2.urlopen("http://localhost:%s" % handler.port)
+            info_obj = open_url.info()
+            self.assert_(isinstance(info_obj, mimetools.Message),
+                         "object returned by 'info' is not an instance of "
+                         "mimetools.Message")
+            self.assertEqual(info_obj.getsubtype(), "plain")
+        finally:
+            self.server.stop()
+
+    def test_geturl(self):
+        # Make sure same URL as opened is returned by geturl.
+        handler = self.start_server([(200, [], b"we don't care")])
+
+        try:
+            open_url = urllib2.urlopen("http://localhost:%s" % handler.port)
+            url = open_url.geturl()
+            self.assertEqual(url, "http://localhost:%s" % handler.port)
+        finally:
+            self.server.stop()
+
+
+    def test_bad_address(self):
+        # Make sure proper exception is raised when connecting to a bogus
+        # address.
+        self.assertRaises(IOError,
+                          # SF patch 809915:  In Sep 2003, VeriSign started
+                          # highjacking invalid .com and .net addresses to
+                          # boost traffic to their own site.  This test
+                          # started failing then.  One hopes the .invalid
+                          # domain will be spared to serve its defined
+                          # purpose.
+                          # urllib2.urlopen, "http://www.sadflkjsasadf.com/")
+                          urllib2.urlopen, "http://www.python.invalid./")
+
+
 def test_main():
     # We will NOT depend on the network resource flag
     # (Lib/test/regrtest.py -u network) since all tests here are only
@@ -287,6 +484,7 @@ def test_main():
     #test_support.requires("network")
 
     test_support.run_unittest(ProxyAuthTests)
+    test_support.run_unittest(TestUrlopen)
 
 if __name__ == "__main__":
     test_main()
index dc3d884194f30bf8dd1cfb95f90467e573bfdcb5..75df9fd7b932b2af5c616c40c0f05989506bff83 100644 (file)
@@ -25,20 +25,6 @@ def _urlopen_with_retry(host, *args, **kwargs):
     raise last_exc
 
 
-class URLTimeoutTest(unittest.TestCase):
-
-    TIMEOUT = 10.0
-
-    def setUp(self):
-        socket.setdefaulttimeout(self.TIMEOUT)
-
-    def tearDown(self):
-        socket.setdefaulttimeout(None)
-
-    def testURLread(self):
-        f = _urlopen_with_retry("http://www.python.org/")
-        x = f.read()
-
 
 class AuthTests(unittest.TestCase):
     """Tests urllib2 authentication features."""
@@ -98,68 +84,6 @@ class CloseSocketTest(unittest.TestCase):
         response.close()
         self.assert_(fileobject.closed)
 
-class urlopenNetworkTests(unittest.TestCase):
-    """Tests urllib2.urlopen using the network.
-
-    These tests are not exhaustive.  Assuming that testing using files does a
-    good job overall of some of the basic interface features.  There are no
-    tests exercising the optional 'data' and 'proxies' arguments.  No tests
-    for transparent redirection have been written.
-
-    setUp is not used for always constructing a connection to
-    http://www.python.org/ since there a few tests that don't use that address
-    and making a connection is expensive enough to warrant minimizing unneeded
-    connections.
-
-    """
-
-    def test_basic(self):
-        # Simple test expected to pass.
-        open_url = _urlopen_with_retry("http://www.python.org/")
-        for attr in ("read", "close", "info", "geturl"):
-            self.assert_(hasattr(open_url, attr), "object returned from "
-                            "urlopen lacks the %s attribute" % attr)
-        try:
-            self.assert_(open_url.read(), "calling 'read' failed")
-        finally:
-            open_url.close()
-
-    def test_info(self):
-        # Test 'info'.
-        open_url = _urlopen_with_retry("http://www.python.org/")
-        try:
-            info_obj = open_url.info()
-        finally:
-            open_url.close()
-            self.assert_(isinstance(info_obj, mimetools.Message),
-                         "object returned by 'info' is not an instance of "
-                         "mimetools.Message")
-            self.assertEqual(info_obj.getsubtype(), "html")
-
-    def test_geturl(self):
-        # Make sure same URL as opened is returned by geturl.
-        URL = "http://www.python.org/"
-        open_url = _urlopen_with_retry(URL)
-        try:
-            gotten_url = open_url.geturl()
-        finally:
-            open_url.close()
-        self.assertEqual(gotten_url, URL)
-
-    def test_bad_address(self):
-        # Make sure proper exception is raised when connecting to a bogus
-        # address.
-        self.assertRaises(IOError,
-                          # SF patch 809915:  In Sep 2003, VeriSign started
-                          # highjacking invalid .com and .net addresses to
-                          # boost traffic to their own site.  This test
-                          # started failing then.  One hopes the .invalid
-                          # domain will be spared to serve its defined
-                          # purpose.
-                          # urllib2.urlopen, "http://www.sadflkjsasadf.com/")
-                          urllib2.urlopen, "http://www.python.invalid./")
-
-
 class OtherNetworkTests(unittest.TestCase):
     def setUp(self):
         if 0:  # for debugging
@@ -167,13 +91,6 @@ class OtherNetworkTests(unittest.TestCase):
             logger = logging.getLogger("test_urllib2net")
             logger.addHandler(logging.StreamHandler())
 
-    def test_range (self):
-        req = urllib2.Request("http://www.python.org",
-                              headers={'Range': 'bytes=20-39'})
-        result = _urlopen_with_retry(req)
-        data = result.read()
-        self.assertEqual(len(data), 20)
-
     # XXX The rest of these tests aren't very good -- they don't check much.
     # They do sometimes catch some major disasters, though.
 
@@ -201,16 +118,6 @@ class OtherNetworkTests(unittest.TestCase):
         finally:
             os.remove(TESTFN)
 
-    def test_http(self):
-        urls = [
-            'http://www.espn.com/', # redirect
-            'http://www.python.org/Spanish/Inquistion/',
-            ('http://www.python.org/cgi-bin/faqw.py',
-             'query=pythonistas&querytype=simple&casefold=yes&req=search', None),
-            'http://www.python.org/',
-            ]
-        self._test_urls(urls, self._extra_handlers())
-
     # XXX Following test depends on machine configurations that are internal
     # to CNRI.  Need to set up a public server with the right authentication
     # configuration for test purposes.
@@ -278,6 +185,7 @@ class OtherNetworkTests(unittest.TestCase):
 
         return handlers
 
+
 class TimeoutTest(unittest.TestCase):
     def test_http_basic(self):
         u = _urlopen_with_retry("http://www.python.org")
@@ -326,9 +234,7 @@ class TimeoutTest(unittest.TestCase):
 
 def test_main():
     test_support.requires("network")
-    test_support.run_unittest(URLTimeoutTest,
-                              urlopenNetworkTests,
-                              AuthTests,
+    test_support.run_unittest(AuthTests,
                               OtherNetworkTests,
                               CloseSocketTest,
                               TimeoutTest,
index 77d45253c8c26e924ea3940f98ac23ca90056e9b..0691f23847bf5d932c7570e94ae9613d236ac1f4 100644 (file)
@@ -238,9 +238,17 @@ def http_server(evt, numrequests):
         '''This is my function'''
         return True
 
+    class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer):
+        def get_request(self):
+            # Ensure the socket is always non-blocking.  On Linux, socket
+            # attributes are not inherited like they are on *BSD and Windows.
+            s, port = self.socket.accept()
+            s.setblocking(True)
+            return s, port
+
     try:
-        serv = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 0),
-                        logRequests=False, bind_and_activate=False)
+        serv = MyXMLRPCServer(("localhost", 0),
+                              logRequests=False, bind_and_activate=False)
         serv.server_bind()
         global PORT
         PORT = serv.socket.getsockname()[1]
index d010b80f6fe1bde2eda11b21e2893e7f0a718dcb..8661cde9ca62b7d2cca9bedd69025195076f8b64 100644 (file)
@@ -391,6 +391,9 @@ class Thread(_Verbose):
     # shutdown and thus raises an exception about trying to perform some
     # operation on/with a NoneType
     __exc_info = _sys.exc_info
+    # Keep sys.exc_clear too to clear the exception just before
+    # allowing .join() to return.
+    #XXX __exc_clear = _sys.exc_clear
 
     def __init__(self, group=None, target=None, name=None,
                  args=(), kwargs=None, verbose=None):
@@ -527,6 +530,13 @@ class Thread(_Verbose):
             else:
                 if __debug__:
                     self._note("%s._bootstrap(): normal return", self)
+            finally:
+                # Prevent a race in
+                # test_threading.test_no_refcycle_through_target when
+                # the exception keeps the target alive past when we
+                # assert that it's dead.
+                #XXX self.__exc_clear()
+                pass
         finally:
             with _active_limbo_lock:
                 self._stop()
index 196c14895610b2dc29650e692c7337bb6b752857..4aa01011d67dc6c29804c43379e802916644ad28 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -361,6 +361,7 @@ Lawrence Kesteloot
 Vivek Khera
 Mads Kiilerich
 Taek Joo Kim
+Paul Kippes
 Steve Kirsch
 Ron Klatchko
 Bastian Kleineidam
index 9451881e9645ecc7b5f6b9974fb94be6baad1e58..11a14a1dcec7d1aafcd1b6d5ebbcbe33eb671164 100644 (file)
@@ -1,6 +1,6 @@
 /* connection.c - the connection type
  *
- * Copyright (C) 2004-2006 Gerhard Häring <gh@ghaering.de>
+ * Copyright (C) 2004-2006 Gerhard Hring <gh@ghaering.de>
  *
  * This file is part of pysqlite.
  * 
@@ -1069,6 +1069,52 @@ finally:
     return retval;
 }
 
+/* Function author: Paul Kippes <kippesp@gmail.com>
+ * Class method of Connection to call the Python function _iterdump
+ * of the sqlite3 module.
+ */
+static PyObject *
+pysqlite_connection_iterdump(pysqlite_Connection* self, PyObject* args)
+{
+    PyObject* retval = NULL;
+    PyObject* module = NULL;
+    PyObject* module_dict;
+    PyObject* pyfn_iterdump;
+
+    if (!pysqlite_check_connection(self)) {
+        goto finally;
+    }
+
+    module = PyImport_ImportModule(MODULE_NAME ".dump");
+    if (!module) {
+        goto finally;
+    }
+
+    module_dict = PyModule_GetDict(module);
+    if (!module_dict) {
+        goto finally;
+    }
+
+    pyfn_iterdump = PyDict_GetItemString(module_dict, "_iterdump");
+    if (!pyfn_iterdump) {
+        PyErr_SetString(pysqlite_OperationalError, "Failed to obtain _iterdump() reference");
+        goto finally;
+    }
+
+    args = PyTuple_New(1);
+    if (!args) {
+        goto finally;
+    }
+    Py_INCREF(self);
+    PyTuple_SetItem(args, 0, (PyObject*)self);
+    retval = PyObject_CallObject(pyfn_iterdump, args);
+
+finally:
+    Py_XDECREF(args);
+    Py_XDECREF(module);
+    return retval;
+}
+
 static PyObject *
 pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
 {
@@ -1140,6 +1186,43 @@ finally:
     return retval;
 }
 
+/* Called when the connection is used as a context manager. Returns itself as a
+ * convenience to the caller. */
+static PyObject *
+pysqlite_connection_enter(pysqlite_Connection* self, PyObject* args)
+{
+    Py_INCREF(self);
+    return (PyObject*)self;
+}
+
+/** Called when the connection is used as a context manager. If there was any
+ * exception, a rollback takes place; otherwise we commit. */
+static PyObject *
+pysqlite_connection_exit(pysqlite_Connection* self, PyObject* args)
+{
+    PyObject* exc_type, *exc_value, *exc_tb;
+    char* method_name;
+    PyObject* result;
+
+    if (!PyArg_ParseTuple(args, "OOO", &exc_type, &exc_value, &exc_tb)) {
+        return NULL;
+    }
+
+    if (exc_type == Py_None && exc_value == Py_None && exc_tb == Py_None) {
+        method_name = "commit";
+    } else {
+        method_name = "rollback";
+    }
+
+    result = PyObject_CallMethod((PyObject*)self, method_name, "");
+    if (!result) {
+        return NULL;
+    }
+    Py_DECREF(result);
+
+    Py_RETURN_FALSE;
+}
+
 static char connection_doc[] =
 PyDoc_STR("SQLite database connection object.");
 
@@ -1174,6 +1257,13 @@ static PyMethodDef connection_methods[] = {
         PyDoc_STR("Creates a collation function. Non-standard.")},
     {"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS,
         PyDoc_STR("Abort any pending database operation. Non-standard.")},
+    {"iterdump", (PyCFunction)pysqlite_connection_iterdump, METH_NOARGS,
+        PyDoc_STR("Returns iterator to the dump of the database in an SQL text"
+                  "format.")},
+    {"__enter__", (PyCFunction)pysqlite_connection_enter, METH_NOARGS,
+        PyDoc_STR("For context manager. Non-standard.")},
+    {"__exit__", (PyCFunction)pysqlite_connection_exit, METH_VARARGS,
+        PyDoc_STR("For context manager. Non-standard.")},
     {NULL, NULL}
 };
 
index a47cd549c558ae06d16cdd82409658e9e89749ba..90b970eea9eafe4f77642b846d446e975de39c0b 100644 (file)
@@ -8,6 +8,10 @@
 #include "Python.h"
 #include "structmember.h"
 
+#ifdef HAVE_IEEEFP_H
+#include <ieeefp.h>
+#endif
+
 #ifndef WITHOUT_COMPLEX
 
 /* Precisions used by repr() and str(), respectively.
index 20f1510b86caf1afc44fdd79360ed74b9302d631..745dfc393840943cd5a7b3e30c8e1092308d1235 100644 (file)
 #include <ctype.h>
 #include <float.h>
 
+#ifdef HAVE_IEEEFP_H
+#include <ieeefp.h>
+#endif
+
 #if !defined(__STDC__)
 extern double fmod(double, double);
 extern double pow(double, double);
index b8725dfe01359a7d6cd4d72b71ed746b012e2c85..1d4b502f847f8138e4198a3431beb4184e36f9a9 100644 (file)
@@ -1620,7 +1620,7 @@ long_from_binary_base(char **str, int base)
                n >>= 1;
        /* n <- total # of bits needed, while setting p to end-of-string */
        n = 0;
-       while (_PyLong_DigitValue[(unsigned)Py_CHARMASK(*p)] < base)
+       while (_PyLong_DigitValue[Py_CHARMASK(*p)] < base)
                ++p;
        *str = p;
        /* n <- # of Python digits needed, = ceiling(n/PyLong_SHIFT). */
@@ -1641,7 +1641,7 @@ long_from_binary_base(char **str, int base)
        bits_in_accum = 0;
        pdigit = z->ob_digit;
        while (--p >= start) {
-               int k = _PyLong_DigitValue[(unsigned)Py_CHARMASK(*p)];
+               int k = _PyLong_DigitValue[Py_CHARMASK(*p)];
                assert(k >= 0 && k < base);
                accum |= (twodigits)(k << bits_in_accum);
                bits_in_accum += bits_per_char;
@@ -1828,7 +1828,7 @@ digit beyond the first.
 
                /* Find length of the string of numeric characters. */
                scan = str;
-               while (_PyLong_DigitValue[(unsigned)Py_CHARMASK(*scan)] < base)
+               while (_PyLong_DigitValue[Py_CHARMASK(*scan)] < base)
                        ++scan;
 
                /* Create a long object that can contain the largest possible
@@ -1854,10 +1854,10 @@ digit beyond the first.
                /* Work ;-) */
                while (str < scan) {
                        /* grab up to convwidth digits from the input string */
-                       c = (digit)_PyLong_DigitValue[(unsigned)Py_CHARMASK(*str++)];
+                       c = (digit)_PyLong_DigitValue[Py_CHARMASK(*str++)];
                        for (i = 1; i < convwidth && str != scan; ++i, ++str) {
                                c = (twodigits)(c *  base +
-                                       _PyLong_DigitValue[(unsigned)Py_CHARMASK(*str)]);
+                                       _PyLong_DigitValue[Py_CHARMASK(*str)]);
                                assert(c < PyLong_BASE);
                        }
 
index fef304aeb266752e213aa39d8c4219e182ca322c..60cbffa59f43cf0d694e91c67d40a064bbca1fb7 100644 (file)
@@ -512,13 +512,13 @@ PyObject *PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size)
        /* Single characters are shared when using this constructor.
            Restrict to ASCII, since the input must be UTF-8. */
        if (size == 1 && Py_CHARMASK(*u) < 128) {
-           unicode = unicode_latin1[(unsigned)Py_CHARMASK(*u)];
+           unicode = unicode_latin1[Py_CHARMASK(*u)];
            if (!unicode) {
                unicode = _PyUnicode_New(1);
                if (!unicode)
                    return NULL;
                unicode->str[0] = Py_CHARMASK(*u);
-               unicode_latin1[(unsigned)Py_CHARMASK(*u)] = unicode;
+               unicode_latin1[Py_CHARMASK(*u)] = unicode;
            }
            Py_INCREF(unicode);
            return (PyObject *)unicode;
index 0b8341a0a2742274a6b449520c692fb9288f5bb9..959a0cac9cafe4b428a503f96c2de664d1145047 100644 (file)
@@ -39,14 +39,6 @@ extern char *PyOS_Readline(FILE *, FILE *, char *);
 /* Don't ever change this -- it would break the portability of Python code */
 #define TABSIZE 8
 
-/* Convert a possibly signed character to a nonnegative int */
-/* XXX This assumes characters are 8 bits wide */
-#ifdef __CHAR_UNSIGNED__
-#define Py_CHARMASK(c)         (c)
-#else
-#define Py_CHARMASK(c)         ((c) & 0xff)
-#endif
-
 /* Forward */
 static struct tok_state *tok_new(void);
 static int tok_nextc(struct tok_state *tok);
index ac34c26e48a1813d9560daed7f7715b86aadc025..347f361e03f6d3242012b49a5894ad7a6b3415da 100644 (file)
@@ -109,7 +109,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                        ++str;
                        if (*str == 'x' || *str == 'X') {
                                /* there must be at least one digit after 0x */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 16) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -118,7 +118,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                                base = 16;
                        } else if (*str == 'o' || *str == 'O') {
                                /* there must be at least one digit after 0o */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 8) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 8) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -127,7 +127,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                                base = 8;
                        } else if (*str == 'b' || *str == 'B') {
                                /* there must be at least one digit after 0b */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 2) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -155,7 +155,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                        ++str;
                        if (*str == 'x' || *str == 'X') {
                                /* there must be at least one digit after 0x */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 16) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -169,7 +169,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                        ++str;
                        if (*str == 'o' || *str == 'O') {
                                /* there must be at least one digit after 0o */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 8) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 8) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -183,7 +183,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                        ++str;
                        if (*str == 'b' || *str == 'B') {
                                /* there must be at least one digit after 0b */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 2) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -209,7 +209,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
        ovlimit = digitlimit[base];
 
        /* do the conversion until non-digit character encountered */
-       while ((c = _PyLong_DigitValue[(unsigned)Py_CHARMASK(*str)]) < base) {
+       while ((c = _PyLong_DigitValue[Py_CHARMASK(*str)]) < base) {
                if (ovlimit > 0) /* no overflow check required */
                        result = result * base + c;
                else { /* requires overflow check */
@@ -246,7 +246,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
 overflowed:
        if (ptr) {
                /* spool through remaining digit characters */
-               while (_PyLong_DigitValue[(unsigned)Py_CHARMASK(*str)] < base)
+               while (_PyLong_DigitValue[Py_CHARMASK(*str)] < base)
                        ++str;
                *ptr = str;
        }
index 7fa106f77b7edbad40327fa04632b589b1c3d2c1..37d97260df14a203f303315210566d1589a66187 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 61728 .
+# From configure.in Revision: 61848 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61 for python 3.0.
 #
@@ -5390,11 +5390,12 @@ done
 
 
 
+
 
 
 for ac_header in asm/types.h conio.h curses.h direct.h dlfcn.h errno.h \
 fcntl.h grp.h \
-io.h langinfo.h libintl.h ncurses.h poll.h process.h pthread.h \
+ieeefp.h io.h langinfo.h libintl.h ncurses.h poll.h process.h pthread.h \
 shadow.h signal.h stdint.h stropts.h termios.h thread.h \
 unistd.h utime.h \
 sys/audioio.h sys/bsdtty.h sys/epoll.h sys/event.h sys/file.h sys/loadavg.h \
index 664c9656bbdf10389ab085587d0e7bcebf444ee1..dd96bbeb5ee6ec2313d8bbf5b103a59260bd15ea 100644 (file)
@@ -1074,7 +1074,7 @@ dnl AC_MSG_RESULT($cpp_type)
 AC_HEADER_STDC
 AC_CHECK_HEADERS(asm/types.h conio.h curses.h direct.h dlfcn.h errno.h \
 fcntl.h grp.h \
-io.h langinfo.h libintl.h ncurses.h poll.h process.h pthread.h \
+ieeefp.h io.h langinfo.h libintl.h ncurses.h poll.h process.h pthread.h \
 shadow.h signal.h stdint.h stropts.h termios.h thread.h \
 unistd.h utime.h \
 sys/audioio.h sys/bsdtty.h sys/epoll.h sys/event.h sys/file.h sys/loadavg.h \
index 732b8ff9fb98e13af144f17a4e03e9b43f2f19d7..ef26f8206ee0519ebbaebace48d583e57cff9e48 100644 (file)
 /* Define to 1 if you have the `hypot' function. */
 #undef HAVE_HYPOT
 
+/* Define to 1 if you have the <ieeefp.h> header file. */
+#undef HAVE_IEEEFP_H
+
 /* Define if you have the 'inet_aton' function. */
 #undef HAVE_INET_ATON