Rev 5270: Fix another python tiny bug revealed by pycurl being picky. in file:///home/vila/src/bzr/experimental/leaking-tests/

Vincent Ladeuil v.ladeuil+lp at free.fr
Sat Jun 5 10:01:06 BST 2010


At file:///home/vila/src/bzr/experimental/leaking-tests/

------------------------------------------------------------
revno: 5270
revision-id: v.ladeuil+lp at free.fr-20100605090106-x5intbf9udhfpvwu
parent: v.ladeuil+lp at free.fr-20100604163107-z04iiarg4nbwgzai
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: http-leaks
timestamp: Sat 2010-06-05 11:01:06 +0200
message:
  Fix another python tiny bug revealed by pycurl being picky.
  
  * bzrlib/tests/http_server.py:
  (TestingHTTPRequestHandler.handle): Ovverride to properly close
  the underlying socket that SocketServer.StreamRequestHandler leave
  opened.
  (TestingHTTPRequestHandler.do_GET): s/file/f/ using python
  primitives as variable names is a receipe for disaster.
-------------- next part --------------
=== modified file 'bzrlib/tests/http_server.py'
--- a/bzrlib/tests/http_server.py	2010-06-04 16:31:07 +0000
+++ b/bzrlib/tests/http_server.py	2010-06-05 09:01:06 +0000
@@ -75,6 +75,14 @@
                 self.headers.get('referer', '-'),
                 self.headers.get('user-agent', '-'))
 
+    def handle(self):
+        SimpleHTTPServer.SimpleHTTPRequestHandler.handle(self)
+        # Some client (pycurl, I'm looking at you) are more picky than others
+        # and require that the socket itself is close
+        # (SocketServer.StreamRequestHandler only close the two associated
+        # 'makefile' objects)
+        self.connection.close()
+
     def handle_one_request(self):
         """Handle a single HTTP request.
 
@@ -220,12 +228,12 @@
             # mode may cause newline translations, making the
             # actual size of the content transmitted *less* than
             # the content-length!
-            file = open(path, 'rb')
+            f = open(path, 'rb')
         except IOError:
             self.send_error(404, "File not found")
             return
 
-        file_size = os.fstat(file.fileno())[6]
+        file_size = os.fstat(f.fileno())[6]
         tail, ranges = self.parse_ranges(ranges_header_value)
         # Normalize tail into ranges
         if tail != 0:
@@ -252,7 +260,7 @@
             # RFC2616 14.16 and 14.35 says that when a server
             # encounters unsatisfiable range specifiers, it
             # SHOULD return a 416.
-            file.close()
+            f.close()
             # FIXME: We SHOULD send a Content-Range header too,
             # but the implementation of send_error does not
             # allows that. So far.
@@ -261,10 +269,10 @@
 
         if len(ranges) == 1:
             (start, end) = ranges[0]
-            self.get_single_range(file, file_size, start, end)
+            self.get_single_range(f, file_size, start, end)
         else:
-            self.get_multiple_ranges(file, file_size, ranges)
-        file.close()
+            self.get_multiple_ranges(f, file_size, ranges)
+        f.close()
 
     def translate_path(self, path):
         """Translate a /-separated PATH to the local filename syntax.

=== modified file 'bzrlib/tests/per_transport.py'
--- a/bzrlib/tests/per_transport.py	2010-03-05 05:30:19 +0000
+++ b/bzrlib/tests/per_transport.py	2010-06-05 09:01:06 +0000
@@ -251,7 +251,6 @@
 
     def test_get_bytes_unknown_file(self):
         t = self.get_transport()
-
         self.assertRaises(NoSuchFile, t.get_bytes, 'c')
 
     def test_get_with_open_write_stream_sees_all_content(self):



More information about the bazaar-commits mailing list