##// END OF EJS Templates
cleanup: replace naked excepts with more specific ones
Brodie Rao -
r16688:cfb66829 default
parent child Browse files
Show More
@@ -26,22 +26,22 else:
26 try:
26 try:
27 import hashlib
27 import hashlib
28 sha = hashlib.sha1()
28 sha = hashlib.sha1()
29 except:
29 except ImportError:
30 try:
30 try:
31 import sha
31 import sha
32 except:
32 except ImportError:
33 raise SystemExit(
33 raise SystemExit(
34 "Couldn't import standard hashlib (incomplete Python install).")
34 "Couldn't import standard hashlib (incomplete Python install).")
35
35
36 try:
36 try:
37 import zlib
37 import zlib
38 except:
38 except ImportError:
39 raise SystemExit(
39 raise SystemExit(
40 "Couldn't import standard zlib (incomplete Python install).")
40 "Couldn't import standard zlib (incomplete Python install).")
41
41
42 try:
42 try:
43 import bz2
43 import bz2
44 except:
44 except ImportError:
45 raise SystemExit(
45 raise SystemExit(
46 "Couldn't import standard bz2 (incomplete Python install).")
46 "Couldn't import standard bz2 (incomplete Python install).")
47
47
@@ -116,10 +116,10 class converter_source(object):
116 return s.encode("utf-8")
116 return s.encode("utf-8")
117 try:
117 try:
118 return s.decode(encoding).encode("utf-8")
118 return s.decode(encoding).encode("utf-8")
119 except:
119 except UnicodeError:
120 try:
120 try:
121 return s.decode("latin-1").encode("utf-8")
121 return s.decode("latin-1").encode("utf-8")
122 except:
122 except UnicodeError:
123 return s.decode(encoding, "replace").encode("utf-8")
123 return s.decode(encoding, "replace").encode("utf-8")
124
124
125 def getchangedfiles(self, rev, i):
125 def getchangedfiles(self, rev, i):
@@ -333,7 +333,7 class commandline(object):
333 argmax = 4096
333 argmax = 4096
334 try:
334 try:
335 argmax = os.sysconf("SC_ARG_MAX")
335 argmax = os.sysconf("SC_ARG_MAX")
336 except:
336 except (AttributeError, ValueError):
337 pass
337 pass
338
338
339 # Windows shells impose their own limits on command line length,
339 # Windows shells impose their own limits on command line length,
@@ -706,11 +706,11 def createchangeset(ui, log, fuzz=60, me
706 if mergeto:
706 if mergeto:
707 m = mergeto.search(c.comment)
707 m = mergeto.search(c.comment)
708 if m:
708 if m:
709 try:
709 if m.groups():
710 m = m.group(1)
710 m = m.group(1)
711 if m == 'HEAD':
711 if m == 'HEAD':
712 m = None
712 m = None
713 except:
713 else:
714 m = None # if no group found then merge to HEAD
714 m = None # if no group found then merge to HEAD
715 if m in branches and c.branch != m:
715 if m in branches and c.branch != m:
716 # insert empty changeset for merge
716 # insert empty changeset for merge
@@ -30,7 +30,7 class monotone_source(converter_source,
30 f = file(path, 'rb')
30 f = file(path, 'rb')
31 header = f.read(16)
31 header = f.read(16)
32 f.close()
32 f.close()
33 except:
33 except IOError:
34 header = ''
34 header = ''
35 if header != 'SQLite format 3\x00':
35 if header != 'SQLite format 3\x00':
36 raise norepo
36 raise norepo
@@ -139,7 +139,7 class logstream(object):
139 ' hg executable is in PATH'))
139 ' hg executable is in PATH'))
140 try:
140 try:
141 orig_paths, revnum, author, date, message = entry
141 orig_paths, revnum, author, date, message = entry
142 except:
142 except (TypeError, ValueError):
143 if entry is None:
143 if entry is None:
144 break
144 break
145 raise util.Abort(_("log stream exception '%s'") % entry)
145 raise util.Abort(_("log stream exception '%s'") % entry)
@@ -43,7 +43,7 class gpg(object):
43 try:
43 try:
44 if f:
44 if f:
45 os.unlink(f)
45 os.unlink(f)
46 except:
46 except OSError:
47 pass
47 pass
48 keys = []
48 keys = []
49 key, fingerprint = None, None
49 key, fingerprint = None, None
@@ -46,17 +46,14 from mercurial.node import bin, short
46 from mercurial import cmdutil, patch, templater, util, mail
46 from mercurial import cmdutil, patch, templater, util, mail
47 import email.Parser
47 import email.Parser
48
48
49 import xmlrpclib
49 import socket, xmlrpclib
50 from xml.sax import saxutils
50 from xml.sax import saxutils
51
51
52 socket_timeout = 30 # seconds
52 socket_timeout = 30 # seconds
53 try:
53 if util.safehasattr(socket, 'setdefaulttimeout'):
54 # set a timeout for the socket so you don't have to wait so looooong
54 # set a timeout for the socket so you don't have to wait so looooong
55 # when cia.vc is having problems. requires python >= 2.3:
55 # when cia.vc is having problems. requires python >= 2.3:
56 import socket
57 socket.setdefaulttimeout(socket_timeout)
56 socket.setdefaulttimeout(socket_timeout)
58 except:
59 pass
60
57
61 HGCIA_VERSION = '0.1'
58 HGCIA_VERSION = '0.1'
62 HGCIA_URL = 'http://hg.kublai.com/mercurial/hgcia'
59 HGCIA_URL = 'http://hg.kublai.com/mercurial/hgcia'
@@ -355,7 +355,7 class socketlistener(object):
355 except (OSError, socket.error), inst:
355 except (OSError, socket.error), inst:
356 try:
356 try:
357 os.unlink(self.realsockpath)
357 os.unlink(self.realsockpath)
358 except:
358 except OSError:
359 pass
359 pass
360 os.rmdir(tempdir)
360 os.rmdir(tempdir)
361 if inst.errno == errno.EEXIST:
361 if inst.errno == errno.EEXIST:
@@ -416,7 +416,7 class socketlistener(object):
416 # try to send back our version to the client
416 # try to send back our version to the client
417 # this way, the client too is informed of the mismatch
417 # this way, the client too is informed of the mismatch
418 sock.sendall(chr(common.version))
418 sock.sendall(chr(common.version))
419 except:
419 except socket.error:
420 pass
420 pass
421 return
421 return
422
422
@@ -1084,7 +1084,7 class queue(object):
1084 patchpath = self.join(patchfn)
1084 patchpath = self.join(patchfn)
1085 try:
1085 try:
1086 os.unlink(patchpath)
1086 os.unlink(patchpath)
1087 except:
1087 except OSError:
1088 self.ui.warn(_('error unlinking %s\n') % patchpath)
1088 self.ui.warn(_('error unlinking %s\n') % patchpath)
1089 raise
1089 raise
1090 self.removeundo(repo)
1090 self.removeundo(repo)
@@ -304,7 +304,7 def patchbomb(ui, repo, *revs, **opts):
304 finally:
304 finally:
305 try:
305 try:
306 os.unlink(tmpfn)
306 os.unlink(tmpfn)
307 except:
307 except OSError:
308 pass
308 pass
309 os.rmdir(tmpdir)
309 os.rmdir(tmpdir)
310
310
@@ -44,7 +44,7 def getip():
44 s.connect(('1.0.0.1', 0))
44 s.connect(('1.0.0.1', 0))
45 ip = s.getsockname()[0]
45 ip = s.getsockname()[0]
46 return ip
46 return ip
47 except:
47 except socket.error:
48 pass
48 pass
49
49
50 # Generic method, sometimes gives useless results
50 # Generic method, sometimes gives useless results
@@ -61,7 +61,7 def getip():
61 s.connect(('1.0.0.1', 1))
61 s.connect(('1.0.0.1', 1))
62 ip = s.getsockname()[0]
62 ip = s.getsockname()[0]
63 return ip
63 return ip
64 except:
64 except socket.error:
65 pass
65 pass
66
66
67 return dumbip
67 return dumbip
@@ -758,7 +758,7 if __name__ == '__main__':
758 try:
758 try:
759 N = int(sys.argv[1])
759 N = int(sys.argv[1])
760 url = sys.argv[2]
760 url = sys.argv[2]
761 except:
761 except (IndexError, ValueError):
762 print "%s <integer> <url>" % sys.argv[0]
762 print "%s <integer> <url>" % sys.argv[0]
763 else:
763 else:
764 test(url, N)
764 test(url, N)
@@ -29,6 +29,7 class sshrepository(wireproto.wirereposi
29 def __init__(self, ui, path, create=False):
29 def __init__(self, ui, path, create=False):
30 self._url = path
30 self._url = path
31 self.ui = ui
31 self.ui = ui
32 self.pipeo = self.pipei = self.pipee = None
32
33
33 u = util.url(path, parsequery=False, parsefragment=False)
34 u = util.url(path, parsequery=False, parsefragment=False)
34 if u.scheme != 'ssh' or not u.host or u.path is None:
35 if u.scheme != 'ssh' or not u.host or u.path is None:
@@ -111,15 +112,17 class sshrepository(wireproto.wirereposi
111 raise exception
112 raise exception
112
113
113 def cleanup(self):
114 def cleanup(self):
114 try:
115 if self.pipeo is None:
116 return
115 self.pipeo.close()
117 self.pipeo.close()
116 self.pipei.close()
118 self.pipei.close()
119 try:
117 # read the error descriptor until EOF
120 # read the error descriptor until EOF
118 for l in self.pipee:
121 for l in self.pipee:
119 self.ui.status(_("remote: "), l)
122 self.ui.status(_("remote: "), l)
123 except (IOError, ValueError):
124 pass
120 self.pipee.close()
125 self.pipee.close()
121 except:
122 pass
123
126
124 __del__ = cleanup
127 __del__ = cleanup
125
128
@@ -1079,7 +1079,7 def matchdate(date):
1079 try:
1079 try:
1080 d["d"] = days
1080 d["d"] = days
1081 return parsedate(date, extendeddateformats, d)[0]
1081 return parsedate(date, extendeddateformats, d)[0]
1082 except:
1082 except Abort:
1083 pass
1083 pass
1084 d["d"] = "28"
1084 d["d"] = "28"
1085 return parsedate(date, extendeddateformats, d)[0]
1085 return parsedate(date, extendeddateformats, d)[0]
@@ -23,16 +23,16 else:
23 try:
23 try:
24 import hashlib
24 import hashlib
25 sha = hashlib.sha1()
25 sha = hashlib.sha1()
26 except:
26 except ImportError:
27 try:
27 try:
28 import sha
28 import sha
29 except:
29 except ImportError:
30 raise SystemExit(
30 raise SystemExit(
31 "Couldn't import standard hashlib (incomplete Python install).")
31 "Couldn't import standard hashlib (incomplete Python install).")
32
32
33 try:
33 try:
34 import zlib
34 import zlib
35 except:
35 except ImportError:
36 raise SystemExit(
36 raise SystemExit(
37 "Couldn't import standard zlib (incomplete Python install).")
37 "Couldn't import standard zlib (incomplete Python install).")
38
38
@@ -41,7 +41,7 isironpython = False
41 try:
41 try:
42 isironpython = (platform.python_implementation()
42 isironpython = (platform.python_implementation()
43 .lower().find("ironpython") != -1)
43 .lower().find("ironpython") != -1)
44 except:
44 except AttributeError:
45 pass
45 pass
46
46
47 if isironpython:
47 if isironpython:
@@ -49,7 +49,7 if isironpython:
49 else:
49 else:
50 try:
50 try:
51 import bz2
51 import bz2
52 except:
52 except ImportError:
53 raise SystemExit(
53 raise SystemExit(
54 "Couldn't import standard bz2 (incomplete Python install).")
54 "Couldn't import standard bz2 (incomplete Python install).")
55
55
@@ -60,7 +60,7 def has_eol_in_paths():
60 os.close(fd)
60 os.close(fd)
61 os.remove(path)
61 os.remove(path)
62 return True
62 return True
63 except:
63 except (IOError, OSError):
64 return False
64 return False
65
65
66 def has_executablebit():
66 def has_executablebit():
@@ -93,7 +93,7 def has_icasefs():
93 try:
93 try:
94 s2 = os.stat(p2)
94 s2 = os.stat(p2)
95 return s2 == s1
95 return s2 == s1
96 except:
96 except OSError:
97 return False
97 return False
98 finally:
98 finally:
99 os.remove(path)
99 os.remove(path)
@@ -860,7 +860,7 def runone(options, test):
860 tf = open(testpath)
860 tf = open(testpath)
861 firstline = tf.readline().rstrip()
861 firstline = tf.readline().rstrip()
862 tf.close()
862 tf.close()
863 except:
863 except IOError:
864 firstline = ''
864 firstline = ''
865 lctest = test.lower()
865 lctest = test.lower()
866
866
@@ -17,27 +17,12
17 contrib/setup3k.py:0:
17 contrib/setup3k.py:0:
18 > except:
18 > except:
19 warning: naked except clause
19 warning: naked except clause
20 contrib/setup3k.py:0:
21 > except:
22 warning: naked except clause
23 contrib/setup3k.py:0:
24 > except:
25 warning: naked except clause
26 warning: naked except clause
27 warning: naked except clause
28 contrib/shrink-revlog.py:0:
20 contrib/shrink-revlog.py:0:
29 > except:
21 > except:
30 warning: naked except clause
22 warning: naked except clause
31 hgext/convert/bzr.py:0:
23 hgext/convert/bzr.py:0:
32 > except:
24 > except:
33 warning: naked except clause
25 warning: naked except clause
34 hgext/convert/common.py:0:
35 > except:
36 warning: naked except clause
37 hgext/convert/common.py:0:
38 > except:
39 warning: naked except clause
40 warning: naked except clause
41 hgext/convert/convcmd.py:0:
26 hgext/convert/convcmd.py:0:
42 > except:
27 > except:
43 warning: naked except clause
28 warning: naked except clause
@@ -51,9 +36,6
51 > ui.write('Parents: %s\n' %
36 > ui.write('Parents: %s\n' %
52 warning: unwrapped ui message
37 warning: unwrapped ui message
53 hgext/convert/cvsps.py:0:
38 hgext/convert/cvsps.py:0:
54 > except:
55 warning: naked except clause
56 hgext/convert/cvsps.py:0:
57 > ui.write('Branchpoints: %s \n' % ', '.join(branchpoints))
39 > ui.write('Branchpoints: %s \n' % ', '.join(branchpoints))
58 warning: unwrapped ui message
40 warning: unwrapped ui message
59 hgext/convert/cvsps.py:0:
41 hgext/convert/cvsps.py:0:
@@ -90,21 +72,9
90 hgext/convert/monotone.py:0:
72 hgext/convert/monotone.py:0:
91 > except:
73 > except:
92 warning: naked except clause
74 warning: naked except clause
93 hgext/convert/monotone.py:0:
94 > except:
95 warning: naked except clause
96 hgext/convert/subversion.py:0:
75 hgext/convert/subversion.py:0:
97 > except:
76 > except:
98 warning: naked except clause
77 warning: naked except clause
99 hgext/convert/subversion.py:0:
100 > except:
101 warning: naked except clause
102 hgext/gpg.py:0:
103 > except:
104 warning: naked except clause
105 hgext/hgcia.py:0:
106 > except:
107 warning: naked except clause
108 hgext/hgk.py:0:
78 hgext/hgk.py:0:
109 > ui.write("parent %s\n" % p)
79 > ui.write("parent %s\n" % p)
110 warning: unwrapped ui message
80 warning: unwrapped ui message
@@ -126,19 +96,12
126 hgext/hgk.py:0:
96 hgext/hgk.py:0:
127 > ui.write("tree %s\n" % short(ctx.changeset()[0]))
97 > ui.write("tree %s\n" % short(ctx.changeset()[0]))
128 warning: unwrapped ui message
98 warning: unwrapped ui message
129 hgext/inotify/server.py:0:
130 > except:
131 warning: naked except clause
132 hgext/inotify/server.py:0:
133 > except:
134 warning: naked except clause
135 hgext/keyword.py:0:
99 hgext/keyword.py:0:
136 > ui.note("hg ci -m '%s'\n" % msg)
100 > ui.note("hg ci -m '%s'\n" % msg)
137 warning: unwrapped ui message
101 warning: unwrapped ui message
138 hgext/mq.py:0:
102 hgext/mq.py:0:
139 > except:
103 > except:
140 warning: naked except clause
104 warning: naked except clause
141 warning: naked except clause
142 hgext/mq.py:0:
105 hgext/mq.py:0:
143 > except:
106 > except:
144 warning: naked except clause
107 warning: naked except clause
@@ -152,18 +115,11
152 > ui.write("mq: %s\n" % ', '.join(m))
115 > ui.write("mq: %s\n" % ', '.join(m))
153 warning: unwrapped ui message
116 warning: unwrapped ui message
154 hgext/patchbomb.py:0:
117 hgext/patchbomb.py:0:
155 > except:
156 warning: naked except clause
157 hgext/patchbomb.py:0:
158 > ui.write('Subject: %s\n' % subj)
118 > ui.write('Subject: %s\n' % subj)
159 warning: unwrapped ui message
119 warning: unwrapped ui message
160 hgext/patchbomb.py:0:
120 hgext/patchbomb.py:0:
161 > ui.write('From: %s\n' % sender)
121 > ui.write('From: %s\n' % sender)
162 warning: unwrapped ui message
122 warning: unwrapped ui message
163 hgext/zeroconf/__init__.py:0:
164 > except:
165 warning: naked except clause
166 warning: naked except clause
167 mercurial/commands.py:0:
123 mercurial/commands.py:0:
168 > ui.note('branch %s\n' % data)
124 > ui.note('branch %s\n' % data)
169 warning: unwrapped ui message
125 warning: unwrapped ui message
@@ -270,9 +226,6
270 mercurial/keepalive.py:0:
226 mercurial/keepalive.py:0:
271 > except:
227 > except:
272 warning: naked except clause
228 warning: naked except clause
273 mercurial/keepalive.py:0:
274 > except:
275 warning: naked except clause
276 mercurial/localrepo.py:0:
229 mercurial/localrepo.py:0:
277 > except:
230 > except:
278 warning: naked except clause
231 warning: naked except clause
@@ -285,18 +238,12
285 mercurial/repair.py:0:
238 mercurial/repair.py:0:
286 > except:
239 > except:
287 warning: naked except clause
240 warning: naked except clause
288 mercurial/sshrepo.py:0:
289 > except:
290 warning: naked except clause
291 mercurial/transaction.py:0:
241 mercurial/transaction.py:0:
292 > except:
242 > except:
293 warning: naked except clause
243 warning: naked except clause
294 mercurial/util.py:0:
244 mercurial/util.py:0:
295 > except:
245 > except:
296 warning: naked except clause
246 warning: naked except clause
297 mercurial/util.py:0:
298 > except:
299 warning: naked except clause
300 mercurial/verify.py:0:
247 mercurial/verify.py:0:
301 > except:
248 > except:
302 warning: naked except clause
249 warning: naked except clause
@@ -306,27 +253,12
306 setup.py:0:
253 setup.py:0:
307 > except:
254 > except:
308 warning: naked except clause
255 warning: naked except clause
309 setup.py:0:
310 > except:
311 warning: naked except clause
312 warning: naked except clause
313 setup.py:0:
314 > except:
315 warning: naked except clause
316 warning: naked except clause
317 warning: naked except clause
318 tests/autodiff.py:0:
256 tests/autodiff.py:0:
319 > ui.write('data lost for: %s\n' % fn)
257 > ui.write('data lost for: %s\n' % fn)
320 warning: unwrapped ui message
258 warning: unwrapped ui message
321 tests/run-tests.py:0:
322 > except:
323 warning: naked except clause
324 tests/test-convert-mtn.t:0:
259 tests/test-convert-mtn.t:0:
325 > > function get_passphrase(keypair_id)
260 > > function get_passphrase(keypair_id)
326 don't use 'function', use old style
261 don't use 'function', use old style
327 tests/test-filecache.py:0:
328 > except:
329 warning: naked except clause
330 tests/test-import-git.t:0:
262 tests/test-import-git.t:0:
331 > > Mc\${NkU|\`?^000jF3jhEB
263 > > Mc\${NkU|\`?^000jF3jhEB
332 ^ must be quoted
264 ^ must be quoted
@@ -78,7 +78,7 def fakeuncacheable():
78
78
79 try:
79 try:
80 os.remove('x')
80 os.remove('x')
81 except:
81 except OSError:
82 pass
82 pass
83
83
84 basic(fakerepo())
84 basic(fakerepo())
General Comments 0
You need to be logged in to leave comments. Login now