diff --git a/hgext/histedit.py b/hgext/histedit.py --- a/hgext/histedit.py +++ b/hgext/histedit.py @@ -199,6 +199,7 @@ except ImportError: fcntl = None termios = None +import binascii import functools import os import pickle @@ -504,7 +505,7 @@ class histeditaction: # Check for validation of rule ids and get the rulehash try: rev = bin(ruleid) - except TypeError: + except binascii.Error: try: _ctx = scmutil.revsingle(state.repo, ruleid) rulehash = _ctx.hex() diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py --- a/hgext/largefiles/lfcommands.py +++ b/hgext/largefiles/lfcommands.py @@ -8,6 +8,7 @@ '''High-level command function for lfconvert, plus the cmdtable.''' +import binascii import errno import os import shutil @@ -384,7 +385,7 @@ def _converttags(ui, revmap, data): continue try: newid = bin(id) - except TypeError: + except binascii.Error: ui.warn(_(b'skipping incorrectly formatted id %s\n') % id) continue try: diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py --- a/mercurial/bookmarks.py +++ b/mercurial/bookmarks.py @@ -101,8 +101,8 @@ class bmstore: if nrefs[-2] > refspec: # bookmarks weren't sorted before 4.5 nrefs.sort() - except (TypeError, ValueError): - # TypeError: + except ValueError: + # binascii.Error (ValueError subclass): # - bin(...) # ValueError: # - node in nm, for non-20-bytes entry diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -2691,9 +2691,9 @@ def debugobsolete(ui, repo, precursor=No # local repository. n = bin(s) if len(n) != repo.nodeconstants.nodelen: - raise TypeError() + raise ValueError return n - except TypeError: + except ValueError: raise error.InputError( b'changeset references must be full hexadecimal ' b'node identifiers' diff --git a/mercurial/node.py b/mercurial/node.py --- a/mercurial/node.py +++ b/mercurial/node.py @@ -10,14 +10,7 @@ import binascii # This ugly style has a noticeable effect in manifest parsing hex = binascii.hexlify -# Adapt to Python 3 API changes. If this ends up showing up in -# profiles, we can use this version only on Python 3, and forward -# binascii.unhexlify like we used to on Python 2. -def bin(s): - try: - return binascii.unhexlify(s) - except binascii.Error as e: - raise TypeError(e) +bin = binascii.unhexlify def short(node): diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py --- a/mercurial/obsolete.py +++ b/mercurial/obsolete.py @@ -68,6 +68,7 @@ comment associated with each format for """ +import binascii import errno import struct @@ -244,7 +245,7 @@ def _fm0readmarkers(data, off, stop): if len(p) != 20: parents = None break - except TypeError: + except binascii.Error: # if content cannot be translated to nodeid drop the data. parents = None diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -1487,7 +1487,7 @@ class revlog: node = bin(id) self.rev(node) return node - except (TypeError, error.LookupError): + except (binascii.Error, error.LookupError): pass def _partialmatch(self, id): @@ -1529,7 +1529,7 @@ class revlog: l = len(id) // 2 * 2 # grab an even number of digits try: prefix = bin(id[:l]) - except TypeError: + except binascii.Error: pass else: nl = [e[7] for e in self.index if e[7].startswith(prefix)] diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -6,6 +6,7 @@ # GNU General Public License version 2 or any later version. +import binascii import re from .i18n import _ @@ -1728,7 +1729,7 @@ def _node(repo, n): rn = repo.changelog.rev(bin(n)) except error.WdirUnsupported: rn = wdirrev - except (LookupError, TypeError): + except (binascii.Error, LookupError): rn = None else: try: diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -6,6 +6,7 @@ # GNU General Public License version 2 or any later version. +import binascii import errno import glob import os @@ -639,7 +640,7 @@ def revsymbol(repo, symbol): return repo[rev] except error.FilteredLookupError: raise - except (TypeError, LookupError): + except (binascii.Error, LookupError): pass # look up bookmarks through the name interface diff --git a/mercurial/shelve.py b/mercurial/shelve.py --- a/mercurial/shelve.py +++ b/mercurial/shelve.py @@ -238,7 +238,7 @@ class shelvedstate: d[b'nodestoremove'] = [ bin(h) for h in d[b'nodestoremove'].split(b' ') ] - except (ValueError, TypeError, KeyError) as err: + except (ValueError, KeyError) as err: raise error.CorruptedState(stringutil.forcebytestr(err)) @classmethod diff --git a/mercurial/tags.py b/mercurial/tags.py --- a/mercurial/tags.py +++ b/mercurial/tags.py @@ -11,6 +11,7 @@ # tags too. +import binascii import errno import io @@ -303,7 +304,7 @@ def _readtaghist(ui, repo, lines, fn, re name = recode(name) try: nodebin = bin(nodehex) - except TypeError: + except binascii.Error: dbg(b"node '%s' is not well formed" % nodehex) continue diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py --- a/mercurial/templatefuncs.py +++ b/mercurial/templatefuncs.py @@ -6,6 +6,7 @@ # GNU General Public License version 2 or any later version. +import binascii import re from .i18n import _ @@ -769,7 +770,7 @@ def shortest(context, mapping, args): elif len(hexnode) == hexnodelen: try: node = bin(hexnode) - except TypeError: + except binascii.Error: return hexnode else: try: diff --git a/tests/test-http-bad-server.t b/tests/test-http-bad-server.t --- a/tests/test-http-bad-server.t +++ b/tests/test-http-bad-server.t @@ -386,14 +386,10 @@ Server sends an incomplete HTTP response > -p $HGPORT -d --pid-file=hg.pid -E error.log $ cat hg.pid > $DAEMON_PIDS -TODO client spews a stack due to uncaught ValueError in batch.results() -#if no-chg - $ hg clone http://localhost:$HGPORT/ clone 2> /dev/null - [1] -#else - $ hg clone http://localhost:$HGPORT/ clone 2> /dev/null + $ hg clone http://localhost:$HGPORT/ clone + abort: unexpected response: + '96ee1d7354c4ad7372047672' [255] -#endif $ killdaemons.py $DAEMON_PIDS