comparison mercurial/pycompat.py @ 32186:76f9a0009b4b

pycompat: extract helper to raise exception with traceback It uses "raise excobj, None, tb" form which I think is simpler and more useful than "raise exctype, args, tb".
author Yuya Nishihara <yuya@tcha.org>
date Thu, 20 Apr 2017 22:16:12 +0900
parents bc0579a25f82
children 548478efc46c
comparison
equal deleted inserted replaced
32184:cf424dae5dc7 32186:76f9a0009b4b
162 """ 162 """
163 if isinstance(s, builtins.str): 163 if isinstance(s, builtins.str):
164 return s 164 return s
165 return s.decode(u'latin-1') 165 return s.decode(u'latin-1')
166 166
167 def raisewithtb(exc, tb):
168 """Raise exception with the given traceback"""
169 raise exc.with_traceback(tb)
170
167 def _wrapattrfunc(f): 171 def _wrapattrfunc(f):
168 @functools.wraps(f) 172 @functools.wraps(f)
169 def w(object, name, *args): 173 def w(object, name, *args):
170 return f(object, sysstr(name), *args) 174 return f(object, sysstr(name), *args)
171 return w 175 return w
221 bytechr = chr 225 bytechr = chr
222 bytestr = str 226 bytestr = str
223 iterbytestr = iter 227 iterbytestr = iter
224 sysbytes = identity 228 sysbytes = identity
225 sysstr = identity 229 sysstr = identity
230
231 # this can't be parsed on Python 3
232 exec('def raisewithtb(exc, tb):\n'
233 ' raise exc, None, tb\n')
226 234
227 # Partial backport from os.py in Python 3, which only accepts bytes. 235 # Partial backport from os.py in Python 3, which only accepts bytes.
228 # In Python 2, our paths should only ever be bytes, a unicode path 236 # In Python 2, our paths should only ever be bytes, a unicode path
229 # indicates a bug. 237 # indicates a bug.
230 def fsencode(filename): 238 def fsencode(filename):