[PATCH] wireproto: workaround for yield inside try/finally incompatible with python2.4 (was: Re: [PATCH 03 of 10] wireproto: don't audit local paths during) stream_out

Thomas Arendsen Hein thomas at intevation.de
Tue Sep 18 10:04:02 CDT 2012


* Thomas Arendsen Hein <thomas at intevation.de> [20120918 16:29]:
> * Bryan O'Sullivan <bos at serpentine.com> [20120913 21:02]:
> > # HG changeset patch
> > # User Bryan O'Sullivan <bryano at fb.com>
> > # Date 1347562629 25200
> > # Node ID f85d5c5b428594aeccc4ce0a81786f53eea9039c
> > # Parent  d89e56d72ecf0ef69b1650aac774667297969622
> > wireproto: don't audit local paths during stream_out

> > +        try:
> > +            oldaudit = sopener.mustaudit
> > +            sopener.mustaudit = False
> > +
> > +            for name, size in entries:
> > +                repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
> > +                # partially encode name over the wire for backwards compat
> > +                yield '%s\0%d\n' % (store.encodedir(name), size)
> > +                for chunk in util.filechunkiter(sopener(name), limit=size):
> > +                    yield chunk
> > +        finally:
> > +            sopener.mustaudit = oldaudit
> 
> This causes a traceback on Python 2.4:
> SyntaxError: 'yield' not allowed in a 'try' block with a 'finally' clause

Possible workaround:

# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Date 1347980458 -7200
# Node ID a7fa5bd1c914475593afd3e661520d51b0bd1ecc
# Parent  2eac9641496dde7525293edd6cb9123886c3a11b
wireproto: workaround for yield inside try/finally incompatible with python2.4

diff -r 2eac9641496d -r a7fa5bd1c914 mercurial/wireproto.py
--- a/mercurial/wireproto.py	Tue Sep 18 15:36:58 2012 +0200
+++ b/mercurial/wireproto.py	Tue Sep 18 17:00:58 2012 +0200
@@ -567,8 +567,11 @@
                 else:
                     for chunk in util.filechunkiter(sopener(name), limit=size):
                         yield chunk
-        finally:
+        # replace with "finally:" when support for python 2.4 has been dropped
+        except Exception:
             sopener.mustaudit = oldaudit
+            raise
+        sopener.mustaudit = oldaudit
 
     return streamres(streamer(repo, entries, total_bytes))
 

-- 
thomas at intevation.de - http://intevation.de/~thomas/ - OpenPGP key: 0x5816791A
Intevation GmbH, Neuer Graben 17, 49074 Osnabrueck - AG Osnabrueck, HR B 18998
Geschaeftsfuehrer: Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner


More information about the Mercurial-devel mailing list