comparison mercurial/wireproto.py @ 25660:328739ea70c3

global: mass rewrite to use modern exception syntax Python 2.6 introduced the "except type as instance" syntax, replacing the "except type, instance" syntax that came before. Python 3 dropped support for the latter syntax. Since we no longer support Python 2.4 or 2.5, we have no need to continue supporting the "except type, instance". This patch mass rewrites the exception syntax to be Python 2.6+ and Python 3 compatible. This patch was produced by running `2to3 -f except -w -n .`.
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 23 Jun 2015 22:20:08 -0700
parents d8e7b0781ad7
children 5cda0ce05c42
comparison
equal deleted inserted replaced
25659:d60678a567a9 25660:328739ea70c3
703 try: 703 try:
704 k = encoding.tolocal(key) 704 k = encoding.tolocal(key)
705 c = repo[k] 705 c = repo[k]
706 r = c.hex() 706 r = c.hex()
707 success = 1 707 success = 1
708 except Exception, inst: 708 except Exception as inst:
709 r = str(inst) 709 r = str(inst)
710 success = 0 710 success = 0
711 return "%s %s\n" % (success, r) 711 return "%s %s\n" % (success, r)
712 712
713 @wireprotocommand('known', 'nodes *') 713 @wireprotocommand('known', 'nodes *')
798 798
799 finally: 799 finally:
800 fp.close() 800 fp.close()
801 os.unlink(tempname) 801 os.unlink(tempname)
802 802
803 except (error.BundleValueError, util.Abort, error.PushRaced), exc: 803 except (error.BundleValueError, util.Abort, error.PushRaced) as exc:
804 # handle non-bundle2 case first 804 # handle non-bundle2 case first
805 if not getattr(exc, 'duringunbundle2', False): 805 if not getattr(exc, 'duringunbundle2', False):
806 try: 806 try:
807 raise 807 raise
808 except util.Abort: 808 except util.Abort:
819 for out in getattr(exc, '_bundle2salvagedoutput', ()): 819 for out in getattr(exc, '_bundle2salvagedoutput', ()):
820 bundler.addpart(out) 820 bundler.addpart(out)
821 try: 821 try:
822 try: 822 try:
823 raise 823 raise
824 except error.PushkeyFailed, exc: 824 except error.PushkeyFailed as exc:
825 # check client caps 825 # check client caps
826 remotecaps = getattr(exc, '_replycaps', None) 826 remotecaps = getattr(exc, '_replycaps', None)
827 if (remotecaps is not None 827 if (remotecaps is not None
828 and 'pushkey' not in remotecaps.get('error', ())): 828 and 'pushkey' not in remotecaps.get('error', ())):
829 # no support remote side, fallback to Abort handler. 829 # no support remote side, fallback to Abort handler.
838 part.addparam('new', exc.new, mandatory=False) 838 part.addparam('new', exc.new, mandatory=False)
839 if exc.old is not None: 839 if exc.old is not None:
840 part.addparam('old', exc.old, mandatory=False) 840 part.addparam('old', exc.old, mandatory=False)
841 if exc.ret is not None: 841 if exc.ret is not None:
842 part.addparam('ret', exc.ret, mandatory=False) 842 part.addparam('ret', exc.ret, mandatory=False)
843 except error.BundleValueError, exc: 843 except error.BundleValueError as exc:
844 errpart = bundler.newpart('error:unsupportedcontent') 844 errpart = bundler.newpart('error:unsupportedcontent')
845 if exc.parttype is not None: 845 if exc.parttype is not None:
846 errpart.addparam('parttype', exc.parttype) 846 errpart.addparam('parttype', exc.parttype)
847 if exc.params: 847 if exc.params:
848 errpart.addparam('params', '\0'.join(exc.params)) 848 errpart.addparam('params', '\0'.join(exc.params))
849 except util.Abort, exc: 849 except util.Abort as exc:
850 manargs = [('message', str(exc))] 850 manargs = [('message', str(exc))]
851 advargs = [] 851 advargs = []
852 if exc.hint is not None: 852 if exc.hint is not None:
853 advargs.append(('hint', exc.hint)) 853 advargs.append(('hint', exc.hint))
854 bundler.addpart(bundle2.bundlepart('error:abort', 854 bundler.addpart(bundle2.bundlepart('error:abort',
855 manargs, advargs)) 855 manargs, advargs))
856 except error.PushRaced, exc: 856 except error.PushRaced as exc:
857 bundler.newpart('error:pushraced', [('message', str(exc))]) 857 bundler.newpart('error:pushraced', [('message', str(exc))])
858 return streamres(bundler.getchunks()) 858 return streamres(bundler.getchunks())