Skip to content

Commit

Permalink
Fix yield in try/finally for python2.4 compatibility.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dborowitz committed Apr 30, 2010
1 parent b4b384f commit 5ba3a7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
13 changes: 7 additions & 6 deletions dulwich/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ def close(self):
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()

Expand Down
22 changes: 12 additions & 10 deletions dulwich/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 5ba3a7e

Please sign in to comment.