Explorar el Código

Fix yield in try/finally for python2.4 compatibility.

A yield statement in a try block with a finally clause was not supported
prior to python2.5; the same effect can be achieved with either a bare
except clause or an additional level of nesting.

Change-Id: Ib13a9f492feb69184a48e1013b6461ea643f0ebd
Dave Borowitz hace 15 años
padre
commit
5ba3a7e2fa
Se han modificado 2 ficheros con 19 adiciones y 16 borrados
  1. 7 6
      dulwich/file.py
  2. 12 10
      dulwich/web.py

+ 7 - 6
dulwich/file.py

@@ -160,12 +160,13 @@ class _GitFile(object):
             return
         self._file.close()
         try:
-            os.rename(self._lockfilename, self._filename)
-        except OSError, e:
-            # Windows versions prior to Vista don't support atomic renames
-            if e.errno != errno.EEXIST:
-                raise
-            fancy_rename(self._lockfilename, self._filename)
+            try:
+                os.rename(self._lockfilename, self._filename)
+            except OSError, e:
+                # Windows versions prior to Vista don't support atomic renames
+                if e.errno != errno.EEXIST:
+                    raise
+                fancy_rename(self._lockfilename, self._filename)
         finally:
             self.abort()
 

+ 12 - 10
dulwich/web.py

@@ -80,17 +80,19 @@ def send_file(req, f, content_type):
         yield req.not_found('File not found')
         return
     try:
-        try:
-            req.respond(HTTP_OK, content_type)
-            while True:
-                data = f.read(10240)
-                if not data:
-                    break
-                yield data
-        except IOError:
-            yield req.not_found('Error reading file')
-    finally:
+        req.respond(HTTP_OK, content_type)
+        while True:
+            data = f.read(10240)
+            if not data:
+                break
+            yield data
+        f.close()
+    except IOError:
+        f.close()
+        yield req.not_found('Error reading file')
+    except:
         f.close()
+        raise
 
 
 def get_text_file(req, backend, mat):