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