Show More
@@ -455,7 +455,7 b' def checkfile(f, logfunc=_defaultlogger.' | |||
|
455 | 455 | |
|
456 | 456 | try: |
|
457 | 457 | fp = open(f) |
|
458 |
except IOError |
|
|
458 | except IOError as e: | |
|
459 | 459 | print "Skipping %s, %s" % (f, str(e).split(':', 1)[0]) |
|
460 | 460 | return result |
|
461 | 461 | pre = post = fp.read() |
@@ -328,7 +328,7 b' def find_cycles(imports):' | |||
|
328 | 328 | for mod in sorted(imports.iterkeys()): |
|
329 | 329 | try: |
|
330 | 330 | checkmod(mod, imports) |
|
331 |
except CircularImport |
|
|
331 | except CircularImport as e: | |
|
332 | 332 | cycle = e.args[0] |
|
333 | 333 | cycles.add(" -> ".join(rotatecycle(cycle))) |
|
334 | 334 | return cycles |
@@ -33,7 +33,7 b' def update(rev):' | |||
|
33 | 33 | """update the repo to a revision""" |
|
34 | 34 | try: |
|
35 | 35 | check_call(['hg', 'update', '--quiet', '--check', str(rev)]) |
|
36 |
except CalledProcessError |
|
|
36 | except CalledProcessError as exc: | |
|
37 | 37 | print >> sys.stderr, 'update to revision %s failed, aborting' % rev |
|
38 | 38 | sys.exit(exc.returncode) |
|
39 | 39 | |
@@ -56,7 +56,7 b' def perf(revset, target=None):' | |||
|
56 | 56 | try: |
|
57 | 57 | output = hg(['perfrevset', revset], repo=target) |
|
58 | 58 | return parseoutput(output) |
|
59 |
except CalledProcessError |
|
|
59 | except CalledProcessError as exc: | |
|
60 | 60 | print >> sys.stderr, 'abort: cannot run revset benchmark: %s' % exc.cmd |
|
61 | 61 | if exc.output is None: |
|
62 | 62 | print >> sys.stderr, '(no ouput)' |
@@ -201,7 +201,7 b' def getrevs(spec):' | |||
|
201 | 201 | """get the list of rev matched by a revset""" |
|
202 | 202 | try: |
|
203 | 203 | out = check_output(['hg', 'log', '--template={rev}\n', '--rev', spec]) |
|
204 |
except CalledProcessError |
|
|
204 | except CalledProcessError as exc: | |
|
205 | 205 | print >> sys.stderr, "abort, can't get revision from %s" % spec |
|
206 | 206 | sys.exit(exc.returncode) |
|
207 | 207 | return [r for r in out.split() if r] |
@@ -253,7 +253,7 b' def synthesize(ui, repo, descpath, **opt' | |||
|
253 | 253 | ''' |
|
254 | 254 | try: |
|
255 | 255 | fp = hg.openpath(ui, descpath) |
|
256 |
except Exception |
|
|
256 | except Exception as err: | |
|
257 | 257 | raise util.Abort('%s: %s' % (descpath, err[0].strerror)) |
|
258 | 258 | desc = json.load(fp) |
|
259 | 259 | fp.close() |
@@ -285,7 +285,7 b' def synthesize(ui, repo, descpath, **opt' | |||
|
285 | 285 | dictfile = opts.get('dict') or '/usr/share/dict/words' |
|
286 | 286 | try: |
|
287 | 287 | fp = open(dictfile, 'rU') |
|
288 |
except IOError |
|
|
288 | except IOError as err: | |
|
289 | 289 | raise util.Abort('%s: %s' % (dictfile, err.strerror)) |
|
290 | 290 | words = fp.read().splitlines() |
|
291 | 291 | fp.close() |
@@ -52,14 +52,14 b' def wrapui(ui):' | |||
|
52 | 52 | def rotate(oldpath, newpath): |
|
53 | 53 | try: |
|
54 | 54 | os.unlink(newpath) |
|
55 |
except OSError |
|
|
55 | except OSError as err: | |
|
56 | 56 | if err.errno != errno.ENOENT: |
|
57 | 57 | self.debug("warning: cannot remove '%s': %s\n" % |
|
58 | 58 | (newpath, err.strerror)) |
|
59 | 59 | try: |
|
60 | 60 | if newpath: |
|
61 | 61 | os.rename(oldpath, newpath) |
|
62 |
except OSError |
|
|
62 | except OSError as err: | |
|
63 | 63 | if err.errno != errno.ENOENT: |
|
64 | 64 | self.debug("warning: cannot rename '%s' to '%s': %s\n" % |
|
65 | 65 | (newpath, oldpath, err.strerror)) |
@@ -92,7 +92,7 b' def wrapui(ui):' | |||
|
92 | 92 | elif util.safehasattr(self, '_bbopener'): |
|
93 | 93 | try: |
|
94 | 94 | self._blackbox = self._openlogfile() |
|
95 |
except (IOError, OSError) |
|
|
95 | except (IOError, OSError) as err: | |
|
96 | 96 | self.debug('warning: cannot write to blackbox.log: %s\n' % |
|
97 | 97 | err.strerror) |
|
98 | 98 | del self._bbopener |
@@ -110,7 +110,7 b' def wrapui(ui):' | |||
|
110 | 110 | formattedmsg = msg[0] % msg[1:] |
|
111 | 111 | try: |
|
112 | 112 | blackbox.write('%s %s> %s' % (date, user, formattedmsg)) |
|
113 |
except IOError |
|
|
113 | except IOError as err: | |
|
114 | 114 | self.debug('warning: cannot write to blackbox.log: %s\n' % |
|
115 | 115 | err.strerror) |
|
116 | 116 | lastblackbox = blackbox |
@@ -357,7 +357,7 b' class bzmysql(bzaccess):' | |||
|
357 | 357 | try: |
|
358 | 358 | import MySQLdb as mysql |
|
359 | 359 | bzmysql._MySQLdb = mysql |
|
360 |
except ImportError |
|
|
360 | except ImportError as err: | |
|
361 | 361 | raise util.Abort(_('python mysql support not available: %s') % err) |
|
362 | 362 | |
|
363 | 363 | bzaccess.__init__(self, ui) |
@@ -910,5 +910,5 b' def hook(ui, repo, hooktype, node=None, ' | |||
|
910 | 910 | for bug in bugs: |
|
911 | 911 | bz.update(bug, bugs[bug], ctx) |
|
912 | 912 | bz.notify(bugs, util.email(ctx.user())) |
|
913 |
except Exception |
|
|
913 | except Exception as e: | |
|
914 | 914 | raise util.Abort(_('Bugzilla error: %s') % e) |
@@ -147,7 +147,7 b" def censor(ui, repo, path, rev='', tombs" | |||
|
147 | 147 | # Immediate children of censored node must be re-added as fulltext. |
|
148 | 148 | try: |
|
149 | 149 | revdata = flog.revision(srev) |
|
150 |
except error.CensoredNodeError |
|
|
150 | except error.CensoredNodeError as e: | |
|
151 | 151 | revdata = e.tombstone |
|
152 | 152 | dlen = rewrite(srev, offset, revdata) |
|
153 | 153 | else: |
@@ -26,7 +26,7 b' def maketemplater(ui, repo, tmpl):' | |||
|
26 | 26 | try: |
|
27 | 27 | t = cmdutil.changeset_templater(ui, repo, False, None, tmpl, |
|
28 | 28 | None, False) |
|
29 |
except SyntaxError |
|
|
29 | except SyntaxError as inst: | |
|
30 | 30 | raise util.Abort(inst.args[0]) |
|
31 | 31 | return t |
|
32 | 32 |
@@ -194,7 +194,7 b' def _terminfosetup(ui, mode):' | |||
|
194 | 194 | |
|
195 | 195 | try: |
|
196 | 196 | curses.setupterm() |
|
197 |
except curses.error |
|
|
197 | except curses.error as e: | |
|
198 | 198 | _terminfo_params = {} |
|
199 | 199 | return |
|
200 | 200 |
@@ -427,7 +427,7 b' class mapfile(dict):' | |||
|
427 | 427 | return |
|
428 | 428 | try: |
|
429 | 429 | fp = open(self.path, 'r') |
|
430 |
except IOError |
|
|
430 | except IOError as err: | |
|
431 | 431 | if err.errno != errno.ENOENT: |
|
432 | 432 | raise |
|
433 | 433 | return |
@@ -451,7 +451,7 b' class mapfile(dict):' | |||
|
451 | 451 | if self.fp is None: |
|
452 | 452 | try: |
|
453 | 453 | self.fp = open(self.path, 'a') |
|
454 |
except IOError |
|
|
454 | except IOError as err: | |
|
455 | 455 | raise util.Abort(_('could not open map file %r: %s') % |
|
456 | 456 | (self.path, err.strerror)) |
|
457 | 457 | self.fp.write('%s %s\n' % (key, value)) |
@@ -54,7 +54,7 b' def convertsource(ui, path, type, rev):' | |||
|
54 | 54 | try: |
|
55 | 55 | if not type or name == type: |
|
56 | 56 | return source(ui, path, rev), sortmode |
|
57 |
except (NoRepo, MissingTool) |
|
|
57 | except (NoRepo, MissingTool) as inst: | |
|
58 | 58 | exceptions.append(inst) |
|
59 | 59 | if not ui.quiet: |
|
60 | 60 | for inst in exceptions: |
@@ -68,9 +68,9 b' def convertsink(ui, path, type):' | |||
|
68 | 68 | try: |
|
69 | 69 | if not type or name == type: |
|
70 | 70 | return sink(ui, path) |
|
71 |
except NoRepo |
|
|
71 | except NoRepo as inst: | |
|
72 | 72 | ui.note(_("convert: %s\n") % inst) |
|
73 |
except MissingTool |
|
|
73 | except MissingTool as inst: | |
|
74 | 74 | raise util.Abort('%s\n' % inst) |
|
75 | 75 | raise util.Abort(_('%s: unknown repository type') % path) |
|
76 | 76 |
@@ -136,7 +136,7 b' class convert_cvs(converter_source):' | |||
|
136 | 136 | passw = part2 |
|
137 | 137 | break |
|
138 | 138 | pf.close() |
|
139 |
except IOError |
|
|
139 | except IOError as inst: | |
|
140 | 140 | if inst.errno != errno.ENOENT: |
|
141 | 141 | if not getattr(inst, 'filename', None): |
|
142 | 142 | inst.filename = cvspass |
@@ -179,7 +179,7 b' def createlog(ui, directory=None, root="' | |||
|
179 | 179 | break |
|
180 | 180 | |
|
181 | 181 | ui.note(_('cache has %d log entries\n') % len(oldlog)) |
|
182 |
except Exception |
|
|
182 | except Exception as e: | |
|
183 | 183 | ui.note(_('error reading cache: %r\n') % e) |
|
184 | 184 | |
|
185 | 185 | if oldlog: |
@@ -824,7 +824,7 b' def debugcvsps(ui, *args, **opts):' | |||
|
824 | 824 | log += createlog(ui, d, root=opts["root"], cache=cache) |
|
825 | 825 | else: |
|
826 | 826 | log = createlog(ui, root=opts["root"], cache=cache) |
|
827 |
except logerror |
|
|
827 | except logerror as e: | |
|
828 | 828 | ui.write("%r\n"%e) |
|
829 | 829 | return |
|
830 | 830 |
@@ -197,7 +197,7 b' class darcs_source(converter_source, com' | |||
|
197 | 197 | try: |
|
198 | 198 | data = util.readfile(path) |
|
199 | 199 | mode = os.lstat(path).st_mode |
|
200 |
except IOError |
|
|
200 | except IOError as inst: | |
|
201 | 201 | if inst.errno == errno.ENOENT: |
|
202 | 202 | return None, None |
|
203 | 203 | raise |
@@ -42,7 +42,7 b' class mercurial_sink(converter_sink):' | |||
|
42 | 42 | if not self.repo.local(): |
|
43 | 43 | raise NoRepo(_('%s is not a local Mercurial repository') |
|
44 | 44 | % path) |
|
45 |
except error.RepoError |
|
|
45 | except error.RepoError as err: | |
|
46 | 46 | ui.traceback() |
|
47 | 47 | raise NoRepo(err.args[0]) |
|
48 | 48 | else: |
@@ -487,7 +487,7 b' class mercurial_source(converter_source)' | |||
|
487 | 487 | copies[name] = copysource |
|
488 | 488 | except TypeError: |
|
489 | 489 | pass |
|
490 |
except error.LookupError |
|
|
490 | except error.LookupError as e: | |
|
491 | 491 | if not self.ignoreerrors: |
|
492 | 492 | raise |
|
493 | 493 | self.ignored.add(name) |
@@ -126,7 +126,7 b' def get_log_child(fp, url, paths, start,' | |||
|
126 | 126 | except IOError: |
|
127 | 127 | # Caller may interrupt the iteration |
|
128 | 128 | pickle.dump(None, fp, protocol) |
|
129 |
except Exception |
|
|
129 | except Exception as inst: | |
|
130 | 130 | pickle.dump(str(inst), fp, protocol) |
|
131 | 131 | else: |
|
132 | 132 | pickle.dump(None, fp, protocol) |
@@ -216,7 +216,7 b' def httpcheck(ui, path, proto):' | |||
|
216 | 216 | opener = urllib2.build_opener() |
|
217 | 217 | rsp = opener.open('%s://%s/!svn/ver/0/.svn' % (proto, path)) |
|
218 | 218 | data = rsp.read() |
|
219 |
except urllib2.HTTPError |
|
|
219 | except urllib2.HTTPError as inst: | |
|
220 | 220 | if inst.code != 404: |
|
221 | 221 | # Except for 404 we cannot know for sure this is not an svn repo |
|
222 | 222 | ui.warn(_('svn: cannot probe remote repository, assume it could ' |
@@ -944,7 +944,8 b' class svn_source(converter_source):' | |||
|
944 | 944 | firstcset.parents.append(latest) |
|
945 | 945 | except SvnPathNotFound: |
|
946 | 946 | pass |
|
947 |
except SubversionException |
|
|
947 | except SubversionException as xxx_todo_changeme: | |
|
948 | (inst, num) = xxx_todo_changeme.args | |
|
948 | 949 | if num == svn.core.SVN_ERR_FS_NO_SUCH_REVISION: |
|
949 | 950 | raise util.Abort(_('svn: branch has no revision %s') |
|
950 | 951 | % to_revnum) |
@@ -970,7 +971,7 b' class svn_source(converter_source):' | |||
|
970 | 971 | info = info[-1] |
|
971 | 972 | mode = ("svn:executable" in info) and 'x' or '' |
|
972 | 973 | mode = ("svn:special" in info) and 'l' or mode |
|
973 |
except SubversionException |
|
|
974 | except SubversionException as e: | |
|
974 | 975 | notfound = (svn.core.SVN_ERR_FS_NOT_FOUND, |
|
975 | 976 | svn.core.SVN_ERR_RA_DAV_PATH_NOT_FOUND) |
|
976 | 977 | if e.apr_err in notfound: # File not found |
@@ -87,7 +87,8 b' class SvnRaTransport(object):' | |||
|
87 | 87 | self.ra = svn.client.open_ra_session( |
|
88 | 88 | self.svn_url, |
|
89 | 89 | self.client, self.pool) |
|
90 |
except SubversionException |
|
|
90 | except SubversionException as xxx_todo_changeme: | |
|
91 | (inst, num) = xxx_todo_changeme.args | |
|
91 | 92 | if num in (svn.core.SVN_ERR_RA_ILLEGAL_URL, |
|
92 | 93 | svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, |
|
93 | 94 | svn.core.SVN_ERR_BAD_URL): |
@@ -218,7 +218,7 b' def parseeol(ui, repo, nodes):' | |||
|
218 | 218 | return eolfile(ui, repo.root, data) |
|
219 | 219 | except (IOError, LookupError): |
|
220 | 220 | pass |
|
221 |
except error.ParseError |
|
|
221 | except error.ParseError as inst: | |
|
222 | 222 | ui.warn(_("warning: ignoring .hgeol file due to parse error " |
|
223 | 223 | "at %s: %s\n") % (inst.args[1], inst.args[0])) |
|
224 | 224 | return None |
@@ -283,7 +283,7 b' def sign(ui, repo, *revs, **opts):' | |||
|
283 | 283 | editor = cmdutil.getcommiteditor(editform='gpg.sign', **opts) |
|
284 | 284 | repo.commit(message, opts['user'], opts['date'], match=msigs, |
|
285 | 285 | editor=editor) |
|
286 |
except ValueError |
|
|
286 | except ValueError as inst: | |
|
287 | 287 | raise util.Abort(str(inst)) |
|
288 | 288 | |
|
289 | 289 | def shortkey(ui, key): |
@@ -222,7 +222,7 b' class histeditstate(object):' | |||
|
222 | 222 | """Load histedit state from disk and set fields appropriately.""" |
|
223 | 223 | try: |
|
224 | 224 | fp = self.repo.vfs('histedit-state', 'r') |
|
225 |
except IOError |
|
|
225 | except IOError as err: | |
|
226 | 226 | if err.errno != errno.ENOENT: |
|
227 | 227 | raise |
|
228 | 228 | raise util.Abort(_('no histedit in progress')) |
@@ -96,7 +96,7 b' class basestore(object):' | |||
|
96 | 96 | |
|
97 | 97 | try: |
|
98 | 98 | gothash = self._getfile(tmpfile, filename, hash) |
|
99 |
except StoreError |
|
|
99 | except StoreError as err: | |
|
100 | 100 | self.ui.warn(err.longmessage()) |
|
101 | 101 | gothash = "" |
|
102 | 102 | tmpfile.close() |
@@ -391,7 +391,7 b' def cachelfiles(ui, repo, node, filelist' | |||
|
391 | 391 | for lfile in lfiles: |
|
392 | 392 | try: |
|
393 | 393 | expectedhash = repo[node][lfutil.standin(lfile)].data().strip() |
|
394 |
except IOError |
|
|
394 | except IOError as err: | |
|
395 | 395 | if err.errno == errno.ENOENT: |
|
396 | 396 | continue # node must be None and standin wasn't found in wctx |
|
397 | 397 | raise |
@@ -580,7 +580,7 b' def overridecopy(orig, ui, repo, pats, o' | |||
|
580 | 580 | installnormalfilesmatchfn(repo[None].manifest()) |
|
581 | 581 | try: |
|
582 | 582 | result = orig(ui, repo, pats, opts, rename) |
|
583 |
except util.Abort |
|
|
583 | except util.Abort as e: | |
|
584 | 584 | if str(e) != _('no files to copy'): |
|
585 | 585 | raise e |
|
586 | 586 | else: |
@@ -682,7 +682,7 b' def overridecopy(orig, ui, repo, pats, o' | |||
|
682 | 682 | |
|
683 | 683 | lfdirstate.add(destlfile) |
|
684 | 684 | lfdirstate.write() |
|
685 |
except util.Abort |
|
|
685 | except util.Abort as e: | |
|
686 | 686 | if str(e) != _('no files to copy'): |
|
687 | 687 | raise e |
|
688 | 688 | else: |
@@ -37,7 +37,7 b' def putlfile(repo, proto, sha):' | |||
|
37 | 37 | raise IOError(0, _('largefile contents do not match hash')) |
|
38 | 38 | tmpfp.close() |
|
39 | 39 | lfutil.linktousercache(repo, sha) |
|
40 |
except IOError |
|
|
40 | except IOError as e: | |
|
41 | 41 | repo.ui.warn(_('largefiles: failed to put %s into store: %s\n') % |
|
42 | 42 | (sha, e.strerror)) |
|
43 | 43 | return wireproto.pushres(1) |
@@ -38,7 +38,7 b' class remotestore(basestore.basestore):' | |||
|
38 | 38 | try: |
|
39 | 39 | fd = lfutil.httpsendfile(self.ui, filename) |
|
40 | 40 | return self._put(hash, fd) |
|
41 |
except IOError |
|
|
41 | except IOError as e: | |
|
42 | 42 | raise util.Abort( |
|
43 | 43 | _('remotestore: could not open file %s: %s') |
|
44 | 44 | % (filename, str(e))) |
@@ -49,17 +49,17 b' class remotestore(basestore.basestore):' | |||
|
49 | 49 | def _getfile(self, tmpfile, filename, hash): |
|
50 | 50 | try: |
|
51 | 51 | chunks = self._get(hash) |
|
52 |
except urllib2.HTTPError |
|
|
52 | except urllib2.HTTPError as e: | |
|
53 | 53 | # 401s get converted to util.Aborts; everything else is fine being |
|
54 | 54 | # turned into a StoreError |
|
55 | 55 | raise basestore.StoreError(filename, hash, self.url, str(e)) |
|
56 |
except urllib2.URLError |
|
|
56 | except urllib2.URLError as e: | |
|
57 | 57 | # This usually indicates a connection problem, so don't |
|
58 | 58 | # keep trying with the other files... they will probably |
|
59 | 59 | # all fail too. |
|
60 | 60 | raise util.Abort('%s: %s' % |
|
61 | 61 | (util.hidepassword(self.url), e.reason)) |
|
62 |
except IOError |
|
|
62 | except IOError as e: | |
|
63 | 63 | raise basestore.StoreError(filename, hash, self.url, str(e)) |
|
64 | 64 | |
|
65 | 65 | return lfutil.copyandhash(chunks, tmpfile) |
@@ -448,7 +448,7 b' class queue(object):' | |||
|
448 | 448 | try: |
|
449 | 449 | lines = self.opener.read(self.statuspath).splitlines() |
|
450 | 450 | return list(parselines(lines)) |
|
451 |
except IOError |
|
|
451 | except IOError as e: | |
|
452 | 452 | if e.errno == errno.ENOENT: |
|
453 | 453 | return [] |
|
454 | 454 | raise |
@@ -457,7 +457,7 b' class queue(object):' | |||
|
457 | 457 | def fullseries(self): |
|
458 | 458 | try: |
|
459 | 459 | return self.opener.read(self.seriespath).splitlines() |
|
460 |
except IOError |
|
|
460 | except IOError as e: | |
|
461 | 461 | if e.errno == errno.ENOENT: |
|
462 | 462 | return [] |
|
463 | 463 | raise |
@@ -574,7 +574,7 b' class queue(object):' | |||
|
574 | 574 | self.activeguards = [] |
|
575 | 575 | try: |
|
576 | 576 | guards = self.opener.read(self.guardspath).split() |
|
577 |
except IOError |
|
|
577 | except IOError as err: | |
|
578 | 578 | if err.errno != errno.ENOENT: |
|
579 | 579 | raise |
|
580 | 580 | guards = [] |
@@ -675,7 +675,7 b' class queue(object):' | |||
|
675 | 675 | return |
|
676 | 676 | try: |
|
677 | 677 | os.unlink(undo) |
|
678 |
except OSError |
|
|
678 | except OSError as inst: | |
|
679 | 679 | self.ui.warn(_('error removing undo: %s\n') % str(inst)) |
|
680 | 680 | |
|
681 | 681 | def backup(self, repo, files, copy=False): |
@@ -804,7 +804,7 b' class queue(object):' | |||
|
804 | 804 | fuzz = patchmod.patch(self.ui, repo, patchfile, strip=1, |
|
805 | 805 | files=files, eolmode=None) |
|
806 | 806 | return (True, list(files), fuzz) |
|
807 |
except Exception |
|
|
807 | except Exception as inst: | |
|
808 | 808 | self.ui.note(str(inst) + '\n') |
|
809 | 809 | if not self.ui.verbose: |
|
810 | 810 | self.ui.warn(_("patch failed, unable to continue (try -v)\n")) |
@@ -959,7 +959,7 b' class queue(object):' | |||
|
959 | 959 | for p in patches: |
|
960 | 960 | try: |
|
961 | 961 | os.unlink(self.join(p)) |
|
962 |
except OSError |
|
|
962 | except OSError as inst: | |
|
963 | 963 | if inst.errno != errno.ENOENT: |
|
964 | 964 | raise |
|
965 | 965 | |
@@ -1159,7 +1159,7 b' class queue(object):' | |||
|
1159 | 1159 | try: |
|
1160 | 1160 | # if patch file write fails, abort early |
|
1161 | 1161 | p = self.opener(patchfn, "w") |
|
1162 |
except IOError |
|
|
1162 | except IOError as e: | |
|
1163 | 1163 | raise util.Abort(_('cannot write patch "%s": %s') |
|
1164 | 1164 | % (patchfn, e.strerror)) |
|
1165 | 1165 | try: |
@@ -1816,7 +1816,7 b' class queue(object):' | |||
|
1816 | 1816 | raise util.Abort(_("patch queue directory already exists")) |
|
1817 | 1817 | try: |
|
1818 | 1818 | os.mkdir(self.path) |
|
1819 |
except OSError |
|
|
1819 | except OSError as inst: | |
|
1820 | 1820 | if inst.errno != errno.EEXIST or not create: |
|
1821 | 1821 | raise |
|
1822 | 1822 | if create: |
@@ -276,7 +276,7 b' class notifier(object):' | |||
|
276 | 276 | p = email.Parser.Parser() |
|
277 | 277 | try: |
|
278 | 278 | msg = p.parsestr(data) |
|
279 |
except email.Errors.MessageParseError |
|
|
279 | except email.Errors.MessageParseError as inst: | |
|
280 | 280 | raise util.Abort(inst) |
|
281 | 281 | |
|
282 | 282 | # store sender and subject |
@@ -628,7 +628,7 b' def patchbomb(ui, repo, *revs, **opts):' | |||
|
628 | 628 | try: |
|
629 | 629 | generator.flatten(m, 0) |
|
630 | 630 | fp.write('\n') |
|
631 |
except IOError |
|
|
631 | except IOError as inst: | |
|
632 | 632 | if inst.errno != errno.EPIPE: |
|
633 | 633 | raise |
|
634 | 634 | if fp is not ui: |
@@ -838,7 +838,7 b' def restorestatus(repo):' | |||
|
838 | 838 | _setrebasesetvisibility(repo, state.keys()) |
|
839 | 839 | return (originalwd, target, state, skipped, |
|
840 | 840 | collapse, keep, keepbranches, external, activebookmark) |
|
841 |
except IOError |
|
|
841 | except IOError as err: | |
|
842 | 842 | if err.errno != errno.ENOENT: |
|
843 | 843 | raise |
|
844 | 844 | raise util.Abort(_('no rebase in progress')) |
@@ -178,7 +178,7 b' def do_relink(src, dst, files, ui):' | |||
|
178 | 178 | ui.progress(_('relinking'), pos, f, _('files'), total) |
|
179 | 179 | relinked += 1 |
|
180 | 180 | savedbytes += sz |
|
181 |
except OSError |
|
|
181 | except OSError as inst: | |
|
182 | 182 | ui.warn('%s: %s\n' % (tgt, str(inst))) |
|
183 | 183 | |
|
184 | 184 | ui.progress(_('relinking'), None) |
@@ -84,7 +84,7 b' def _hassharedbookmarks(repo):' | |||
|
84 | 84 | """Returns whether this repo has shared bookmarks""" |
|
85 | 85 | try: |
|
86 | 86 | shared = repo.vfs.read('shared').splitlines() |
|
87 |
except IOError |
|
|
87 | except IOError as inst: | |
|
88 | 88 | if inst.errno != errno.ENOENT: |
|
89 | 89 | raise |
|
90 | 90 | return False |
@@ -69,7 +69,7 b' class shelvedfile(object):' | |||
|
69 | 69 | def opener(self, mode='rb'): |
|
70 | 70 | try: |
|
71 | 71 | return self.vfs(self.fname, mode) |
|
72 |
except IOError |
|
|
72 | except IOError as err: | |
|
73 | 73 | if err.errno != errno.ENOENT: |
|
74 | 74 | raise |
|
75 | 75 | raise util.Abort(_("shelved change '%s' not found") % self.name) |
@@ -294,7 +294,7 b' def deletecmd(ui, repo, pats):' | |||
|
294 | 294 | for name in pats: |
|
295 | 295 | for suffix in 'hg patch'.split(): |
|
296 | 296 | shelvedfile(repo, name, suffix).unlink() |
|
297 |
except OSError |
|
|
297 | except OSError as err: | |
|
298 | 298 | if err.errno != errno.ENOENT: |
|
299 | 299 | raise |
|
300 | 300 | raise util.Abort(_("shelved change '%s' not found") % name) |
@@ -305,7 +305,7 b' def listshelves(repo):' | |||
|
305 | 305 | """return all shelves in repo as list of (time, filename)""" |
|
306 | 306 | try: |
|
307 | 307 | names = repo.vfs.readdir('shelved') |
|
308 |
except OSError |
|
|
308 | except OSError as err: | |
|
309 | 309 | if err.errno != errno.ENOENT: |
|
310 | 310 | raise |
|
311 | 311 | return [] |
@@ -532,7 +532,7 b' def unshelve(ui, repo, *shelved, **opts)' | |||
|
532 | 532 | |
|
533 | 533 | try: |
|
534 | 534 | state = shelvedstate.load(repo) |
|
535 |
except IOError |
|
|
535 | except IOError as err: | |
|
536 | 536 | if err.errno != errno.ENOENT: |
|
537 | 537 | raise |
|
538 | 538 | raise util.Abort(_('no unshelve operation underway')) |
@@ -272,7 +272,7 b' class transplanter(object):' | |||
|
272 | 272 | files = set() |
|
273 | 273 | patch.patch(self.ui, repo, patchfile, files=files, eolmode=None) |
|
274 | 274 | files = list(files) |
|
275 |
except Exception |
|
|
275 | except Exception as inst: | |
|
276 | 276 | seriespath = os.path.join(self.path, 'series') |
|
277 | 277 | if os.path.exists(seriespath): |
|
278 | 278 | os.unlink(seriespath) |
@@ -1276,7 +1276,7 b' class _POFileParser(object):' | |||
|
1276 | 1276 | (action, state) = self.transitions[(symbol, self.current_state)] |
|
1277 | 1277 | if action(): |
|
1278 | 1278 | self.current_state = state |
|
1279 |
except Exception |
|
|
1279 | except Exception as exc: | |
|
1280 | 1280 | raise IOError('Syntax error in po file (line %s)' % linenum) |
|
1281 | 1281 | |
|
1282 | 1282 | # state handlers |
@@ -45,7 +45,7 b' class bmstore(dict):' | |||
|
45 | 45 | self[refspec] = repo.changelog.lookup(sha) |
|
46 | 46 | except LookupError: |
|
47 | 47 | pass |
|
48 |
except IOError |
|
|
48 | except IOError as inst: | |
|
49 | 49 | if inst.errno != errno.ENOENT: |
|
50 | 50 | raise |
|
51 | 51 | |
@@ -54,7 +54,7 b' class bmstore(dict):' | |||
|
54 | 54 | if 'HG_PENDING' in os.environ: |
|
55 | 55 | try: |
|
56 | 56 | bkfile = repo.vfs('bookmarks.pending') |
|
57 |
except IOError |
|
|
57 | except IOError as inst: | |
|
58 | 58 | if inst.errno != errno.ENOENT: |
|
59 | 59 | raise |
|
60 | 60 | if bkfile is None: |
@@ -116,7 +116,7 b' def readactive(repo):' | |||
|
116 | 116 | mark = None |
|
117 | 117 | try: |
|
118 | 118 | file = repo.vfs('bookmarks.current') |
|
119 |
except IOError |
|
|
119 | except IOError as inst: | |
|
120 | 120 | if inst.errno != errno.ENOENT: |
|
121 | 121 | raise |
|
122 | 122 | return None |
@@ -159,7 +159,7 b' def deactivate(repo):' | |||
|
159 | 159 | try: |
|
160 | 160 | repo.vfs.unlink('bookmarks.current') |
|
161 | 161 | repo._activebookmark = None |
|
162 |
except OSError |
|
|
162 | except OSError as inst: | |
|
163 | 163 | if inst.errno != errno.ENOENT: |
|
164 | 164 | raise |
|
165 | 165 | finally: |
@@ -55,7 +55,7 b' def read(repo):' | |||
|
55 | 55 | partial._closednodes.add(node) |
|
56 | 56 | except KeyboardInterrupt: |
|
57 | 57 | raise |
|
58 |
except Exception |
|
|
58 | except Exception as inst: | |
|
59 | 59 | if repo.ui.debugflag: |
|
60 | 60 | msg = 'invalid branchheads cache' |
|
61 | 61 | if repo.filtername is not None: |
@@ -203,7 +203,7 b' class branchcache(dict):' | |||
|
203 | 203 | repo.ui.log('branchcache', |
|
204 | 204 | 'wrote %s branch cache with %d labels and %d nodes\n', |
|
205 | 205 | repo.filtername, len(self), nodecount) |
|
206 |
except (IOError, OSError, util.Abort) |
|
|
206 | except (IOError, OSError, util.Abort) as inst: | |
|
207 | 207 | repo.ui.debug("couldn't write branch cache: %s\n" % inst) |
|
208 | 208 | # Abort may be raise by read only opener |
|
209 | 209 | pass |
@@ -315,7 +315,7 b' class revbranchcache(object):' | |||
|
315 | 315 | bndata = repo.vfs.read(_rbcnames) |
|
316 | 316 | self._rbcsnameslen = len(bndata) # for verification before writing |
|
317 | 317 | self._names = [encoding.tolocal(bn) for bn in bndata.split('\0')] |
|
318 |
except (IOError, OSError) |
|
|
318 | except (IOError, OSError) as inst: | |
|
319 | 319 | if readonly: |
|
320 | 320 | # don't try to use cache - fall back to the slow path |
|
321 | 321 | self.branchinfo = self._branchinfo |
@@ -324,7 +324,7 b' class revbranchcache(object):' | |||
|
324 | 324 | try: |
|
325 | 325 | data = repo.vfs.read(_rbcrevs) |
|
326 | 326 | self._rbcrevs.fromstring(data) |
|
327 |
except (IOError, OSError) |
|
|
327 | except (IOError, OSError) as inst: | |
|
328 | 328 | repo.ui.debug("couldn't read revision branch cache: %s\n" % |
|
329 | 329 | inst) |
|
330 | 330 | # remember number of good records on disk |
@@ -418,7 +418,7 b' class revbranchcache(object):' | |||
|
418 | 418 | for b in self._names[self._rbcnamescount:])) |
|
419 | 419 | self._rbcsnameslen = f.tell() |
|
420 | 420 | f.close() |
|
421 |
except (IOError, OSError, util.Abort) |
|
|
421 | except (IOError, OSError, util.Abort) as inst: | |
|
422 | 422 | repo.ui.debug("couldn't write revision branch cache names: " |
|
423 | 423 | "%s\n" % inst) |
|
424 | 424 | return |
@@ -436,7 +436,7 b' class revbranchcache(object):' | |||
|
436 | 436 | end = revs * _rbcrecsize |
|
437 | 437 | f.write(self._rbcrevs[start:end]) |
|
438 | 438 | f.close() |
|
439 |
except (IOError, OSError, util.Abort) |
|
|
439 | except (IOError, OSError, util.Abort) as inst: | |
|
440 | 440 | repo.ui.debug("couldn't write revision branch cache: %s\n" % |
|
441 | 441 | inst) |
|
442 | 442 | return |
@@ -336,7 +336,7 b' def processbundle(repo, unbundler, trans' | |||
|
336 | 336 | try: |
|
337 | 337 | for nbpart, part in iterparts: |
|
338 | 338 | _processpart(op, part) |
|
339 |
except BaseException |
|
|
339 | except BaseException as exc: | |
|
340 | 340 | for nbpart, part in iterparts: |
|
341 | 341 | # consume the bundle content |
|
342 | 342 | part.seek(0, 2) |
@@ -380,7 +380,7 b' def _processpart(op, part):' | |||
|
380 | 380 | raise error.UnsupportedPartError(parttype=part.type, |
|
381 | 381 | params=unknownparams) |
|
382 | 382 | status = 'supported' |
|
383 |
except error.UnsupportedPartError |
|
|
383 | except error.UnsupportedPartError as exc: | |
|
384 | 384 | if part.mandatory: # mandatory parts |
|
385 | 385 | raise |
|
386 | 386 | indebug(op.ui, 'ignoring unsupported advisory part %s' % exc) |
@@ -585,7 +585,7 b' class unpackermixin(object):' | |||
|
585 | 585 | if self._seekable: |
|
586 | 586 | try: |
|
587 | 587 | return self._fp.tell() |
|
588 |
except IOError |
|
|
588 | except IOError as e: | |
|
589 | 589 | if e.errno == errno.ESPIPE: |
|
590 | 590 | self._seekable = False |
|
591 | 591 | else: |
@@ -841,7 +841,7 b' class bundlepart(object):' | |||
|
841 | 841 | outdebug(ui, 'payload chunk size: %i' % len(chunk)) |
|
842 | 842 | yield _pack(_fpayloadsize, len(chunk)) |
|
843 | 843 | yield chunk |
|
844 |
except BaseException |
|
|
844 | except BaseException as exc: | |
|
845 | 845 | # backup exception data for later |
|
846 | 846 | ui.debug('bundle2-input-stream-interrupt: encoding exception %s' |
|
847 | 847 | % exc) |
@@ -1248,7 +1248,7 b' def handleremotechangegroup(op, inpart):' | |||
|
1248 | 1248 | part.addparam('return', '%i' % ret, mandatory=False) |
|
1249 | 1249 | try: |
|
1250 | 1250 | real_part.validate() |
|
1251 |
except util.Abort |
|
|
1251 | except util.Abort as e: | |
|
1252 | 1252 | raise util.Abort(_('bundle at %s is corrupted:\n%s') % |
|
1253 | 1253 | (util.hidepassword(raw_url), str(e))) |
|
1254 | 1254 | assert not inpart.read() |
@@ -264,7 +264,7 b' class FTPRangeHandler(urllib2.FTPHandler' | |||
|
264 | 264 | |
|
265 | 265 | try: |
|
266 | 266 | host = socket.gethostbyname(host) |
|
267 |
except socket.error |
|
|
267 | except socket.error as msg: | |
|
268 | 268 | raise urllib2.URLError(msg) |
|
269 | 269 | path, attrs = splitattr(req.get_selector()) |
|
270 | 270 | dirs = path.split('/') |
@@ -322,7 +322,7 b' class FTPRangeHandler(urllib2.FTPHandler' | |||
|
322 | 322 | headers += "Content-Length: %d\n" % retrlen |
|
323 | 323 | headers = email.message_from_string(headers) |
|
324 | 324 | return addinfourl(fp, headers, req.get_full_url()) |
|
325 |
except ftplib.all_errors |
|
|
325 | except ftplib.all_errors as msg: | |
|
326 | 326 | raise IOError('ftp error', msg) |
|
327 | 327 | |
|
328 | 328 | def connect_ftp(self, user, passwd, host, port, dirs): |
@@ -352,7 +352,7 b' class ftpwrapper(urllib.ftpwrapper):' | |||
|
352 | 352 | # Use nlst to see if the file exists at all |
|
353 | 353 | try: |
|
354 | 354 | self.ftp.nlst(file) |
|
355 |
except ftplib.error_perm |
|
|
355 | except ftplib.error_perm as reason: | |
|
356 | 356 | raise IOError('ftp error', reason) |
|
357 | 357 | # Restore the transfer mode! |
|
358 | 358 | self.ftp.voidcmd(cmd) |
@@ -360,7 +360,7 b' class ftpwrapper(urllib.ftpwrapper):' | |||
|
360 | 360 | try: |
|
361 | 361 | cmd = 'RETR ' + file |
|
362 | 362 | conn = self.ftp.ntransfercmd(cmd, rest) |
|
363 |
except ftplib.error_perm |
|
|
363 | except ftplib.error_perm as reason: | |
|
364 | 364 | if str(reason).startswith('501'): |
|
365 | 365 | # workaround for REST not supported error |
|
366 | 366 | fp, retrlen = self.retrfile(file, type) |
@@ -491,7 +491,7 b' class cg1packer(object):' | |||
|
491 | 491 | if revlog.iscensored(base) or revlog.iscensored(rev): |
|
492 | 492 | try: |
|
493 | 493 | delta = revlog.revision(node) |
|
494 |
except error.CensoredNodeError |
|
|
494 | except error.CensoredNodeError as e: | |
|
495 | 495 | delta = e.tombstone |
|
496 | 496 | if base == nullrev: |
|
497 | 497 | prefix = mdiff.trivialdiffheader(len(delta)) |
@@ -665,7 +665,7 b' def addchangegroupfiles(repo, source, re' | |||
|
665 | 665 | try: |
|
666 | 666 | if not fl.addgroup(source, revmap, trp): |
|
667 | 667 | raise util.Abort(_("received file revlog group is empty")) |
|
668 |
except error.CensoredBaseError |
|
|
668 | except error.CensoredBaseError as e: | |
|
669 | 669 | raise util.Abort(_("received delta base is censored: %s") % e) |
|
670 | 670 | revisions += len(fl) - o |
|
671 | 671 | files += 1 |
@@ -119,7 +119,7 b' def dorecord(ui, repo, commitfunc, cmdsu' | |||
|
119 | 119 | # 1. filter patch, so we have intending-to apply subset of it |
|
120 | 120 | try: |
|
121 | 121 | chunks = filterfn(ui, originalchunks) |
|
122 |
except patch.PatchError |
|
|
122 | except patch.PatchError as err: | |
|
123 | 123 | raise util.Abort(_('error parsing patch: %s') % err) |
|
124 | 124 | |
|
125 | 125 | # We need to keep a backup of files that have been newly added and |
@@ -153,7 +153,7 b' def dorecord(ui, repo, commitfunc, cmdsu' | |||
|
153 | 153 | backupdir = repo.join('record-backups') |
|
154 | 154 | try: |
|
155 | 155 | os.mkdir(backupdir) |
|
156 |
except OSError |
|
|
156 | except OSError as err: | |
|
157 | 157 | if err.errno != errno.EEXIST: |
|
158 | 158 | raise |
|
159 | 159 | try: |
@@ -189,7 +189,7 b' def dorecord(ui, repo, commitfunc, cmdsu' | |||
|
189 | 189 | ui.debug('applying patch\n') |
|
190 | 190 | ui.debug(fp.getvalue()) |
|
191 | 191 | patch.internalpatch(ui, repo, fp, 1, eolmode=None) |
|
192 |
except patch.PatchError |
|
|
192 | except patch.PatchError as err: | |
|
193 | 193 | raise util.Abort(str(err)) |
|
194 | 194 | del fp |
|
195 | 195 | |
@@ -309,7 +309,7 b' def logmessage(ui, opts):' | |||
|
309 | 309 | message = ui.fin.read() |
|
310 | 310 | else: |
|
311 | 311 | message = '\n'.join(util.readfile(logfile).splitlines()) |
|
312 |
except IOError |
|
|
312 | except IOError as inst: | |
|
313 | 313 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
314 | 314 | (logfile, inst.strerror)) |
|
315 | 315 | return message |
@@ -418,7 +418,7 b' def makefilename(repo, pat, node, desc=N' | |||
|
418 | 418 | newname.append(c) |
|
419 | 419 | i += 1 |
|
420 | 420 | return ''.join(newname) |
|
421 |
except KeyError |
|
|
421 | except KeyError as inst: | |
|
422 | 422 | raise util.Abort(_("invalid format spec '%%%s' in output filename") % |
|
423 | 423 | inst.args[0]) |
|
424 | 424 | |
@@ -605,7 +605,7 b' def copy(ui, repo, pats, opts, rename=Fa' | |||
|
605 | 605 | else: |
|
606 | 606 | util.copyfile(src, target) |
|
607 | 607 | srcexists = True |
|
608 |
except IOError |
|
|
608 | except IOError as inst: | |
|
609 | 609 | if inst.errno == errno.ENOENT: |
|
610 | 610 | ui.warn(_('%s: deleted in working directory\n') % relsrc) |
|
611 | 611 | srcexists = False |
@@ -773,7 +773,7 b' def service(opts, parentfn=None, initfn=' | |||
|
773 | 773 | finally: |
|
774 | 774 | try: |
|
775 | 775 | os.unlink(lockpath) |
|
776 |
except OSError |
|
|
776 | except OSError as e: | |
|
777 | 777 | if e.errno != errno.ENOENT: |
|
778 | 778 | raise |
|
779 | 779 | if parentfn: |
@@ -898,7 +898,7 b' def tryimportone(ui, repo, hunk, parents' | |||
|
898 | 898 | try: |
|
899 | 899 | patch.patch(ui, repo, tmpname, strip=strip, prefix=prefix, |
|
900 | 900 | files=files, eolmode=None, similarity=sim / 100.0) |
|
901 |
except patch.PatchError |
|
|
901 | except patch.PatchError as e: | |
|
902 | 902 | if not partial: |
|
903 | 903 | raise util.Abort(str(e)) |
|
904 | 904 | if partial: |
@@ -942,7 +942,7 b' def tryimportone(ui, repo, hunk, parents' | |||
|
942 | 942 | try: |
|
943 | 943 | patch.patchrepo(ui, repo, p1, store, tmpname, strip, prefix, |
|
944 | 944 | files, eolmode=None) |
|
945 |
except patch.PatchError |
|
|
945 | except patch.PatchError as e: | |
|
946 | 946 | raise util.Abort(str(e)) |
|
947 | 947 | if opts.get('exact'): |
|
948 | 948 | editor = None |
@@ -1459,10 +1459,10 b' class changeset_templater(changeset_prin' | |||
|
1459 | 1459 | self.footer = templater.stringify(self.t(types['footer'], |
|
1460 | 1460 | **props)) |
|
1461 | 1461 | |
|
1462 |
except KeyError |
|
|
1462 | except KeyError as inst: | |
|
1463 | 1463 | msg = _("%s: no key named '%s'") |
|
1464 | 1464 | raise util.Abort(msg % (self.t.mapfile, inst.args[0])) |
|
1465 |
except SyntaxError |
|
|
1465 | except SyntaxError as inst: | |
|
1466 | 1466 | raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0])) |
|
1467 | 1467 | |
|
1468 | 1468 | def gettemplate(ui, tmpl, style): |
@@ -1523,7 +1523,7 b' def show_changeset(ui, repo, opts, buffe' | |||
|
1523 | 1523 | try: |
|
1524 | 1524 | t = changeset_templater(ui, repo, matchfn, opts, tmpl, mapfile, |
|
1525 | 1525 | buffered) |
|
1526 |
except SyntaxError |
|
|
1526 | except SyntaxError as inst: | |
|
1527 | 1527 | raise util.Abort(inst.args[0]) |
|
1528 | 1528 | return t |
|
1529 | 1529 | |
@@ -2682,7 +2682,7 b' def buildcommittemplate(repo, ctx, subs,' | |||
|
2682 | 2682 | |
|
2683 | 2683 | try: |
|
2684 | 2684 | t = changeset_templater(ui, repo, None, {}, tmpl, mapfile, False) |
|
2685 |
except SyntaxError |
|
|
2685 | except SyntaxError as inst: | |
|
2686 | 2686 | raise util.Abort(inst.args[0]) |
|
2687 | 2687 | |
|
2688 | 2688 | for k, v in repo.ui.configitems('committemplate'): |
@@ -3115,7 +3115,7 b' def _performrevert(repo, parents, ctx, a' | |||
|
3115 | 3115 | if reversehunks: |
|
3116 | 3116 | chunks = patch.reversehunks(chunks) |
|
3117 | 3117 | |
|
3118 |
except patch.PatchError |
|
|
3118 | except patch.PatchError as err: | |
|
3119 | 3119 | raise util.Abort(_('error parsing patch: %s') % err) |
|
3120 | 3120 | |
|
3121 | 3121 | newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks) |
@@ -3128,7 +3128,7 b' def _performrevert(repo, parents, ctx, a' | |||
|
3128 | 3128 | if dopatch: |
|
3129 | 3129 | try: |
|
3130 | 3130 | patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None) |
|
3131 |
except patch.PatchError |
|
|
3131 | except patch.PatchError as err: | |
|
3132 | 3132 | raise util.Abort(str(err)) |
|
3133 | 3133 | del fp |
|
3134 | 3134 | else: |
@@ -2340,7 +2340,7 b' def debuginstall(ui):' | |||
|
2340 | 2340 | ui.status(_("checking encoding (%s)...\n") % encoding.encoding) |
|
2341 | 2341 | try: |
|
2342 | 2342 | encoding.fromlocal("test") |
|
2343 |
except util.Abort |
|
|
2343 | except util.Abort as inst: | |
|
2344 | 2344 | ui.write(" %s\n" % inst) |
|
2345 | 2345 | ui.write(_(" (check that your locale is properly set)\n")) |
|
2346 | 2346 | problems += 1 |
@@ -2358,7 +2358,7 b' def debuginstall(ui):' | |||
|
2358 | 2358 | try: |
|
2359 | 2359 | import bdiff, mpatch, base85, osutil |
|
2360 | 2360 | dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes |
|
2361 |
except Exception |
|
|
2361 | except Exception as inst: | |
|
2362 | 2362 | ui.write(" %s\n" % inst) |
|
2363 | 2363 | ui.write(_(" One or more extensions could not be found")) |
|
2364 | 2364 | ui.write(_(" (check that you compiled the extensions)\n")) |
@@ -2374,7 +2374,7 b' def debuginstall(ui):' | |||
|
2374 | 2374 | # template found, check if it is working |
|
2375 | 2375 | try: |
|
2376 | 2376 | templater.templater(m) |
|
2377 |
except Exception |
|
|
2377 | except Exception as inst: | |
|
2378 | 2378 | ui.write(" %s\n" % inst) |
|
2379 | 2379 | p = None |
|
2380 | 2380 | else: |
@@ -2406,7 +2406,7 b' def debuginstall(ui):' | |||
|
2406 | 2406 | ui.status(_("checking username...\n")) |
|
2407 | 2407 | try: |
|
2408 | 2408 | ui.username() |
|
2409 |
except util.Abort |
|
|
2409 | except util.Abort as e: | |
|
2410 | 2410 | ui.write(" %s\n" % e) |
|
2411 | 2411 | ui.write(_(" (specify a username in your configuration file)\n")) |
|
2412 | 2412 | problems += 1 |
@@ -2517,7 +2517,7 b' def debuglocks(ui, repo, **opts):' | |||
|
2517 | 2517 | % (user, pid, host) |
|
2518 | 2518 | ui.write("%-6s %s (%ds)\n" % (name + ":", locker, age)) |
|
2519 | 2519 | return 1 |
|
2520 |
except OSError |
|
|
2520 | except OSError as e: | |
|
2521 | 2521 | if e.errno != errno.ENOENT: |
|
2522 | 2522 | raise |
|
2523 | 2523 | |
@@ -2581,7 +2581,7 b' def debugobsolete(ui, repo, precursor=No' | |||
|
2581 | 2581 | parents=parents, date=date, |
|
2582 | 2582 | metadata=metadata) |
|
2583 | 2583 | tr.close() |
|
2584 |
except ValueError |
|
|
2584 | except ValueError as exc: | |
|
2585 | 2585 | raise util.Abort(_('bad obsmarker input: %s') % exc) |
|
2586 | 2586 | finally: |
|
2587 | 2587 | tr.release() |
@@ -3470,7 +3470,7 b' def graft(ui, repo, *revs, **opts):' | |||
|
3470 | 3470 | try: |
|
3471 | 3471 | nodes = repo.vfs.read('graftstate').splitlines() |
|
3472 | 3472 | revs = [repo[node].rev() for node in nodes] |
|
3473 |
except IOError |
|
|
3473 | except IOError as inst: | |
|
3474 | 3474 | if inst.errno != errno.ENOENT: |
|
3475 | 3475 | raise |
|
3476 | 3476 | raise util.Abort(_("no graft state found, can't continue")) |
@@ -3664,7 +3664,7 b' def grep(ui, repo, pattern, *pats, **opt' | |||
|
3664 | 3664 | reflags |= re.I |
|
3665 | 3665 | try: |
|
3666 | 3666 | regexp = util.re.compile(pattern, reflags) |
|
3667 |
except re.error |
|
|
3667 | except re.error as inst: | |
|
3668 | 3668 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) |
|
3669 | 3669 | return 1 |
|
3670 | 3670 | sep, eol = ':', '\n' |
@@ -5083,7 +5083,7 b' def postincoming(ui, repo, modheads, opt' | |||
|
5083 | 5083 | checkout, movemarkfrom = bookmarks.calculateupdate(ui, repo, checkout) |
|
5084 | 5084 | try: |
|
5085 | 5085 | ret = hg.update(repo, checkout) |
|
5086 |
except util.Abort |
|
|
5086 | except util.Abort as inst: | |
|
5087 | 5087 | ui.warn(_("not updating: %s\n") % str(inst)) |
|
5088 | 5088 | if inst.hint: |
|
5089 | 5089 | ui.warn(_("(%s)\n") % inst.hint) |
@@ -300,9 +300,9 b' class _requesthandler(SocketServer.Strea' | |||
|
300 | 300 | sv.serve() |
|
301 | 301 | # handle exceptions that may be raised by command server. most of |
|
302 | 302 | # known exceptions are caught by dispatch. |
|
303 |
except util.Abort |
|
|
303 | except util.Abort as inst: | |
|
304 | 304 | ui.warn(_('abort: %s\n') % inst) |
|
305 |
except IOError |
|
|
305 | except IOError as inst: | |
|
306 | 306 | if inst.errno != errno.EPIPE: |
|
307 | 307 | raise |
|
308 | 308 | except KeyboardInterrupt: |
@@ -122,7 +122,7 b' class config(object):' | |||
|
122 | 122 | try: |
|
123 | 123 | include(inc, remap=remap, sections=sections) |
|
124 | 124 | break |
|
125 |
except IOError |
|
|
125 | except IOError as inst: | |
|
126 | 126 | if inst.errno != errno.ENOENT: |
|
127 | 127 | raise error.ParseError(_("cannot include %s (%s)") |
|
128 | 128 | % (inc, inst.strerror), |
@@ -1438,7 +1438,7 b' class workingctx(committablectx):' | |||
|
1438 | 1438 | def copy(self, source, dest): |
|
1439 | 1439 | try: |
|
1440 | 1440 | st = self._repo.wvfs.lstat(dest) |
|
1441 |
except OSError |
|
|
1441 | except OSError as err: | |
|
1442 | 1442 | if err.errno != errno.ENOENT: |
|
1443 | 1443 | raise |
|
1444 | 1444 | self._repo.ui.warn(_("%s does not exist!\n") % dest) |
@@ -1684,7 +1684,7 b' class workingfilectx(committablefilectx)' | |||
|
1684 | 1684 | t, tz = self._changectx.date() |
|
1685 | 1685 | try: |
|
1686 | 1686 | return (int(self._repo.wvfs.lstat(self._path).st_mtime), tz) |
|
1687 |
except OSError |
|
|
1687 | except OSError as err: | |
|
1688 | 1688 | if err.errno != errno.ENOENT: |
|
1689 | 1689 | raise |
|
1690 | 1690 | return (t, tz) |
@@ -115,7 +115,7 b' class dirstate(object):' | |||
|
115 | 115 | def _branch(self): |
|
116 | 116 | try: |
|
117 | 117 | return self._opener.read("branch").strip() or "default" |
|
118 |
except IOError |
|
|
118 | except IOError as inst: | |
|
119 | 119 | if inst.errno != errno.ENOENT: |
|
120 | 120 | raise |
|
121 | 121 | return "default" |
@@ -131,7 +131,7 b' class dirstate(object):' | |||
|
131 | 131 | return st[:20], st[20:40] |
|
132 | 132 | elif l > 0 and l < 40: |
|
133 | 133 | raise util.Abort(_('working directory state appears damaged!')) |
|
134 |
except IOError |
|
|
134 | except IOError as err: | |
|
135 | 135 | if err.errno != errno.ENOENT: |
|
136 | 136 | raise |
|
137 | 137 | return [nullid, nullid] |
@@ -331,7 +331,7 b' class dirstate(object):' | |||
|
331 | 331 | st = fp.read() |
|
332 | 332 | finally: |
|
333 | 333 | fp.close() |
|
334 |
except IOError |
|
|
334 | except IOError as err: | |
|
335 | 335 | if err.errno != errno.ENOENT: |
|
336 | 336 | raise |
|
337 | 337 | return |
@@ -717,7 +717,7 b' class dirstate(object):' | |||
|
717 | 717 | badfn(ff, badtype(kind)) |
|
718 | 718 | if nf in dmap: |
|
719 | 719 | results[nf] = None |
|
720 |
except OSError |
|
|
720 | except OSError as inst: # nf not found on disk - it is dirstate only | |
|
721 | 721 | if nf in dmap: # does it exactly match a missing file? |
|
722 | 722 | results[nf] = None |
|
723 | 723 | else: # does it match a missing directory? |
@@ -802,7 +802,7 b' class dirstate(object):' | |||
|
802 | 802 | skip = '.hg' |
|
803 | 803 | try: |
|
804 | 804 | entries = listdir(join(nd), stat=True, skip=skip) |
|
805 |
except OSError |
|
|
805 | except OSError as inst: | |
|
806 | 806 | if inst.errno in (errno.EACCES, errno.ENOENT): |
|
807 | 807 | match.bad(self.pathto(nd), inst.strerror) |
|
808 | 808 | continue |
@@ -76,12 +76,12 b' def dispatch(req):' | |||
|
76 | 76 | req.ui.fout = req.fout |
|
77 | 77 | if req.ferr: |
|
78 | 78 | req.ui.ferr = req.ferr |
|
79 |
except util.Abort |
|
|
79 | except util.Abort as inst: | |
|
80 | 80 | ferr.write(_("abort: %s\n") % inst) |
|
81 | 81 | if inst.hint: |
|
82 | 82 | ferr.write(_("(%s)\n") % inst.hint) |
|
83 | 83 | return -1 |
|
84 |
except error.ParseError |
|
|
84 | except error.ParseError as inst: | |
|
85 | 85 | _formatparse(ferr.write, inst) |
|
86 | 86 | return -1 |
|
87 | 87 | |
@@ -172,29 +172,29 b' def _runcatch(req):' | |||
|
172 | 172 | |
|
173 | 173 | # Global exception handling, alphabetically |
|
174 | 174 | # Mercurial-specific first, followed by built-in and library exceptions |
|
175 |
except error.AmbiguousCommand |
|
|
175 | except error.AmbiguousCommand as inst: | |
|
176 | 176 | ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
177 | 177 | (inst.args[0], " ".join(inst.args[1]))) |
|
178 |
except error.ParseError |
|
|
178 | except error.ParseError as inst: | |
|
179 | 179 | _formatparse(ui.warn, inst) |
|
180 | 180 | return -1 |
|
181 |
except error.LockHeld |
|
|
181 | except error.LockHeld as inst: | |
|
182 | 182 | if inst.errno == errno.ETIMEDOUT: |
|
183 | 183 | reason = _('timed out waiting for lock held by %s') % inst.locker |
|
184 | 184 | else: |
|
185 | 185 | reason = _('lock held by %s') % inst.locker |
|
186 | 186 | ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
|
187 |
except error.LockUnavailable |
|
|
187 | except error.LockUnavailable as inst: | |
|
188 | 188 | ui.warn(_("abort: could not lock %s: %s\n") % |
|
189 | 189 | (inst.desc or inst.filename, inst.strerror)) |
|
190 |
except error.CommandError |
|
|
190 | except error.CommandError as inst: | |
|
191 | 191 | if inst.args[0]: |
|
192 | 192 | ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
193 | 193 | commands.help_(ui, inst.args[0], full=False, command=True) |
|
194 | 194 | else: |
|
195 | 195 | ui.warn(_("hg: %s\n") % inst.args[1]) |
|
196 | 196 | commands.help_(ui, 'shortlist') |
|
197 |
except error.OutOfBandError |
|
|
197 | except error.OutOfBandError as inst: | |
|
198 | 198 | if inst.args: |
|
199 | 199 | msg = _("abort: remote error:\n") |
|
200 | 200 | else: |
@@ -204,11 +204,11 b' def _runcatch(req):' | |||
|
204 | 204 | ui.warn(''.join(inst.args)) |
|
205 | 205 | if inst.hint: |
|
206 | 206 | ui.warn('(%s)\n' % inst.hint) |
|
207 |
except error.RepoError |
|
|
207 | except error.RepoError as inst: | |
|
208 | 208 | ui.warn(_("abort: %s!\n") % inst) |
|
209 | 209 | if inst.hint: |
|
210 | 210 | ui.warn(_("(%s)\n") % inst.hint) |
|
211 |
except error.ResponseError |
|
|
211 | except error.ResponseError as inst: | |
|
212 | 212 | ui.warn(_("abort: %s") % inst.args[0]) |
|
213 | 213 | if not isinstance(inst.args[1], basestring): |
|
214 | 214 | ui.warn(" %r\n" % (inst.args[1],)) |
@@ -216,13 +216,13 b' def _runcatch(req):' | |||
|
216 | 216 | ui.warn(_(" empty string\n")) |
|
217 | 217 | else: |
|
218 | 218 | ui.warn("\n%r\n" % util.ellipsis(inst.args[1])) |
|
219 |
except error.CensoredNodeError |
|
|
219 | except error.CensoredNodeError as inst: | |
|
220 | 220 | ui.warn(_("abort: file censored %s!\n") % inst) |
|
221 |
except error.RevlogError |
|
|
221 | except error.RevlogError as inst: | |
|
222 | 222 | ui.warn(_("abort: %s!\n") % inst) |
|
223 | 223 | except error.SignalInterrupt: |
|
224 | 224 | ui.warn(_("killed!\n")) |
|
225 |
except error.UnknownCommand |
|
|
225 | except error.UnknownCommand as inst: | |
|
226 | 226 | ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
227 | 227 | try: |
|
228 | 228 | # check if the command is in a disabled extension |
@@ -238,21 +238,21 b' def _runcatch(req):' | |||
|
238 | 238 | suggested = True |
|
239 | 239 | if not suggested: |
|
240 | 240 | commands.help_(ui, 'shortlist') |
|
241 |
except error.InterventionRequired |
|
|
241 | except error.InterventionRequired as inst: | |
|
242 | 242 | ui.warn("%s\n" % inst) |
|
243 | 243 | return 1 |
|
244 |
except util.Abort |
|
|
244 | except util.Abort as inst: | |
|
245 | 245 | ui.warn(_("abort: %s\n") % inst) |
|
246 | 246 | if inst.hint: |
|
247 | 247 | ui.warn(_("(%s)\n") % inst.hint) |
|
248 |
except ImportError |
|
|
248 | except ImportError as inst: | |
|
249 | 249 | ui.warn(_("abort: %s!\n") % inst) |
|
250 | 250 | m = str(inst).split()[-1] |
|
251 | 251 | if m in "mpatch bdiff".split(): |
|
252 | 252 | ui.warn(_("(did you forget to compile extensions?)\n")) |
|
253 | 253 | elif m in "zlib".split(): |
|
254 | 254 | ui.warn(_("(is your Python install correct?)\n")) |
|
255 |
except IOError |
|
|
255 | except IOError as inst: | |
|
256 | 256 | if util.safehasattr(inst, "code"): |
|
257 | 257 | ui.warn(_("abort: %s\n") % inst) |
|
258 | 258 | elif util.safehasattr(inst, "reason"): |
@@ -276,7 +276,7 b' def _runcatch(req):' | |||
|
276 | 276 | ui.warn(_("abort: %s\n") % inst.strerror) |
|
277 | 277 | else: |
|
278 | 278 | raise |
|
279 |
except OSError |
|
|
279 | except OSError as inst: | |
|
280 | 280 | if getattr(inst, "filename", None) is not None: |
|
281 | 281 | ui.warn(_("abort: %s: '%s'\n") % (inst.strerror, inst.filename)) |
|
282 | 282 | else: |
@@ -284,7 +284,7 b' def _runcatch(req):' | |||
|
284 | 284 | except KeyboardInterrupt: |
|
285 | 285 | try: |
|
286 | 286 | ui.warn(_("interrupted!\n")) |
|
287 |
except IOError |
|
|
287 | except IOError as inst: | |
|
288 | 288 | if inst.errno == errno.EPIPE: |
|
289 | 289 | if ui.debugflag: |
|
290 | 290 | ui.warn(_("\nbroken pipe\n")) |
@@ -292,11 +292,11 b' def _runcatch(req):' | |||
|
292 | 292 | raise |
|
293 | 293 | except MemoryError: |
|
294 | 294 | ui.warn(_("abort: out of memory\n")) |
|
295 |
except SystemExit |
|
|
295 | except SystemExit as inst: | |
|
296 | 296 | # Commands shouldn't sys.exit directly, but give a return code. |
|
297 | 297 | # Just in case catch this and and pass exit code to caller. |
|
298 | 298 | return inst.code |
|
299 |
except socket.error |
|
|
299 | except socket.error as inst: | |
|
300 | 300 | ui.warn(_("abort: %s\n") % inst.args[-1]) |
|
301 | 301 | except: # re-raises |
|
302 | 302 | myver = util.version() |
@@ -452,7 +452,7 b' class cmdalias(object):' | |||
|
452 | 452 | |
|
453 | 453 | try: |
|
454 | 454 | args = shlex.split(self.definition) |
|
455 |
except ValueError |
|
|
455 | except ValueError as inst: | |
|
456 | 456 | self.badalias = (_("error in definition for alias '%s': %s") |
|
457 | 457 | % (self.name, inst)) |
|
458 | 458 | return |
@@ -543,7 +543,7 b' def _parse(ui, args):' | |||
|
543 | 543 | |
|
544 | 544 | try: |
|
545 | 545 | args = fancyopts.fancyopts(args, commands.globalopts, options) |
|
546 |
except fancyopts.getopt.GetoptError |
|
|
546 | except fancyopts.getopt.GetoptError as inst: | |
|
547 | 547 | raise error.CommandError(None, inst) |
|
548 | 548 | |
|
549 | 549 | if args: |
@@ -566,7 +566,7 b' def _parse(ui, args):' | |||
|
566 | 566 | |
|
567 | 567 | try: |
|
568 | 568 | args = fancyopts.fancyopts(args, c, cmdoptions, True) |
|
569 |
except fancyopts.getopt.GetoptError |
|
|
569 | except fancyopts.getopt.GetoptError as inst: | |
|
570 | 570 | raise error.CommandError(cmd, inst) |
|
571 | 571 | |
|
572 | 572 | # separate global options back out |
@@ -665,7 +665,7 b' def _getlocal(ui, rpath):' | |||
|
665 | 665 | """ |
|
666 | 666 | try: |
|
667 | 667 | wd = os.getcwd() |
|
668 |
except OSError |
|
|
668 | except OSError as e: | |
|
669 | 669 | raise util.Abort(_("error getting current working directory: %s") % |
|
670 | 670 | e.strerror) |
|
671 | 671 | path = cmdutil.findrepo(wd) or "" |
@@ -138,7 +138,7 b' def tolocal(s):' | |||
|
138 | 138 | except UnicodeDecodeError: |
|
139 | 139 | u = s.decode("utf-8", "replace") # last ditch |
|
140 | 140 | return u.encode(encoding, "replace") # can't round-trip |
|
141 |
except LookupError |
|
|
141 | except LookupError as k: | |
|
142 | 142 | raise error.Abort(k, hint="please check your locale settings") |
|
143 | 143 | |
|
144 | 144 | def fromlocal(s): |
@@ -158,10 +158,10 b' def fromlocal(s):' | |||
|
158 | 158 | |
|
159 | 159 | try: |
|
160 | 160 | return s.decode(encoding, encodingmode).encode("utf-8") |
|
161 |
except UnicodeDecodeError |
|
|
161 | except UnicodeDecodeError as inst: | |
|
162 | 162 | sub = s[max(0, inst.start - 10):inst.start + 10] |
|
163 | 163 | raise error.Abort("decoding near '%s': %s!" % (sub, inst)) |
|
164 |
except LookupError |
|
|
164 | except LookupError as k: | |
|
165 | 165 | raise error.Abort(k, hint="please check your locale settings") |
|
166 | 166 | |
|
167 | 167 | # How to treat ambiguous-width characters. Set to 'wide' to treat as wide. |
@@ -330,7 +330,7 b' def lower(s):' | |||
|
330 | 330 | return lu.encode(encoding) |
|
331 | 331 | except UnicodeError: |
|
332 | 332 | return s.lower() # we don't know how to fold this except in ASCII |
|
333 |
except LookupError |
|
|
333 | except LookupError as k: | |
|
334 | 334 | raise error.Abort(k, hint="please check your locale settings") |
|
335 | 335 | |
|
336 | 336 | def upper(s): |
@@ -353,7 +353,7 b' def upperfallback(s):' | |||
|
353 | 353 | return uu.encode(encoding) |
|
354 | 354 | except UnicodeError: |
|
355 | 355 | return s.upper() # we don't know how to fold this except in ASCII |
|
356 |
except LookupError |
|
|
356 | except LookupError as k: | |
|
357 | 357 | raise error.Abort(k, hint="please check your locale settings") |
|
358 | 358 | |
|
359 | 359 | class normcasespecs(object): |
@@ -215,7 +215,7 b' def push(repo, remote, force=False, revs' | |||
|
215 | 215 | localwlock = pushop.repo.wlock() |
|
216 | 216 | locallock = pushop.repo.lock() |
|
217 | 217 | pushop.locallocked = True |
|
218 |
except IOError |
|
|
218 | except IOError as err: | |
|
219 | 219 | pushop.locallocked = False |
|
220 | 220 | if err.errno != errno.EACCES: |
|
221 | 221 | raise |
@@ -646,16 +646,16 b' def _pushbundle2(pushop):' | |||
|
646 | 646 | try: |
|
647 | 647 | try: |
|
648 | 648 | reply = pushop.remote.unbundle(stream, ['force'], 'push') |
|
649 |
except error.BundleValueError |
|
|
649 | except error.BundleValueError as exc: | |
|
650 | 650 | raise util.Abort('missing support for %s' % exc) |
|
651 | 651 | try: |
|
652 | 652 | trgetter = None |
|
653 | 653 | if pushback: |
|
654 | 654 | trgetter = pushop.trmanager.transaction |
|
655 | 655 | op = bundle2.processbundle(pushop.repo, reply, trgetter) |
|
656 |
except error.BundleValueError |
|
|
656 | except error.BundleValueError as exc: | |
|
657 | 657 | raise util.Abort('missing support for %s' % exc) |
|
658 |
except error.PushkeyFailed |
|
|
658 | except error.PushkeyFailed as exc: | |
|
659 | 659 | partid = int(exc.partid) |
|
660 | 660 | if partid not in pushop.pkfailcb: |
|
661 | 661 | raise |
@@ -1061,7 +1061,7 b' def _pullbundle2(pullop):' | |||
|
1061 | 1061 | bundle = pullop.remote.getbundle('pull', **kwargs) |
|
1062 | 1062 | try: |
|
1063 | 1063 | op = bundle2.processbundle(pullop.repo, bundle, pullop.gettransaction) |
|
1064 |
except error.BundleValueError |
|
|
1064 | except error.BundleValueError as exc: | |
|
1065 | 1065 | raise util.Abort('missing support for %s' % exc) |
|
1066 | 1066 | |
|
1067 | 1067 | if pullop.fetch: |
@@ -1425,7 +1425,7 b' def unbundle(repo, cg, heads, source, ur' | |||
|
1425 | 1425 | def recordout(output): |
|
1426 | 1426 | r.newpart('output', data=output, mandatory=False) |
|
1427 | 1427 | tr.close() |
|
1428 |
except BaseException |
|
|
1428 | except BaseException as exc: | |
|
1429 | 1429 | exc.duringunbundle2 = True |
|
1430 | 1430 | if captureoutput and r is not None: |
|
1431 | 1431 | parts = exc._bundle2salvagedoutput = r.salvageoutput() |
@@ -53,7 +53,7 b' def loadpath(path, module_name):' | |||
|
53 | 53 | else: |
|
54 | 54 | try: |
|
55 | 55 | return imp.load_source(module_name, path) |
|
56 |
except IOError |
|
|
56 | except IOError as exc: | |
|
57 | 57 | if not exc.filename: |
|
58 | 58 | exc.filename = path # python does not fill this |
|
59 | 59 | raise |
@@ -82,7 +82,7 b' def load(ui, name, path):' | |||
|
82 | 82 | return mod |
|
83 | 83 | try: |
|
84 | 84 | mod = importh("hgext.%s" % name) |
|
85 |
except ImportError |
|
|
85 | except ImportError as err: | |
|
86 | 86 | ui.debug('could not import hgext.%s (%s): trying %s\n' |
|
87 | 87 | % (name, err, name)) |
|
88 | 88 | if ui.debugflag: |
@@ -105,7 +105,7 b' def loadall(ui):' | |||
|
105 | 105 | load(ui, name, path) |
|
106 | 106 | except KeyboardInterrupt: |
|
107 | 107 | raise |
|
108 |
except Exception |
|
|
108 | except Exception as inst: | |
|
109 | 109 | if path: |
|
110 | 110 | ui.warn(_("*** failed to import extension %s from %s: %s\n") |
|
111 | 111 | % (name, path, inst)) |
@@ -280,7 +280,7 b' def grep(mctx, x):' | |||
|
280 | 280 | try: |
|
281 | 281 | # i18n: "grep" is a keyword |
|
282 | 282 | r = re.compile(getstring(x, _("grep requires a pattern"))) |
|
283 |
except re.error |
|
|
283 | except re.error as e: | |
|
284 | 284 | raise error.ParseError(_('invalid match pattern: %s') % e) |
|
285 | 285 | return [f for f in mctx.existing() if r.search(mctx.ctx[f].data())] |
|
286 | 286 |
@@ -228,7 +228,7 b' def help_(ui, name, unknowncmd=False, fu' | |||
|
228 | 228 | try: |
|
229 | 229 | aliases, entry = cmdutil.findcmd(name, commands.table, |
|
230 | 230 | strict=unknowncmd) |
|
231 |
except error.AmbiguousCommand |
|
|
231 | except error.AmbiguousCommand as inst: | |
|
232 | 232 | # py3k fix: except vars can't be used outside the scope of the |
|
233 | 233 | # except block, nor can be used inside a lambda. python issue4617 |
|
234 | 234 | prefix = inst.args[0] |
@@ -202,7 +202,7 b' def share(ui, source, dest=None, update=' | |||
|
202 | 202 | requirements = '' |
|
203 | 203 | try: |
|
204 | 204 | requirements = srcrepo.vfs.read('requires') |
|
205 |
except IOError |
|
|
205 | except IOError as inst: | |
|
206 | 206 | if inst.errno != errno.ENOENT: |
|
207 | 207 | raise |
|
208 | 208 | |
@@ -388,7 +388,7 b' def clone(ui, peeropts, source, dest=Non' | |||
|
388 | 388 | try: |
|
389 | 389 | destpath = hgdir |
|
390 | 390 | util.makedir(destpath, notindexed=True) |
|
391 |
except OSError |
|
|
391 | except OSError as inst: | |
|
392 | 392 | if inst.errno == errno.EEXIST: |
|
393 | 393 | cleandir = None |
|
394 | 394 | raise util.Abort(_("destination '%s' already exists") |
@@ -428,7 +428,7 b' def clone(ui, peeropts, source, dest=Non' | |||
|
428 | 428 | try: |
|
429 | 429 | destpeer = peer(srcrepo or ui, peeropts, dest, create=True) |
|
430 | 430 | # only pass ui when no srcrepo |
|
431 |
except OSError |
|
|
431 | except OSError as inst: | |
|
432 | 432 | if inst.errno == errno.EEXIST: |
|
433 | 433 | cleandir = None |
|
434 | 434 | raise util.Abort(_("destination '%s' already exists") |
@@ -153,7 +153,7 b' def staticfile(directory, fname, req):' | |||
|
153 | 153 | req.respond(HTTP_OK, ct, body=data) |
|
154 | 154 | except TypeError: |
|
155 | 155 | raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') |
|
156 |
except OSError |
|
|
156 | except OSError as err: | |
|
157 | 157 | if err.errno == errno.ENOENT: |
|
158 | 158 | raise ErrorResponse(HTTP_NOT_FOUND) |
|
159 | 159 | else: |
@@ -190,7 +190,7 b' class hgweb(object):' | |||
|
190 | 190 | if cmd in perms: |
|
191 | 191 | self.check_perm(req, perms[cmd]) |
|
192 | 192 | return protocol.call(self.repo, req, cmd) |
|
193 |
except ErrorResponse |
|
|
193 | except ErrorResponse as inst: | |
|
194 | 194 | # A client that sends unbundle without 100-continue will |
|
195 | 195 | # break if we respond early. |
|
196 | 196 | if (cmd == 'unbundle' and |
@@ -269,17 +269,17 b' class hgweb(object):' | |||
|
269 | 269 | |
|
270 | 270 | return content |
|
271 | 271 | |
|
272 |
except (error.LookupError, error.RepoLookupError) |
|
|
272 | except (error.LookupError, error.RepoLookupError) as err: | |
|
273 | 273 | req.respond(HTTP_NOT_FOUND, ctype) |
|
274 | 274 | msg = str(err) |
|
275 | 275 | if (util.safehasattr(err, 'name') and |
|
276 | 276 | not isinstance(err, error.ManifestLookupError)): |
|
277 | 277 | msg = 'revision not found: %s' % err.name |
|
278 | 278 | return tmpl('error', error=msg) |
|
279 |
except (error.RepoError, error.RevlogError) |
|
|
279 | except (error.RepoError, error.RevlogError) as inst: | |
|
280 | 280 | req.respond(HTTP_SERVER_ERROR, ctype) |
|
281 | 281 | return tmpl('error', error=str(inst)) |
|
282 |
except ErrorResponse |
|
|
282 | except ErrorResponse as inst: | |
|
283 | 283 | req.respond(inst, ctype) |
|
284 | 284 | if inst.code == HTTP_NOT_MODIFIED: |
|
285 | 285 | # Not allowed to return a body on a 304 |
@@ -219,10 +219,10 b' class hgwebdir(object):' | |||
|
219 | 219 | # ensure caller gets private copy of ui |
|
220 | 220 | repo = hg.repository(self.ui.copy(), real) |
|
221 | 221 | return hgweb(repo).run_wsgi(req) |
|
222 |
except IOError |
|
|
222 | except IOError as inst: | |
|
223 | 223 | msg = inst.strerror |
|
224 | 224 | raise ErrorResponse(HTTP_SERVER_ERROR, msg) |
|
225 |
except error.RepoError |
|
|
225 | except error.RepoError as inst: | |
|
226 | 226 | raise ErrorResponse(HTTP_SERVER_ERROR, str(inst)) |
|
227 | 227 | |
|
228 | 228 | up = virtualrepo.rfind('/') |
@@ -240,7 +240,7 b' class hgwebdir(object):' | |||
|
240 | 240 | req.respond(HTTP_NOT_FOUND, ctype) |
|
241 | 241 | return tmpl("notfound", repo=virtual) |
|
242 | 242 | |
|
243 |
except ErrorResponse |
|
|
243 | except ErrorResponse as err: | |
|
244 | 244 | req.respond(err, ctype) |
|
245 | 245 | return tmpl('error', error=err.message or '') |
|
246 | 246 | finally: |
@@ -336,7 +336,7 b' class hgwebdir(object):' | |||
|
336 | 336 | u = self.ui.copy() |
|
337 | 337 | try: |
|
338 | 338 | u.readconfig(os.path.join(path, '.hg', 'hgrc')) |
|
339 |
except Exception |
|
|
339 | except Exception as e: | |
|
340 | 340 | u.warn(_('error reading %s/.hg/hgrc: %s\n') % (path, e)) |
|
341 | 341 | continue |
|
342 | 342 | def get(section, name, default=None): |
@@ -111,7 +111,7 b' class wsgirequest(object):' | |||
|
111 | 111 | if thing: |
|
112 | 112 | try: |
|
113 | 113 | self.server_write(thing) |
|
114 |
except socket.error |
|
|
114 | except socket.error as inst: | |
|
115 | 115 | if inst[0] != errno.ECONNRESET: |
|
116 | 116 | raise |
|
117 | 117 |
@@ -71,7 +71,7 b' class _httprequesthandler(BaseHTTPServer' | |||
|
71 | 71 | def do_write(self): |
|
72 | 72 | try: |
|
73 | 73 | self.do_hgweb() |
|
74 |
except socket.error |
|
|
74 | except socket.error as inst: | |
|
75 | 75 | if inst[0] != errno.EPIPE: |
|
76 | 76 | raise |
|
77 | 77 | |
@@ -226,7 +226,7 b' class _httprequesthandleropenssl(_httpre' | |||
|
226 | 226 | import OpenSSL |
|
227 | 227 | try: |
|
228 | 228 | _httprequesthandler.do_write(self) |
|
229 |
except OpenSSL.SSL.SysCallError |
|
|
229 | except OpenSSL.SSL.SysCallError as inst: | |
|
230 | 230 | if inst.args[0] != errno.EPIPE: |
|
231 | 231 | raise |
|
232 | 232 | |
@@ -344,6 +344,6 b' def create_server(ui, app):' | |||
|
344 | 344 | port = util.getport(ui.config('web', 'port', 8000)) |
|
345 | 345 | try: |
|
346 | 346 | return cls(ui, app, (address, port), handler) |
|
347 |
except socket.error |
|
|
347 | except socket.error as inst: | |
|
348 | 348 | raise util.Abort(_("cannot start server at '%s:%d': %s") |
|
349 | 349 | % (address, port, inst.args[1])) |
@@ -76,7 +76,7 b' def rawfile(web, req, tmpl):' | |||
|
76 | 76 | |
|
77 | 77 | try: |
|
78 | 78 | fctx = webutil.filectx(web.repo, req) |
|
79 |
except error.LookupError |
|
|
79 | except error.LookupError as inst: | |
|
80 | 80 | try: |
|
81 | 81 | content = manifest(web, req, tmpl) |
|
82 | 82 | req.respond(HTTP_OK, web.ctype) |
@@ -160,7 +160,7 b' def file(web, req, tmpl):' | |||
|
160 | 160 | return manifest(web, req, tmpl) |
|
161 | 161 | try: |
|
162 | 162 | return _filerevision(web, req, tmpl, webutil.filectx(web.repo, req)) |
|
163 |
except error.LookupError |
|
|
163 | except error.LookupError as inst: | |
|
164 | 164 | try: |
|
165 | 165 | return manifest(web, req, tmpl) |
|
166 | 166 | except ErrorResponse: |
@@ -80,7 +80,7 b' def _pythonhook(ui, repo, name, hname, f' | |||
|
80 | 80 | sys.stdout, sys.stderr, sys.stdin = ui.fout, ui.ferr, ui.fin |
|
81 | 81 | |
|
82 | 82 | r = obj(ui=ui, repo=repo, hooktype=name, **args) |
|
83 |
except Exception |
|
|
83 | except Exception as exc: | |
|
84 | 84 | if isinstance(exc, util.Abort): |
|
85 | 85 | ui.warn(_('error: %s hook failed: %s\n') % |
|
86 | 86 | (hname, exc.args[0])) |
@@ -166,7 +166,7 b' class HTTPResponse(object):' | |||
|
166 | 166 | raise HTTPTimeoutException('timeout reading data') |
|
167 | 167 | try: |
|
168 | 168 | data = self.sock.recv(INCOMING_BUFFER_SIZE) |
|
169 |
except socket.sslerror |
|
|
169 | except socket.sslerror as e: | |
|
170 | 170 | if e.args[0] != socket.SSL_ERROR_WANT_READ: |
|
171 | 171 | raise |
|
172 | 172 | logger.debug('SSL_ERROR_WANT_READ in _select, should retry later') |
@@ -555,7 +555,7 b' class HTTPConnection(object):' | |||
|
555 | 555 | try: |
|
556 | 556 | try: |
|
557 | 557 | data = r[0].recv(INCOMING_BUFFER_SIZE) |
|
558 |
except socket.sslerror |
|
|
558 | except socket.sslerror as e: | |
|
559 | 559 | if e.args[0] != socket.SSL_ERROR_WANT_READ: |
|
560 | 560 | raise |
|
561 | 561 | logger.debug('SSL_ERROR_WANT_READ while sending ' |
@@ -610,7 +610,7 b' class HTTPConnection(object):' | |||
|
610 | 610 | # Jump to the next select() call so we load more |
|
611 | 611 | # data if the server is still sending us content. |
|
612 | 612 | continue |
|
613 |
except socket.error |
|
|
613 | except socket.error as e: | |
|
614 | 614 | if e[0] != errno.EPIPE and not was_first: |
|
615 | 615 | raise |
|
616 | 616 | |
@@ -633,7 +633,7 b' class HTTPConnection(object):' | |||
|
633 | 633 | else: |
|
634 | 634 | out = data |
|
635 | 635 | amt = w[0].send(out) |
|
636 |
except socket.error |
|
|
636 | except socket.error as e: | |
|
637 | 637 | if e[0] == socket.SSL_ERROR_WANT_WRITE and self.ssl: |
|
638 | 638 | # This means that SSL hasn't flushed its buffer into |
|
639 | 639 | # the socket yet. |
@@ -64,7 +64,7 b' except AttributeError:' | |||
|
64 | 64 | sock = socket.socket(af, socktype, proto) |
|
65 | 65 | logger.info("connect: (%s, %s)", host, port) |
|
66 | 66 | sock.connect(sa) |
|
67 |
except socket.error |
|
|
67 | except socket.error as msg: | |
|
68 | 68 | logger.info('connect fail: %s %s', host, port) |
|
69 | 69 | if sock: |
|
70 | 70 | sock.close() |
@@ -100,7 +100,7 b' else:' | |||
|
100 | 100 | while True: |
|
101 | 101 | try: |
|
102 | 102 | return self._ssl.read(buflen) |
|
103 |
except socket.sslerror |
|
|
103 | except socket.sslerror as x: | |
|
104 | 104 | if x.args[0] == socket.SSL_ERROR_WANT_READ: |
|
105 | 105 | continue |
|
106 | 106 | else: |
@@ -211,7 +211,7 b' class http2handler(urllib2.HTTPHandler, ' | |||
|
211 | 211 | path = '/' + path |
|
212 | 212 | h.request(req.get_method(), path, req.data, headers) |
|
213 | 213 | r = h.getresponse() |
|
214 |
except socket.error |
|
|
214 | except socket.error as err: # XXX what error? | |
|
215 | 215 | raise urllib2.URLError(err) |
|
216 | 216 | |
|
217 | 217 | # Pick apart the HTTPResponse object to get the addinfourl |
@@ -119,11 +119,11 b' class httppeer(wireproto.wirepeer):' | |||
|
119 | 119 | req.add_unredirected_header('Content-Length', '%d' % size) |
|
120 | 120 | try: |
|
121 | 121 | resp = self.urlopener.open(req) |
|
122 |
except urllib2.HTTPError |
|
|
122 | except urllib2.HTTPError as inst: | |
|
123 | 123 | if inst.code == 401: |
|
124 | 124 | raise util.Abort(_('authorization failed')) |
|
125 | 125 | raise |
|
126 |
except httplib.HTTPException |
|
|
126 | except httplib.HTTPException as inst: | |
|
127 | 127 | self.ui.debug('http error while sending %s command\n' % cmd) |
|
128 | 128 | self.ui.traceback() |
|
129 | 129 | raise IOError(None, inst) |
@@ -205,7 +205,7 b' class httppeer(wireproto.wirepeer):' | |||
|
205 | 205 | if len(vals) < 2: |
|
206 | 206 | raise error.ResponseError(_("unexpected response:"), r) |
|
207 | 207 | return vals |
|
208 |
except socket.error |
|
|
208 | except socket.error as err: | |
|
209 | 209 | if err.args[0] in (errno.ECONNRESET, errno.EPIPE): |
|
210 | 210 | raise util.Abort(_('push failed: %s') % err.args[1]) |
|
211 | 211 | raise util.Abort(err.args[1]) |
@@ -267,7 +267,7 b' def instance(ui, path, create):' | |||
|
267 | 267 | # No luck, try older compatibility check. |
|
268 | 268 | inst.between([(nullid, nullid)]) |
|
269 | 269 | return inst |
|
270 |
except error.RepoError |
|
|
270 | except error.RepoError as httpexception: | |
|
271 | 271 | try: |
|
272 | 272 | r = statichttprepo.instance(ui, "static-" + path, create) |
|
273 | 273 | ui.note('(falling back to static-http)\n') |
@@ -251,7 +251,7 b' class KeepAliveHandler(object):' | |||
|
251 | 251 | self._cm.add(host, h, 0) |
|
252 | 252 | self._start_transaction(h, req) |
|
253 | 253 | r = h.getresponse() |
|
254 |
except (socket.error, httplib.HTTPException) |
|
|
254 | except (socket.error, httplib.HTTPException) as err: | |
|
255 | 255 | raise urllib2.URLError(err) |
|
256 | 256 | |
|
257 | 257 | # if not a persistent connection, don't try to reuse it |
@@ -343,7 +343,7 b' class KeepAliveHandler(object):' | |||
|
343 | 343 | h.putheader('Content-length', '%d' % len(data)) |
|
344 | 344 | else: |
|
345 | 345 | h.putrequest('GET', req.get_selector(), **skipheaders) |
|
346 |
except (socket.error) |
|
|
346 | except (socket.error) as err: | |
|
347 | 347 | raise urllib2.URLError(err) |
|
348 | 348 | for k, v in headers.items(): |
|
349 | 349 | h.putheader(k, v) |
@@ -550,7 +550,7 b' def safesend(self, str):' | |||
|
550 | 550 | data = read(blocksize) |
|
551 | 551 | else: |
|
552 | 552 | self.sock.sendall(str) |
|
553 |
except socket.error |
|
|
553 | except socket.error as v: | |
|
554 | 554 | reraise = True |
|
555 | 555 | if v[0] == errno.EPIPE: # Broken pipe |
|
556 | 556 | if self._HTTPConnection__state == httplib._CS_REQ_SENT: |
@@ -605,7 +605,7 b' def error_handler(url):' | |||
|
605 | 605 | status, reason = fo.status, fo.reason |
|
606 | 606 | except AttributeError: |
|
607 | 607 | status, reason = None, None |
|
608 |
except IOError |
|
|
608 | except IOError as e: | |
|
609 | 609 | print " EXCEPTION: %s" % e |
|
610 | 610 | raise |
|
611 | 611 | else: |
@@ -135,7 +135,7 b' class localpeer(peer.peerrepository):' | |||
|
135 | 135 | stream = util.chunkbuffer(ret.getchunks()) |
|
136 | 136 | ret = bundle2.getunbundler(self.ui, stream) |
|
137 | 137 | return ret |
|
138 |
except Exception |
|
|
138 | except Exception as exc: | |
|
139 | 139 | # If the exception contains output salvaged from a bundle2 |
|
140 | 140 | # reply, we need to make sure it is printed before continuing |
|
141 | 141 | # to fail. So we build a bundle2 with such output and consume |
@@ -152,7 +152,7 b' class localpeer(peer.peerrepository):' | |||
|
152 | 152 | b = bundle2.getunbundler(self.ui, stream) |
|
153 | 153 | bundle2.processbundle(self._repo, b) |
|
154 | 154 | raise |
|
155 |
except error.PushRaced |
|
|
155 | except error.PushRaced as exc: | |
|
156 | 156 | raise error.ResponseError(_('push failed:'), str(exc)) |
|
157 | 157 | |
|
158 | 158 | def lock(self): |
@@ -272,7 +272,7 b' class localrepository(object):' | |||
|
272 | 272 | try: |
|
273 | 273 | self.requirements = scmutil.readrequires( |
|
274 | 274 | self.vfs, self.supported) |
|
275 |
except IOError |
|
|
275 | except IOError as inst: | |
|
276 | 276 | if inst.errno != errno.ENOENT: |
|
277 | 277 | raise |
|
278 | 278 | |
@@ -285,7 +285,7 b' class localrepository(object):' | |||
|
285 | 285 | raise error.RepoError( |
|
286 | 286 | _('.hg/sharedpath points to nonexistent directory %s') % s) |
|
287 | 287 | self.sharedpath = s |
|
288 |
except IOError |
|
|
288 | except IOError as inst: | |
|
289 | 289 | if inst.errno != errno.ENOENT: |
|
290 | 290 | raise |
|
291 | 291 | |
@@ -578,7 +578,7 b' class localrepository(object):' | |||
|
578 | 578 | |
|
579 | 579 | try: |
|
580 | 580 | fp = self.wfile('.hgtags', 'rb+') |
|
581 |
except IOError |
|
|
581 | except IOError as e: | |
|
582 | 582 | if e.errno != errno.ENOENT: |
|
583 | 583 | raise |
|
584 | 584 | fp = self.wfile('.hgtags', 'ab') |
@@ -1189,7 +1189,7 b' class localrepository(object):' | |||
|
1189 | 1189 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc): |
|
1190 | 1190 | try: |
|
1191 | 1191 | l = lockmod.lock(vfs, lockname, 0, releasefn, desc=desc) |
|
1192 |
except error.LockHeld |
|
|
1192 | except error.LockHeld as inst: | |
|
1193 | 1193 | if not wait: |
|
1194 | 1194 | raise |
|
1195 | 1195 | self.ui.warn(_("waiting for lock on %s held by %r\n") % |
@@ -1570,10 +1570,10 b' class localrepository(object):' | |||
|
1570 | 1570 | m[f] = self._filecommit(fctx, m1, m2, linkrev, |
|
1571 | 1571 | trp, changed) |
|
1572 | 1572 | m.setflag(f, fctx.flags()) |
|
1573 |
except OSError |
|
|
1573 | except OSError as inst: | |
|
1574 | 1574 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
1575 | 1575 | raise |
|
1576 |
except IOError |
|
|
1576 | except IOError as inst: | |
|
1577 | 1577 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
1578 | 1578 | if error or errcode and errcode != errno.ENOENT: |
|
1579 | 1579 | self.ui.warn(_("trouble committing %s!\n") % f) |
@@ -1888,7 +1888,7 b' class localrepository(object):' | |||
|
1888 | 1888 | hookargs['old'] = old |
|
1889 | 1889 | hookargs['new'] = new |
|
1890 | 1890 | self.hook('prepushkey', throw=True, **hookargs) |
|
1891 |
except error.HookAbort |
|
|
1891 | except error.HookAbort as exc: | |
|
1892 | 1892 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) |
|
1893 | 1893 | if exc.hint: |
|
1894 | 1894 | self.ui.write_err(_("(%s)\n") % exc.hint) |
@@ -58,7 +58,7 b' class lock(object):' | |||
|
58 | 58 | try: |
|
59 | 59 | self.trylock() |
|
60 | 60 | return self.timeout - timeout |
|
61 |
except error.LockHeld |
|
|
61 | except error.LockHeld as inst: | |
|
62 | 62 | if timeout != 0: |
|
63 | 63 | time.sleep(1) |
|
64 | 64 | if timeout > 0: |
@@ -78,7 +78,7 b' class lock(object):' | |||
|
78 | 78 | try: |
|
79 | 79 | self.vfs.makelock(lockname, self.f) |
|
80 | 80 | self.held = 1 |
|
81 |
except (OSError, IOError) |
|
|
81 | except (OSError, IOError) as why: | |
|
82 | 82 | if why.errno == errno.EEXIST: |
|
83 | 83 | locker = self.testlock() |
|
84 | 84 | if locker is not None: |
@@ -102,7 +102,7 b' class lock(object):' | |||
|
102 | 102 | """ |
|
103 | 103 | try: |
|
104 | 104 | locker = self.vfs.readlock(self.f) |
|
105 |
except (OSError, IOError) |
|
|
105 | except (OSError, IOError) as why: | |
|
106 | 106 | if why.errno == errno.ENOENT: |
|
107 | 107 | return None |
|
108 | 108 | raise |
@@ -138,16 +138,16 b' def _smtp(ui):' | |||
|
138 | 138 | (username)) |
|
139 | 139 | try: |
|
140 | 140 | s.login(username, password) |
|
141 |
except smtplib.SMTPException |
|
|
141 | except smtplib.SMTPException as inst: | |
|
142 | 142 | raise util.Abort(inst) |
|
143 | 143 | |
|
144 | 144 | def send(sender, recipients, msg): |
|
145 | 145 | try: |
|
146 | 146 | return s.sendmail(sender, recipients, msg) |
|
147 |
except smtplib.SMTPRecipientsRefused |
|
|
147 | except smtplib.SMTPRecipientsRefused as inst: | |
|
148 | 148 | recipients = [r[1] for r in inst.recipients.values()] |
|
149 | 149 | raise util.Abort('\n' + '\n'.join(recipients)) |
|
150 |
except smtplib.SMTPException |
|
|
150 | except smtplib.SMTPException as inst: | |
|
151 | 151 | raise util.Abort(inst) |
|
152 | 152 | |
|
153 | 153 | return send |
@@ -293,9 +293,9 b' class match(object):' | |||
|
293 | 293 | for k, p, source in self._normalize(includepats, default, |
|
294 | 294 | root, cwd, auditor): |
|
295 | 295 | kindpats.append((k, p, source or pat)) |
|
296 |
except util.Abort |
|
|
296 | except util.Abort as inst: | |
|
297 | 297 | raise util.Abort('%s: %s' % (pat, inst[0])) |
|
298 |
except IOError |
|
|
298 | except IOError as inst: | |
|
299 | 299 | if self._warn: |
|
300 | 300 | self._warn(_("skipping unreadable pattern file " |
|
301 | 301 | "'%s': %s\n") % (pat, inst.strerror)) |
@@ -145,7 +145,7 b' class mergestate(object):' | |||
|
145 | 145 | else: |
|
146 | 146 | records.append(('F', l[:-1])) |
|
147 | 147 | f.close() |
|
148 |
except IOError |
|
|
148 | except IOError as err: | |
|
149 | 149 | if err.errno != errno.ENOENT: |
|
150 | 150 | raise |
|
151 | 151 | return records |
@@ -170,7 +170,7 b' class mergestate(object):' | |||
|
170 | 170 | off += length |
|
171 | 171 | records.append((rtype, record)) |
|
172 | 172 | f.close() |
|
173 |
except IOError |
|
|
173 | except IOError as err: | |
|
174 | 174 | if err.errno != errno.ENOENT: |
|
175 | 175 | raise |
|
176 | 176 | return records |
@@ -660,7 +660,7 b' def batchremove(repo, actions):' | |||
|
660 | 660 | audit(f) |
|
661 | 661 | try: |
|
662 | 662 | unlink(wjoin(f), ignoremissing=True) |
|
663 |
except OSError |
|
|
663 | except OSError as inst: | |
|
664 | 664 | repo.ui.warn(_("update failed to remove %s: %s!\n") % |
|
665 | 665 | (f, inst.strerror)) |
|
666 | 666 | if i == 100: |
@@ -431,12 +431,12 b' class fsbackend(abstractbackend):' | |||
|
431 | 431 | isexec = False |
|
432 | 432 | try: |
|
433 | 433 | isexec = self.opener.lstat(fname).st_mode & 0o100 != 0 |
|
434 |
except OSError |
|
|
434 | except OSError as e: | |
|
435 | 435 | if e.errno != errno.ENOENT: |
|
436 | 436 | raise |
|
437 | 437 | try: |
|
438 | 438 | return (self.opener.read(fname), (False, isexec)) |
|
439 |
except IOError |
|
|
439 | except IOError as e: | |
|
440 | 440 | if e.errno != errno.ENOENT: |
|
441 | 441 | raise |
|
442 | 442 | return None, None |
@@ -1363,7 +1363,7 b' class binhunk(object):' | |||
|
1363 | 1363 | l = ord(l) - ord('a') + 27 |
|
1364 | 1364 | try: |
|
1365 | 1365 | dec.append(base85.b85decode(line[1:])[:l]) |
|
1366 |
except ValueError |
|
|
1366 | except ValueError as e: | |
|
1367 | 1367 | raise PatchError(_('could not decode "%s" binary patch: %s') |
|
1368 | 1368 | % (self._fname, str(e))) |
|
1369 | 1369 | line = getline(lr, self.hunk) |
@@ -1938,7 +1938,7 b' def _applydiff(ui, fp, patcher, backend,' | |||
|
1938 | 1938 | try: |
|
1939 | 1939 | current_file = patcher(ui, gp, backend, store, |
|
1940 | 1940 | eolmode=eolmode) |
|
1941 |
except PatchError |
|
|
1941 | except PatchError as inst: | |
|
1942 | 1942 | ui.warn(str(inst) + '\n') |
|
1943 | 1943 | current_file = None |
|
1944 | 1944 | rejects += 1 |
@@ -76,7 +76,7 b' class pathauditor(object):' | |||
|
76 | 76 | curpath = os.path.join(self.root, prefix) |
|
77 | 77 | try: |
|
78 | 78 | st = os.lstat(curpath) |
|
79 |
except OSError |
|
|
79 | except OSError as err: | |
|
80 | 80 | # EINVAL can be raised as invalid path syntax under win32. |
|
81 | 81 | # They must be ignored for patterns can be checked too. |
|
82 | 82 | if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL): |
@@ -129,7 +129,7 b' def _readroots(repo, phasedefaults=None)' | |||
|
129 | 129 | if 'HG_PENDING' in os.environ: |
|
130 | 130 | try: |
|
131 | 131 | f = repo.svfs('phaseroots.pending') |
|
132 |
except IOError |
|
|
132 | except IOError as inst: | |
|
133 | 133 | if inst.errno != errno.ENOENT: |
|
134 | 134 | raise |
|
135 | 135 | if f is None: |
@@ -140,7 +140,7 b' def _readroots(repo, phasedefaults=None)' | |||
|
140 | 140 | roots[int(phase)].add(bin(nh)) |
|
141 | 141 | finally: |
|
142 | 142 | f.close() |
|
143 |
except IOError |
|
|
143 | except IOError as inst: | |
|
144 | 144 | if inst.errno != errno.ENOENT: |
|
145 | 145 | raise |
|
146 | 146 | if phasedefaults: |
@@ -115,7 +115,7 b' def copymode(src, dst, mode=None):' | |||
|
115 | 115 | using umask.''' |
|
116 | 116 | try: |
|
117 | 117 | st_mode = os.lstat(src).st_mode & 0o777 |
|
118 |
except OSError |
|
|
118 | except OSError as inst: | |
|
119 | 119 | if inst.errno != errno.ENOENT: |
|
120 | 120 | raise |
|
121 | 121 | st_mode = mode |
@@ -166,7 +166,7 b' def checklink(path):' | |||
|
166 | 166 | fd.close() |
|
167 | 167 | except AttributeError: |
|
168 | 168 | return False |
|
169 |
except OSError |
|
|
169 | except OSError as inst: | |
|
170 | 170 | # sshfs might report failure while successfully creating the link |
|
171 | 171 | if inst[0] == errno.EIO and os.path.exists(name): |
|
172 | 172 | os.unlink(name) |
@@ -355,7 +355,7 b' def testpid(pid):' | |||
|
355 | 355 | try: |
|
356 | 356 | os.kill(pid, 0) |
|
357 | 357 | return True |
|
358 |
except OSError |
|
|
358 | except OSError as inst: | |
|
359 | 359 | return inst.errno != errno.ESRCH |
|
360 | 360 | |
|
361 | 361 | def explainexit(code): |
@@ -410,7 +410,7 b' def statfiles(files):' | |||
|
410 | 410 | st = lstat(nf) |
|
411 | 411 | if getkind(st.st_mode) not in _wantedkinds: |
|
412 | 412 | st = None |
|
413 |
except OSError |
|
|
413 | except OSError as err: | |
|
414 | 414 | if err.errno not in (errno.ENOENT, errno.ENOTDIR): |
|
415 | 415 | raise |
|
416 | 416 | st = None |
@@ -477,7 +477,7 b' def termwidth():' | |||
|
477 | 477 | pass |
|
478 | 478 | except ValueError: |
|
479 | 479 | pass |
|
480 |
except IOError |
|
|
480 | except IOError as e: | |
|
481 | 481 | if e[0] == errno.EINVAL: |
|
482 | 482 | pass |
|
483 | 483 | else: |
@@ -493,7 +493,7 b' def unlinkpath(f, ignoremissing=False):' | |||
|
493 | 493 | """unlink and remove the directory if it is empty""" |
|
494 | 494 | try: |
|
495 | 495 | os.unlink(f) |
|
496 |
except OSError |
|
|
496 | except OSError as e: | |
|
497 | 497 | if not (ignoremissing and e.errno == errno.ENOENT): |
|
498 | 498 | raise |
|
499 | 499 | # try removing directories that might now be empty |
@@ -560,7 +560,7 b' class unixdomainserver(socket.socket):' | |||
|
560 | 560 | os.unlink(self.path) |
|
561 | 561 | try: |
|
562 | 562 | self.bind(self.realpath) |
|
563 |
except socket.error |
|
|
563 | except socket.error as err: | |
|
564 | 564 | if err.args[0] == 'AF_UNIX path too long': |
|
565 | 565 | tmpdir = tempfile.mkdtemp(prefix='hg-%s-' % subsystem) |
|
566 | 566 | self.realpath = os.path.join(tmpdir, sockname) |
@@ -578,7 +578,7 b' class unixdomainserver(socket.socket):' | |||
|
578 | 578 | def okayifmissing(f, path): |
|
579 | 579 | try: |
|
580 | 580 | f(path) |
|
581 |
except OSError |
|
|
581 | except OSError as err: | |
|
582 | 582 | if err.errno != errno.ENOENT: |
|
583 | 583 | raise |
|
584 | 584 |
@@ -205,7 +205,7 b' def strip(ui, repo, nodelist, backup=Tru' | |||
|
205 | 205 | for undovfs, undofile in repo.undofiles(): |
|
206 | 206 | try: |
|
207 | 207 | undovfs.unlink(undofile) |
|
208 |
except OSError |
|
|
208 | except OSError as e: | |
|
209 | 209 | if e.errno != errno.ENOENT: |
|
210 | 210 | ui.warn(_('error removing %s: %s\n') % |
|
211 | 211 | (undovfs.join(undofile), str(e))) |
@@ -89,7 +89,7 b' def decompress(bin):' | |||
|
89 | 89 | if t == 'x': |
|
90 | 90 | try: |
|
91 | 91 | return _decompress(bin) |
|
92 |
except zlib.error |
|
|
92 | except zlib.error as e: | |
|
93 | 93 | raise RevlogError(_("revlog decompress error: %s") % str(e)) |
|
94 | 94 | if t == 'u': |
|
95 | 95 | return bin[1:] |
@@ -246,7 +246,7 b' class revlog(object):' | |||
|
246 | 246 | if len(i) > 0: |
|
247 | 247 | v = struct.unpack(versionformat, i[:4])[0] |
|
248 | 248 | self._initempty = False |
|
249 |
except IOError |
|
|
249 | except IOError as inst: | |
|
250 | 250 | if inst.errno != errno.ENOENT: |
|
251 | 251 | raise |
|
252 | 252 | |
@@ -1571,7 +1571,7 b' class revlog(object):' | |||
|
1571 | 1571 | actual = f.tell() |
|
1572 | 1572 | f.close() |
|
1573 | 1573 | dd = actual - expected |
|
1574 |
except IOError |
|
|
1574 | except IOError as inst: | |
|
1575 | 1575 | if inst.errno != errno.ENOENT: |
|
1576 | 1576 | raise |
|
1577 | 1577 | dd = 0 |
@@ -1590,7 +1590,7 b' class revlog(object):' | |||
|
1590 | 1590 | databytes += max(0, self.length(r)) |
|
1591 | 1591 | dd = 0 |
|
1592 | 1592 | di = actual - len(self) * s - databytes |
|
1593 |
except IOError |
|
|
1593 | except IOError as inst: | |
|
1594 | 1594 | if inst.errno != errno.ENOENT: |
|
1595 | 1595 | raise |
|
1596 | 1596 | di = 0 |
@@ -1019,7 +1019,7 b' def grep(repo, subset, x):' | |||
|
1019 | 1019 | try: |
|
1020 | 1020 | # i18n: "grep" is a keyword |
|
1021 | 1021 | gr = re.compile(getstring(x, _("grep requires a string"))) |
|
1022 |
except re.error |
|
|
1022 | except re.error as e: | |
|
1023 | 1023 | raise error.ParseError(_('invalid match pattern: %s') % e) |
|
1024 | 1024 | |
|
1025 | 1025 | def matches(x): |
@@ -1900,7 +1900,7 b' def _stringmatcher(pattern):' | |||
|
1900 | 1900 | pattern = pattern[3:] |
|
1901 | 1901 | try: |
|
1902 | 1902 | regex = re.compile(pattern) |
|
1903 |
except re.error |
|
|
1903 | except re.error as e: | |
|
1904 | 1904 | raise error.ParseError(_('invalid regular expression: %s') |
|
1905 | 1905 | % e) |
|
1906 | 1906 | return 're', pattern, regex.search |
@@ -2416,7 +2416,7 b' def _parsealiasdecl(decl):' | |||
|
2416 | 2416 | return (name, ('func', ('symbol', name)), args, None) |
|
2417 | 2417 | |
|
2418 | 2418 | return (decl, None, None, _("invalid format")) |
|
2419 |
except error.ParseError |
|
|
2419 | except error.ParseError as inst: | |
|
2420 | 2420 | return (decl, None, None, parseerrordetail(inst)) |
|
2421 | 2421 | |
|
2422 | 2422 | def _parsealiasdefn(defn, args): |
@@ -2505,7 +2505,7 b' class revsetalias(object):' | |||
|
2505 | 2505 | self.replacement = _parsealiasdefn(value, self.args) |
|
2506 | 2506 | # Check for placeholder injection |
|
2507 | 2507 | _checkaliasarg(self.replacement, self.args) |
|
2508 |
except error.ParseError |
|
|
2508 | except error.ParseError as inst: | |
|
2509 | 2509 | self.error = _('failed to parse the definition of revset alias' |
|
2510 | 2510 | ' "%s": %s') % (self.name, parseerrordetail(inst)) |
|
2511 | 2511 |
@@ -222,7 +222,7 b' class abstractvfs(object):' | |||
|
222 | 222 | '''gracefully return an empty string for missing files''' |
|
223 | 223 | try: |
|
224 | 224 | return self.read(path) |
|
225 |
except IOError |
|
|
225 | except IOError as inst: | |
|
226 | 226 | if inst.errno != errno.ENOENT: |
|
227 | 227 | raise |
|
228 | 228 | return "" |
@@ -231,7 +231,7 b' class abstractvfs(object):' | |||
|
231 | 231 | '''gracefully return an empty array for missing files''' |
|
232 | 232 | try: |
|
233 | 233 | return self.readlines(path, mode=mode) |
|
234 |
except IOError |
|
|
234 | except IOError as inst: | |
|
235 | 235 | if inst.errno != errno.ENOENT: |
|
236 | 236 | raise |
|
237 | 237 | return [] |
@@ -491,7 +491,7 b' class vfs(abstractvfs):' | |||
|
491 | 491 | if nlink < 1: |
|
492 | 492 | nlink = 2 # force mktempcopy (issue1922) |
|
493 | 493 | fd.close() |
|
494 |
except (OSError, IOError) |
|
|
494 | except (OSError, IOError) as e: | |
|
495 | 495 | if e.errno != errno.ENOENT: |
|
496 | 496 | raise |
|
497 | 497 | nlink = 0 |
@@ -519,7 +519,7 b' class vfs(abstractvfs):' | |||
|
519 | 519 | if self._cansymlink: |
|
520 | 520 | try: |
|
521 | 521 | os.symlink(src, linkname) |
|
522 |
except OSError |
|
|
522 | except OSError as err: | |
|
523 | 523 | raise OSError(err.errno, _('could not symlink to %r: %s') % |
|
524 | 524 | (src, err.strerror), linkname) |
|
525 | 525 | else: |
@@ -1058,7 +1058,7 b' class filecachesubentry(object):' | |||
|
1058 | 1058 | def stat(path): |
|
1059 | 1059 | try: |
|
1060 | 1060 | return util.cachestat(path) |
|
1061 |
except OSError |
|
|
1061 | except OSError as e: | |
|
1062 | 1062 | if e.errno != errno.ENOENT: |
|
1063 | 1063 | raise |
|
1064 | 1064 |
@@ -33,10 +33,10 b' class httprangereader(object):' | |||
|
33 | 33 | f = self.opener.open(req) |
|
34 | 34 | data = f.read() |
|
35 | 35 | code = f.code |
|
36 |
except urllib2.HTTPError |
|
|
36 | except urllib2.HTTPError as inst: | |
|
37 | 37 | num = inst.code == 404 and errno.ENOENT or None |
|
38 | 38 | raise IOError(num, inst) |
|
39 |
except urllib2.URLError |
|
|
39 | except urllib2.URLError as inst: | |
|
40 | 40 | raise IOError(None, inst.reason[1]) |
|
41 | 41 | |
|
42 | 42 | if code == 200: |
@@ -106,7 +106,7 b' class statichttprepository(localrepo.loc' | |||
|
106 | 106 | |
|
107 | 107 | try: |
|
108 | 108 | requirements = scmutil.readrequires(self.vfs, self.supported) |
|
109 |
except IOError |
|
|
109 | except IOError as inst: | |
|
110 | 110 | if inst.errno != errno.ENOENT: |
|
111 | 111 | raise |
|
112 | 112 | requirements = set() |
@@ -116,7 +116,7 b' class statichttprepository(localrepo.loc' | |||
|
116 | 116 | fp = self.vfs("00changelog.i") |
|
117 | 117 | fp.read(1) |
|
118 | 118 | fp.close() |
|
119 |
except IOError |
|
|
119 | except IOError as inst: | |
|
120 | 120 | if inst.errno != errno.ENOENT: |
|
121 | 121 | raise |
|
122 | 122 | # we do not care about empty old-style repositories here |
@@ -489,7 +489,7 b' class fncachestore(basicstore):' | |||
|
489 | 489 | ef = self.encode(f) |
|
490 | 490 | try: |
|
491 | 491 | yield f, ef, self.getsize(ef) |
|
492 |
except OSError |
|
|
492 | except OSError as err: | |
|
493 | 493 | if err.errno != errno.ENOENT: |
|
494 | 494 | raise |
|
495 | 495 | |
@@ -513,7 +513,7 b' class fncachestore(basicstore):' | |||
|
513 | 513 | try: |
|
514 | 514 | self.getsize(ef) |
|
515 | 515 | return True |
|
516 |
except OSError |
|
|
516 | except OSError as err: | |
|
517 | 517 | if err.errno != errno.ENOENT: |
|
518 | 518 | raise |
|
519 | 519 | # nonexistent entry |
@@ -44,10 +44,10 b' def annotatesubrepoerror(func):' | |||
|
44 | 44 | def decoratedmethod(self, *args, **kargs): |
|
45 | 45 | try: |
|
46 | 46 | res = func(self, *args, **kargs) |
|
47 |
except SubrepoAbort |
|
|
47 | except SubrepoAbort as ex: | |
|
48 | 48 | # This exception has already been handled |
|
49 | 49 | raise ex |
|
50 |
except error.Abort |
|
|
50 | except error.Abort as ex: | |
|
51 | 51 | subrepo = subrelpath(self) |
|
52 | 52 | errormsg = str(ex) + ' ' + _('(in subrepo %s)') % subrepo |
|
53 | 53 | # avoid handling this exception by raising a SubrepoAbort exception |
@@ -66,7 +66,7 b' def state(ctx, ui):' | |||
|
66 | 66 | if f in ctx: |
|
67 | 67 | try: |
|
68 | 68 | data = ctx[f].data() |
|
69 |
except IOError |
|
|
69 | except IOError as err: | |
|
70 | 70 | if err.errno != errno.ENOENT: |
|
71 | 71 | raise |
|
72 | 72 | # handle missing subrepo spec files as removed |
@@ -101,7 +101,7 b' def state(ctx, ui):' | |||
|
101 | 101 | % (util.pathto(repo.root, repo.getcwd(), |
|
102 | 102 | '.hgsubstate'), (i + 1))) |
|
103 | 103 | rev[path] = revision |
|
104 |
except IOError |
|
|
104 | except IOError as err: | |
|
105 | 105 | if err.errno != errno.ENOENT: |
|
106 | 106 | raise |
|
107 | 107 | |
@@ -116,7 +116,7 b' def state(ctx, ui):' | |||
|
116 | 116 | repl = re.sub(r'\\\\([0-9]+)', r'\\\1', repl) |
|
117 | 117 | try: |
|
118 | 118 | src = re.sub(pattern, repl, src, 1) |
|
119 |
except re.error |
|
|
119 | except re.error as e: | |
|
120 | 120 | raise util.Abort(_("bad subrepository pattern in %s: %s") |
|
121 | 121 | % (p.source('subpaths', pattern), e)) |
|
122 | 122 | return src |
@@ -734,7 +734,7 b' class hgsubrepo(abstractsubrepo):' | |||
|
734 | 734 | ctx1 = self._repo[rev1] |
|
735 | 735 | ctx2 = self._repo[rev2] |
|
736 | 736 | return self._repo.status(ctx1, ctx2, **opts) |
|
737 |
except error.RepoLookupError |
|
|
737 | except error.RepoLookupError as inst: | |
|
738 | 738 | self.ui.warn(_('warning: error "%s" in subrepository "%s"\n') |
|
739 | 739 | % (inst, subrelpath(self))) |
|
740 | 740 | return scmutil.status([], [], [], [], [], [], []) |
@@ -751,7 +751,7 b' class hgsubrepo(abstractsubrepo):' | |||
|
751 | 751 | node1, node2, match, |
|
752 | 752 | prefix=posixpath.join(prefix, self._path), |
|
753 | 753 | listsubrepos=True, **opts) |
|
754 |
except error.RepoLookupError |
|
|
754 | except error.RepoLookupError as inst: | |
|
755 | 755 | self.ui.warn(_('warning: error "%s" in subrepository "%s"\n') |
|
756 | 756 | % (inst, subrelpath(self))) |
|
757 | 757 | |
@@ -1280,7 +1280,7 b' class gitsubrepo(abstractsubrepo):' | |||
|
1280 | 1280 | try: |
|
1281 | 1281 | self._gitexecutable = 'git' |
|
1282 | 1282 | out, err = self._gitnodir(['--version']) |
|
1283 |
except OSError |
|
|
1283 | except OSError as e: | |
|
1284 | 1284 | if e.errno != 2 or os.name != 'nt': |
|
1285 | 1285 | raise |
|
1286 | 1286 | self._gitexecutable = 'git.cmd' |
@@ -120,7 +120,7 b' def readlocaltags(ui, repo, alltags, tag' | |||
|
120 | 120 | '''Read local tags in repo. Update alltags and tagtypes.''' |
|
121 | 121 | try: |
|
122 | 122 | data = repo.vfs.read("localtags") |
|
123 |
except IOError |
|
|
123 | except IOError as inst: | |
|
124 | 124 | if inst.errno != errno.ENOENT: |
|
125 | 125 | raise |
|
126 | 126 | return |
@@ -545,7 +545,7 b' class hgtagsfnodescache(object):' | |||
|
545 | 545 | self._dirtyoffset = None |
|
546 | 546 | finally: |
|
547 | 547 | f.close() |
|
548 |
except (IOError, OSError) |
|
|
548 | except (IOError, OSError) as inst: | |
|
549 | 549 | repo.ui.log('tagscache', |
|
550 | 550 | "couldn't write %s: %s\n" % ( |
|
551 | 551 | _fnodescachefile, inst)) |
@@ -770,7 +770,7 b' class templater(object):' | |||
|
770 | 770 | if val[0] in "'\"": |
|
771 | 771 | try: |
|
772 | 772 | self.cache[key] = unquotestring(val) |
|
773 |
except SyntaxError |
|
|
773 | except SyntaxError as inst: | |
|
774 | 774 | raise SyntaxError('%s: %s' % |
|
775 | 775 | (conf.source('', key), inst.args[0])) |
|
776 | 776 | else: |
@@ -787,10 +787,10 b' class templater(object):' | |||
|
787 | 787 | if t not in self.cache: |
|
788 | 788 | try: |
|
789 | 789 | self.cache[t] = util.readfile(self.map[t][1]) |
|
790 |
except KeyError |
|
|
790 | except KeyError as inst: | |
|
791 | 791 | raise TemplateNotFound(_('"%s" not in template map') % |
|
792 | 792 | inst.args[0]) |
|
793 |
except IOError |
|
|
793 | except IOError as inst: | |
|
794 | 794 | raise IOError(inst.args[0], _('template file %s: %s') % |
|
795 | 795 | (self.map[t][1], inst.args[1])) |
|
796 | 796 | return self.cache[t] |
@@ -39,7 +39,7 b' def _playback(journal, report, opener, v' | |||
|
39 | 39 | else: |
|
40 | 40 | try: |
|
41 | 41 | opener.unlink(f) |
|
42 |
except (IOError, OSError) |
|
|
42 | except (IOError, OSError) as inst: | |
|
43 | 43 | if inst.errno != errno.ENOENT: |
|
44 | 44 | raise |
|
45 | 45 | |
@@ -62,10 +62,10 b' def _playback(journal, report, opener, v' | |||
|
62 | 62 | target = f or b |
|
63 | 63 | try: |
|
64 | 64 | vfs.unlink(target) |
|
65 |
except (IOError, OSError) |
|
|
65 | except (IOError, OSError) as inst: | |
|
66 | 66 | if inst.errno != errno.ENOENT: |
|
67 | 67 | raise |
|
68 |
except (IOError, OSError, util.Abort) |
|
|
68 | except (IOError, OSError, util.Abort) as inst: | |
|
69 | 69 | if not c: |
|
70 | 70 | raise |
|
71 | 71 | |
@@ -77,7 +77,7 b' def _playback(journal, report, opener, v' | |||
|
77 | 77 | for f in backupfiles: |
|
78 | 78 | if opener.exists(f): |
|
79 | 79 | opener.unlink(f) |
|
80 |
except (IOError, OSError, util.Abort) |
|
|
80 | except (IOError, OSError, util.Abort) as inst: | |
|
81 | 81 | # only pure backup file remains, it is sage to ignore any error |
|
82 | 82 | pass |
|
83 | 83 | |
@@ -405,7 +405,7 b' class transaction(object):' | |||
|
405 | 405 | if not f and b and vfs.exists(b): |
|
406 | 406 | try: |
|
407 | 407 | vfs.unlink(b) |
|
408 |
except (IOError, OSError, util.Abort) |
|
|
408 | except (IOError, OSError, util.Abort) as inst: | |
|
409 | 409 | if not c: |
|
410 | 410 | raise |
|
411 | 411 | # Abort may be raise by read only opener |
@@ -428,7 +428,7 b' class transaction(object):' | |||
|
428 | 428 | if b and vfs.exists(b): |
|
429 | 429 | try: |
|
430 | 430 | vfs.unlink(b) |
|
431 |
except (IOError, OSError, util.Abort) |
|
|
431 | except (IOError, OSError, util.Abort) as inst: | |
|
432 | 432 | if not c: |
|
433 | 433 | raise |
|
434 | 434 | # Abort may be raise by read only opener |
@@ -153,7 +153,7 b' class ui(object):' | |||
|
153 | 153 | try: |
|
154 | 154 | cfg.read(filename, fp, sections=sections, remap=remap) |
|
155 | 155 | fp.close() |
|
156 |
except error.ConfigError |
|
|
156 | except error.ConfigError as inst: | |
|
157 | 157 | if trusted: |
|
158 | 158 | raise |
|
159 | 159 | self.warn(_("ignored: %s\n") % str(inst)) |
@@ -605,7 +605,7 b' class ui(object):' | |||
|
605 | 605 | # including stdout. |
|
606 | 606 | if not getattr(self.ferr, 'closed', False): |
|
607 | 607 | self.ferr.flush() |
|
608 |
except IOError |
|
|
608 | except IOError as inst: | |
|
609 | 609 | if inst.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): |
|
610 | 610 | raise |
|
611 | 611 |
@@ -159,7 +159,7 b' if has_https:' | |||
|
159 | 159 | sock.connect(sa) |
|
160 | 160 | return sock |
|
161 | 161 | |
|
162 |
except socket.error |
|
|
162 | except socket.error as msg: | |
|
163 | 163 | if sock is not None: |
|
164 | 164 | sock.close() |
|
165 | 165 | |
@@ -411,7 +411,7 b' class httpdigestauthhandler(urllib2.HTTP' | |||
|
411 | 411 | try: |
|
412 | 412 | return urllib2.HTTPDigestAuthHandler.http_error_auth_reqed( |
|
413 | 413 | self, auth_header, host, req, headers) |
|
414 |
except ValueError |
|
|
414 | except ValueError as inst: | |
|
415 | 415 | arg = inst.args[0] |
|
416 | 416 | if arg.startswith("AbstractDigestAuthHandler doesn't know "): |
|
417 | 417 | return |
@@ -816,7 +816,7 b' def copyfile(src, dest, hardlink=False):' | |||
|
816 | 816 | try: |
|
817 | 817 | shutil.copyfile(src, dest) |
|
818 | 818 | shutil.copymode(src, dest) |
|
819 |
except shutil.Error |
|
|
819 | except shutil.Error as inst: | |
|
820 | 820 | raise Abort(str(inst)) |
|
821 | 821 | |
|
822 | 822 | def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): |
@@ -915,7 +915,7 b' else:' | |||
|
915 | 915 | def makelock(info, pathname): |
|
916 | 916 | try: |
|
917 | 917 | return os.symlink(info, pathname) |
|
918 |
except OSError |
|
|
918 | except OSError as why: | |
|
919 | 919 | if why.errno == errno.EEXIST: |
|
920 | 920 | raise |
|
921 | 921 | except AttributeError: # no symlink in os |
@@ -928,7 +928,7 b' def makelock(info, pathname):' | |||
|
928 | 928 | def readlock(pathname): |
|
929 | 929 | try: |
|
930 | 930 | return os.readlink(pathname) |
|
931 |
except OSError |
|
|
931 | except OSError as why: | |
|
932 | 932 | if why.errno not in (errno.EINVAL, errno.ENOSYS): |
|
933 | 933 | raise |
|
934 | 934 | except AttributeError: # no symlink in os |
@@ -1145,7 +1145,7 b' def mktempcopy(name, emptyok=False, crea' | |||
|
1145 | 1145 | try: |
|
1146 | 1146 | try: |
|
1147 | 1147 | ifp = posixfile(name, "rb") |
|
1148 |
except IOError |
|
|
1148 | except IOError as inst: | |
|
1149 | 1149 | if inst.errno == errno.ENOENT: |
|
1150 | 1150 | return temp |
|
1151 | 1151 | if not getattr(inst, 'filename', None): |
@@ -1204,7 +1204,7 b' def makedirs(name, mode=None, notindexed' | |||
|
1204 | 1204 | """recursive directory creation with parent mode inheritance""" |
|
1205 | 1205 | try: |
|
1206 | 1206 | makedir(name, notindexed) |
|
1207 |
except OSError |
|
|
1207 | except OSError as err: | |
|
1208 | 1208 | if err.errno == errno.EEXIST: |
|
1209 | 1209 | return |
|
1210 | 1210 | if err.errno != errno.ENOENT or not name: |
@@ -1231,7 +1231,7 b' def ensuredirs(name, mode=None, notindex' | |||
|
1231 | 1231 | ensuredirs(parent, mode, notindexed) |
|
1232 | 1232 | try: |
|
1233 | 1233 | makedir(name, notindexed) |
|
1234 |
except OSError |
|
|
1234 | except OSError as err: | |
|
1235 | 1235 | if err.errno == errno.EEXIST and os.path.isdir(name): |
|
1236 | 1236 | # someone else seems to have won a directory creation race |
|
1237 | 1237 | return |
@@ -108,7 +108,7 b' def _verify(repo):' | |||
|
108 | 108 | if p2 not in seen and p2 != nullid: |
|
109 | 109 | err(lr, _("unknown parent 2 %s of %s") % |
|
110 | 110 | (short(p2), short(node)), f) |
|
111 |
except Exception |
|
|
111 | except Exception as inst: | |
|
112 | 112 | exc(lr, _("checking parents of %s") % short(node), inst, f) |
|
113 | 113 | |
|
114 | 114 | if node in seen: |
@@ -144,7 +144,7 b' def _verify(repo):' | |||
|
144 | 144 | refersmf = True |
|
145 | 145 | for f in changes[3]: |
|
146 | 146 | filelinkrevs.setdefault(_normpath(f), []).append(i) |
|
147 |
except Exception |
|
|
147 | except Exception as inst: | |
|
148 | 148 | refersmf = True |
|
149 | 149 | exc(i, _("unpacking changeset %s") % short(n), inst) |
|
150 | 150 | ui.progress(_('checking'), None) |
@@ -171,7 +171,7 b' def _verify(repo):' | |||
|
171 | 171 | err(lr, _("file without name in manifest")) |
|
172 | 172 | elif f != "/dev/null": # ignore this in very old repos |
|
173 | 173 | filenodes.setdefault(_normpath(f), {}).setdefault(fn, lr) |
|
174 |
except Exception |
|
|
174 | except Exception as inst: | |
|
175 | 175 | exc(lr, _("reading manifest delta %s") % short(n), inst) |
|
176 | 176 | ui.progress(_('checking'), None) |
|
177 | 177 | |
@@ -237,7 +237,7 b' def _verify(repo):' | |||
|
237 | 237 | |
|
238 | 238 | try: |
|
239 | 239 | fl = repo.file(f) |
|
240 |
except error.RevlogError |
|
|
240 | except error.RevlogError as e: | |
|
241 | 241 | err(lr, _("broken revlog! (%s)") % e, f) |
|
242 | 242 | continue |
|
243 | 243 | |
@@ -272,7 +272,7 b' def _verify(repo):' | |||
|
272 | 272 | except error.CensoredNodeError: |
|
273 | 273 | if ui.config("censor", "policy", "abort") == "abort": |
|
274 | 274 | err(lr, _("censored file data"), f) |
|
275 |
except Exception |
|
|
275 | except Exception as inst: | |
|
276 | 276 | exc(lr, _("unpacking %s") % short(n), inst, f) |
|
277 | 277 | |
|
278 | 278 | # check renames |
@@ -298,7 +298,7 b' def _verify(repo):' | |||
|
298 | 298 | % (f, lr, rp[0], short(rp[1]))) |
|
299 | 299 | else: |
|
300 | 300 | fl2.rev(rp[1]) |
|
301 |
except Exception |
|
|
301 | except Exception as inst: | |
|
302 | 302 | exc(lr, _("checking rename of %s") % short(n), inst, f) |
|
303 | 303 | |
|
304 | 304 | # cross-check |
@@ -467,7 +467,7 b' def unlink(f):' | |||
|
467 | 467 | try: |
|
468 | 468 | os.rename(f, temp) # raises OSError EEXIST if temp exists |
|
469 | 469 | break |
|
470 |
except OSError |
|
|
470 | except OSError as e: | |
|
471 | 471 | if e.errno != errno.EEXIST: |
|
472 | 472 | raise |
|
473 | 473 | else: |
@@ -38,7 +38,7 b" def posixfile(name, mode='r', buffering=" | |||
|
38 | 38 | fp.seek(0, os.SEEK_END) |
|
39 | 39 | |
|
40 | 40 | return fp |
|
41 |
except WindowsError |
|
|
41 | except WindowsError as err: | |
|
42 | 42 | # convert to a friendlier exception |
|
43 | 43 | raise IOError(err.errno, '%s: %s' % (name, err.strerror)) |
|
44 | 44 | |
@@ -69,7 +69,7 b' class winstdout(object):' | |||
|
69 | 69 | end = start + limit |
|
70 | 70 | self.fp.write(s[start:end]) |
|
71 | 71 | start = end |
|
72 |
except IOError |
|
|
72 | except IOError as inst: | |
|
73 | 73 | if inst.errno != 0: |
|
74 | 74 | raise |
|
75 | 75 | self.close() |
@@ -78,7 +78,7 b' class winstdout(object):' | |||
|
78 | 78 | def flush(self): |
|
79 | 79 | try: |
|
80 | 80 | return self.fp.flush() |
|
81 |
except IOError |
|
|
81 | except IOError as inst: | |
|
82 | 82 | if inst.errno != errno.EINVAL: |
|
83 | 83 | raise |
|
84 | 84 | self.close() |
@@ -259,7 +259,7 b' def statfiles(files):' | |||
|
259 | 259 | dmap = dict([(normcase(n), s) |
|
260 | 260 | for n, k, s in osutil.listdir(dir, True) |
|
261 | 261 | if getkind(s.st_mode) in _wantedkinds]) |
|
262 |
except OSError |
|
|
262 | except OSError as err: | |
|
263 | 263 | # Python >= 2.5 returns ENOENT and adds winerror field |
|
264 | 264 | # EINVAL is raised if dir is not a directory. |
|
265 | 265 | if err.errno not in (errno.ENOENT, errno.EINVAL, |
@@ -303,7 +303,7 b' def unlinkpath(f, ignoremissing=False):' | |||
|
303 | 303 | """unlink and remove the directory if it is empty""" |
|
304 | 304 | try: |
|
305 | 305 | unlink(f) |
|
306 |
except OSError |
|
|
306 | except OSError as e: | |
|
307 | 307 | if not (ignoremissing and e.errno == errno.ENOENT): |
|
308 | 308 | raise |
|
309 | 309 | # try removing directories that might now be empty |
@@ -316,7 +316,7 b' def rename(src, dst):' | |||
|
316 | 316 | '''atomically rename file src to dst, replacing dst if it exists''' |
|
317 | 317 | try: |
|
318 | 318 | os.rename(src, dst) |
|
319 |
except OSError |
|
|
319 | except OSError as e: | |
|
320 | 320 | if e.errno != errno.EEXIST: |
|
321 | 321 | raise |
|
322 | 322 | unlink(dst) |
@@ -705,7 +705,7 b' def lookup(repo, proto, key):' | |||
|
705 | 705 | c = repo[k] |
|
706 | 706 | r = c.hex() |
|
707 | 707 | success = 1 |
|
708 |
except Exception |
|
|
708 | except Exception as inst: | |
|
709 | 709 | r = str(inst) |
|
710 | 710 | success = 0 |
|
711 | 711 | return "%s %s\n" % (success, r) |
@@ -800,7 +800,7 b' def unbundle(repo, proto, heads):' | |||
|
800 | 800 | fp.close() |
|
801 | 801 | os.unlink(tempname) |
|
802 | 802 | |
|
803 |
except (error.BundleValueError, util.Abort, error.PushRaced) |
|
|
803 | except (error.BundleValueError, util.Abort, error.PushRaced) as exc: | |
|
804 | 804 | # handle non-bundle2 case first |
|
805 | 805 | if not getattr(exc, 'duringunbundle2', False): |
|
806 | 806 | try: |
@@ -821,7 +821,7 b' def unbundle(repo, proto, heads):' | |||
|
821 | 821 | try: |
|
822 | 822 | try: |
|
823 | 823 | raise |
|
824 |
except error.PushkeyFailed |
|
|
824 | except error.PushkeyFailed as exc: | |
|
825 | 825 | # check client caps |
|
826 | 826 | remotecaps = getattr(exc, '_replycaps', None) |
|
827 | 827 | if (remotecaps is not None |
@@ -840,19 +840,19 b' def unbundle(repo, proto, heads):' | |||
|
840 | 840 | part.addparam('old', exc.old, mandatory=False) |
|
841 | 841 | if exc.ret is not None: |
|
842 | 842 | part.addparam('ret', exc.ret, mandatory=False) |
|
843 |
except error.BundleValueError |
|
|
843 | except error.BundleValueError as exc: | |
|
844 | 844 | errpart = bundler.newpart('error:unsupportedcontent') |
|
845 | 845 | if exc.parttype is not None: |
|
846 | 846 | errpart.addparam('parttype', exc.parttype) |
|
847 | 847 | if exc.params: |
|
848 | 848 | errpart.addparam('params', '\0'.join(exc.params)) |
|
849 |
except util.Abort |
|
|
849 | except util.Abort as exc: | |
|
850 | 850 | manargs = [('message', str(exc))] |
|
851 | 851 | advargs = [] |
|
852 | 852 | if exc.hint is not None: |
|
853 | 853 | advargs.append(('hint', exc.hint)) |
|
854 | 854 | bundler.addpart(bundle2.bundlepart('error:abort', |
|
855 | 855 | manargs, advargs)) |
|
856 |
except error.PushRaced |
|
|
856 | except error.PushRaced as exc: | |
|
857 | 857 | bundler.newpart('error:pushraced', [('message', str(exc))]) |
|
858 | 858 | return streamres(bundler.getchunks()) |
@@ -101,7 +101,7 b' def _posixworker(ui, func, staticargs, a' | |||
|
101 | 101 | for p in pids: |
|
102 | 102 | try: |
|
103 | 103 | os.kill(p, signal.SIGTERM) |
|
104 |
except OSError |
|
|
104 | except OSError as err: | |
|
105 | 105 | if err.errno != errno.ESRCH: |
|
106 | 106 | raise |
|
107 | 107 | def waitforworkers(): |
@@ -23,7 +23,7 b' except ImportError:' | |||
|
23 | 23 | for filename in sys.argv[1:]: |
|
24 | 24 | try: |
|
25 | 25 | fp = open(filename, 'rb') |
|
26 |
except IOError |
|
|
26 | except IOError as msg: | |
|
27 | 27 | sys.stderr.write('%s: Can\'t open: %s\n' % (filename, msg)) |
|
28 | 28 | sys.exit(1) |
|
29 | 29 | |
@@ -34,7 +34,7 b' for filename in sys.argv[1:]:' | |||
|
34 | 34 | if not data: |
|
35 | 35 | break |
|
36 | 36 | m.update(data) |
|
37 |
except IOError |
|
|
37 | except IOError as msg: | |
|
38 | 38 | sys.stderr.write('%s: I/O error: %s\n' % (filename, msg)) |
|
39 | 39 | sys.exit(1) |
|
40 | 40 | sys.stdout.write('%s %s\n' % (m.hexdigest(), filename)) |
@@ -5,7 +5,7 b' import errno, os, sys' | |||
|
5 | 5 | for f in sys.argv[1:]: |
|
6 | 6 | try: |
|
7 | 7 | print f, '->', os.readlink(f) |
|
8 |
except OSError |
|
|
8 | except OSError as err: | |
|
9 | 9 | if err.errno != errno.EINVAL: |
|
10 | 10 | raise |
|
11 | 11 | print f, 'not a symlink' |
@@ -325,21 +325,21 b' class basemanifesttests(object):' | |||
|
325 | 325 | try: |
|
326 | 326 | self.parsemanifest(backwards) |
|
327 | 327 | self.fail('Should have raised ValueError') |
|
328 |
except ValueError |
|
|
328 | except ValueError as v: | |
|
329 | 329 | self.assertIn('Manifest lines not in sorted order.', str(v)) |
|
330 | 330 | |
|
331 | 331 | def testNoTerminalNewline(self): |
|
332 | 332 | try: |
|
333 | 333 | self.parsemanifest(A_SHORT_MANIFEST + 'wat') |
|
334 | 334 | self.fail('Should have raised ValueError') |
|
335 |
except ValueError |
|
|
335 | except ValueError as v: | |
|
336 | 336 | self.assertIn('Manifest did not end in a newline.', str(v)) |
|
337 | 337 | |
|
338 | 338 | def testNoNewLineAtAll(self): |
|
339 | 339 | try: |
|
340 | 340 | self.parsemanifest('wat') |
|
341 | 341 | self.fail('Should have raised ValueError') |
|
342 |
except ValueError |
|
|
342 | except ValueError as v: | |
|
343 | 343 | self.assertIn('Manifest did not end in a newline.', str(v)) |
|
344 | 344 | |
|
345 | 345 | def testHugeManifest(self): |
@@ -169,7 +169,7 b' print "# error handling"' | |||
|
169 | 169 | def assertraises(f, exc=util.Abort): |
|
170 | 170 | try: |
|
171 | 171 | f() |
|
172 |
except exc |
|
|
172 | except exc as inst: | |
|
173 | 173 | print 'raised', inst.__class__.__name__ |
|
174 | 174 | else: |
|
175 | 175 | print 'no exception?!' |
@@ -188,10 +188,10 b' f.close()' | |||
|
188 | 188 | |
|
189 | 189 | try: |
|
190 | 190 | testui(user='abc', group='def', silent=True) |
|
191 |
except error.ParseError |
|
|
191 | except error.ParseError as inst: | |
|
192 | 192 | print inst |
|
193 | 193 | |
|
194 | 194 | try: |
|
195 | 195 | testui(debug=True, silent=True) |
|
196 |
except error.ParseError |
|
|
196 | except error.ParseError as inst: | |
|
197 | 197 | print inst |
@@ -39,7 +39,7 b" print repr(testui.config('values', 'unkn" | |||
|
39 | 39 | print "---" |
|
40 | 40 | try: |
|
41 | 41 | print repr(testui.configbool('values', 'string')) |
|
42 |
except error.ConfigError |
|
|
42 | except error.ConfigError as inst: | |
|
43 | 43 | print inst |
|
44 | 44 | print repr(testui.configbool('values', 'bool1')) |
|
45 | 45 | print repr(testui.configbool('values', 'bool2')) |
@@ -45,7 +45,7 b' class ProxyHandler (BaseHTTPServer.BaseH' | |||
|
45 | 45 | host_port = netloc, 80 |
|
46 | 46 | print "\t" "connect to %s:%d" % host_port |
|
47 | 47 | try: soc.connect(host_port) |
|
48 |
except socket.error |
|
|
48 | except socket.error as arg: | |
|
49 | 49 | try: msg = arg[1] |
|
50 | 50 | except (IndexError, TypeError): msg = arg |
|
51 | 51 | self.send_error(404, msg) |
General Comments 0
You need to be logged in to leave comments.
Login now